Skip to content

Commit adf5c1c

Browse files
committed
Added test for AbstractOption.
1 parent e17bedb commit adf5c1c

2 files changed

Lines changed: 71 additions & 1 deletion

File tree

gcloud-java-dns/src/main/java/com/google/gcloud/dns/Dns.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ enum SortingOrder {
193193
DESCENDING, ASCENDING;
194194

195195
public String selector() {
196-
return this.name().toLowerCase();
196+
return name().toLowerCase();
197197
}
198198
}
199199

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud.dns;
18+
19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertNotEquals;
21+
import static org.junit.Assert.fail;
22+
23+
import com.google.gcloud.spi.DnsRpc;
24+
25+
import org.junit.Test;
26+
27+
public class AbstractOptionTest {
28+
29+
private static final DnsRpc.Option RPC_OPTION = DnsRpc.Option.DNS_TYPE;
30+
private static final DnsRpc.Option ANOTHER_RPC_OPTION = DnsRpc.Option.DNS_NAME;
31+
private static final String VALUE = "some value";
32+
private static final String OTHER_VALUE = "another value";
33+
private static final AbstractOption OPTION = new AbstractOption(RPC_OPTION, VALUE) {
34+
};
35+
private static final AbstractOption OPTION_EQUALS = new AbstractOption(RPC_OPTION, VALUE) {
36+
};
37+
private static final AbstractOption OPTION_NOT_EQUALS1 =
38+
new AbstractOption(RPC_OPTION, OTHER_VALUE) {
39+
};
40+
private static final AbstractOption OPTION_NOT_EQUALS2 =
41+
new AbstractOption(ANOTHER_RPC_OPTION, VALUE) {
42+
};
43+
44+
@Test
45+
public void testEquals() {
46+
assertEquals(OPTION, OPTION_EQUALS);
47+
assertNotEquals(OPTION, OPTION_NOT_EQUALS1);
48+
assertNotEquals(OPTION, OPTION_NOT_EQUALS2);
49+
}
50+
51+
@Test
52+
public void testHashCode() {
53+
assertEquals(OPTION.hashCode(), OPTION_EQUALS.hashCode());
54+
}
55+
56+
@Test
57+
public void testConstructor() {
58+
assertEquals(RPC_OPTION, OPTION.rpcOption());
59+
assertEquals(VALUE, OPTION.value());
60+
try {
61+
new AbstractOption(null, VALUE) {
62+
};
63+
fail("Cannot build with empty option.");
64+
} catch (NullPointerException e) {
65+
// expected
66+
}
67+
new AbstractOption(RPC_OPTION, null) {
68+
}; // null value is ok
69+
}
70+
}

0 commit comments

Comments
 (0)