Debian Codegraph @

src/test/java/jnr/netdb/ProtocolTest.java

raw
1
2 package jnr.netdb;
3
4 import org.junit.After;
5 import org.junit.AfterClass;
6 import org.junit.Before;
7 import org.junit.BeforeClass;
8 import org.junit.Test;
9 import static org.junit.Assert.*;
10
11 /**
12 *
13 */
14 public class ProtocolTest {
15
16 public ProtocolTest() {
17 }
18
19 @BeforeClass
20 public static void setUpClass() throws Exception {
21 }
22
23 @AfterClass
24 public static void tearDownClass() throws Exception {
25 }
26
27 @Before
28 public void setUp() {
29 }
30
31 @After
32 public void tearDown() {
33 }
34
35 @Test public void canLookupIpProtocolByName() {
36 // we try ip first and then ipv4 due to jnr/jnr-netdb#4
37 Protocol p = Protocol.getProtocolByName("ip");
38 if (p != null) {
39 assertEquals("incorrect proto number", 0, p.getProto());
40 assertEquals("incorrect name", "ip", p.getName());
41 } else {
42 p = Protocol.getProtocolByName("ipv4");
43 assertNotNull("could not lookup ipv4 protocol", p);
44 assertEquals("incorrect proto number", 4, p.getProto());
45 assertEquals("incorrect name", "ipv4", p.getName());
46 }
47 }
48
49 @Test public void returnsNullOnUnknownProtocol() {
50 Protocol p = Protocol.getProtocolByName("foo-bar-baz");
51 assertNull("could not handle unknown protocol", p);
52 }
53
54 @Test public void canLookupIpProtocolByNumber() {
55 // we try ip first and then ipv4 due to jnr/jnr-netdb#4
56 Protocol p = Protocol.getProtocolByName("ip");
57 if (p != null) {
58 p = Protocol.getProtocolByNumber(0);
59 assertEquals("incorrect proto number", 0, p.getProto());
60 assertEquals("incorrect name", "ip", p.getName());
61 } else {
62 p = Protocol.getProtocolByNumber(4);
63 assertNotNull("could not lookup ip protocol", p);
64 assertEquals("incorrect proto number", 4, p.getProto());
65 assertEquals("incorrect name", "ipv4", p.getName());
66 }
67 }
68
69 @Test public void returnsNullOnInvalidNumber() {
70 Protocol p = Protocol.getProtocolByNumber(-1);
71 assertNull("could not handle invalid number ", p);
72 }
73 }