Repository navigation
Expand file tree
/
Copy pathProjectInfoTest.java
More file actions
129 lines (113 loc) · 4.53 KB
/
Copy pathProjectInfoTest.java
File metadata and controls
129 lines (113 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.dns;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import org.junit.Test;
import java.math.BigInteger;
public class ProjectInfoTest {
private static final String ID = "project-id-123";
private static final BigInteger NUMBER = new BigInteger("123");
private static final ProjectInfo.Quota QUOTA = new ProjectInfo.Quota(1, 2, 3, 4, 5, 6);
private static final ProjectInfo PROJECT_INFO = ProjectInfo.newBuilder()
.setId(ID).setNumber(NUMBER).setQuota(QUOTA).build();
@Test
public void testBuilder() {
ProjectInfo withId = ProjectInfo.newBuilder().setId(ID).build();
assertEquals(ID, withId.getId());
assertNull(withId.getNumber());
assertNull(withId.getQuota());
ProjectInfo withNumber = ProjectInfo.newBuilder().setNumber(NUMBER).build();
assertEquals(NUMBER, withNumber.getNumber());
assertNull(withNumber.getQuota());
assertNull(withNumber.getId());
ProjectInfo withQuota = ProjectInfo.newBuilder().setQuota(QUOTA).build();
assertEquals(QUOTA, withQuota.getQuota());
assertNull(withQuota.getId());
assertNull(withQuota.getNumber());
assertEquals(QUOTA, PROJECT_INFO.getQuota());
assertEquals(NUMBER, PROJECT_INFO.getNumber());
assertEquals(ID, PROJECT_INFO.getId());
}
@Test
public void testQuotaConstructor() {
assertEquals(1, QUOTA.getZones());
assertEquals(2, QUOTA.getResourceRecordsPerRrset());
assertEquals(3, QUOTA.getRrsetAdditionsPerChange());
assertEquals(4, QUOTA.getRrsetDeletionsPerChange());
assertEquals(5, QUOTA.getRrsetsPerZone());
assertEquals(6, QUOTA.getTotalRrdataSizePerChange());
}
@Test
public void testEqualsAndNotEqualsQuota() {
ProjectInfo.Quota clone = new ProjectInfo.Quota(6, 5, 4, 3, 2, 1);
assertNotEquals(QUOTA, clone);
clone = ProjectInfo.Quota.fromPb(QUOTA.toPb());
assertEquals(QUOTA, clone);
}
@Test
public void testSameHashCodeOnEqualsQuota() {
ProjectInfo.Quota clone = ProjectInfo.Quota.fromPb(QUOTA.toPb());
assertEquals(QUOTA, clone);
assertEquals(QUOTA.hashCode(), clone.hashCode());
}
@Test
public void testEqualsAndNotEquals() {
ProjectInfo clone = ProjectInfo.newBuilder().build();
assertNotEquals(PROJECT_INFO, clone);
clone = ProjectInfo.newBuilder()
.setId(PROJECT_INFO.getId())
.setNumber(PROJECT_INFO.getNumber())
.build();
assertNotEquals(PROJECT_INFO, clone);
clone = ProjectInfo.newBuilder()
.setId(PROJECT_INFO.getId())
.setQuota(PROJECT_INFO.getQuota())
.build();
assertNotEquals(PROJECT_INFO, clone);
clone = ProjectInfo.newBuilder()
.setNumber(PROJECT_INFO.getNumber())
.setQuota(PROJECT_INFO.getQuota())
.build();
assertNotEquals(PROJECT_INFO, clone);
clone = ProjectInfo.fromPb(PROJECT_INFO.toPb());
assertEquals(PROJECT_INFO, clone);
}
@Test
public void testSameHashCodeOnEquals() {
ProjectInfo clone = ProjectInfo.fromPb(PROJECT_INFO.toPb());
assertEquals(PROJECT_INFO, clone);
assertEquals(PROJECT_INFO.hashCode(), clone.hashCode());
}
@Test
public void testToAndFromPb() {
assertEquals(PROJECT_INFO, ProjectInfo.fromPb(PROJECT_INFO.toPb()));
ProjectInfo partial = ProjectInfo.newBuilder().setId(ID).build();
assertEquals(partial, ProjectInfo.fromPb(partial.toPb()));
partial = ProjectInfo.newBuilder().setNumber(NUMBER).build();
assertEquals(partial, ProjectInfo.fromPb(partial.toPb()));
partial = ProjectInfo.newBuilder().setQuota(QUOTA).build();
assertEquals(partial, ProjectInfo.fromPb(partial.toPb()));
assertNotEquals(PROJECT_INFO, partial);
}
@Test
public void testToAndFromPbQuota() {
assertEquals(QUOTA, ProjectInfo.Quota.fromPb(QUOTA.toPb()));
ProjectInfo.Quota wrong = new ProjectInfo.Quota(5, 6, 3, 6, 2, 1);
assertNotEquals(QUOTA, ProjectInfo.Quota.fromPb(wrong.toPb()));
}
}