• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 Google LLC
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.cloud.dns;
18 
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNotEquals;
21 import static org.junit.Assert.assertNull;
22 
23 import com.google.cloud.dns.spi.v1.DnsRpc;
24 import org.junit.Rule;
25 import org.junit.Test;
26 import org.junit.rules.ExpectedException;
27 
28 public class OptionTest {
29 
30   private static final DnsRpc.Option RPC_OPTION = DnsRpc.Option.DNS_TYPE;
31   private static final DnsRpc.Option ANOTHER_RPC_OPTION = DnsRpc.Option.DNS_NAME;
32   private static final String VALUE = "some value";
33   private static final String OTHER_VALUE = "another value";
34   private static final Option OPTION = new Option(RPC_OPTION, VALUE) {};
35   private static final Option OPTION_EQUALS = new Option(RPC_OPTION, VALUE) {};
36   private static final Option OPTION_NOT_EQUALS1 = new Option(RPC_OPTION, OTHER_VALUE) {};
37   private static final Option OPTION_NOT_EQUALS2 = new Option(ANOTHER_RPC_OPTION, VALUE) {};
38 
39   @Rule public ExpectedException thrown = ExpectedException.none();
40 
41   @Test
testEquals()42   public void testEquals() {
43     assertEquals(OPTION, OPTION_EQUALS);
44     assertNotEquals(OPTION, OPTION_NOT_EQUALS1);
45     assertNotEquals(OPTION, OPTION_NOT_EQUALS2);
46   }
47 
48   @Test
testHashCode()49   public void testHashCode() {
50     assertEquals(OPTION.hashCode(), OPTION_EQUALS.hashCode());
51   }
52 
53   @Test
testConstructor()54   public void testConstructor() {
55     assertEquals(RPC_OPTION, OPTION.getRpcOption());
56     assertEquals(VALUE, OPTION.getValue());
57     Option option = new Option(RPC_OPTION, null) {};
58     assertEquals(RPC_OPTION, option.getRpcOption());
59     assertNull(option.getValue());
60     thrown.expect(NullPointerException.class);
61     new Option(null, VALUE) {};
62   }
63 }
64