@Test
 public void testBuilderMethods() {
   Ipv4 sample = new Ipv4(1l);
   assertEquals(sample, Ipv4.of(BigInteger.ONE));
   assertEquals(sample, Ipv4.of(1l));
   assertEquals(sample, Ipv4.of("0.0.0.1"));
 }
 @Test
 public void shouldCalculateCommonPrefixLength() {
   Ipv4 ipv4 = Ipv4.of("192.168.0.0");
   assertEquals(0, ipv4.getCommonPrefixLength(Ipv4.of("0.0.0.0")));
   assertEquals(16, ipv4.getCommonPrefixLength(Ipv4.of("192.168.255.255")));
   assertEquals(32, ipv4.getCommonPrefixLength(Ipv4.of("192.168.0.0")));
 }
 @Test
 public void shouldFailOnLessOctets() {
   thrown.expect(IllegalArgumentException.class);
   thrown.expectMessage("Invalid IPv4 address: 10.1.1");
   Ipv4.parse("10.1.1");
 }
 @Test
 public void shouldParseIPv4AddressWithLeadingAndTrailingSpaces() {
   assertEquals("127.0.8.12", Ipv4.parse("  127.0.8.12  ").toString());
 }
 @Test
 public void shouldParseDottedDecimalNotation() {
   assertEquals("127.0.8.23", Ipv4.parse("127.0.8.23").toString());
   assertEquals("193.168.15.255", Ipv4.parse("193.168.15.255").toString());
 }
 @Test
 public void testHasPrevious() {
   assertFalse(Ipv4.FIRST_IPV4_ADDRESS.hasPrevious());
   assertTrue(Ipv4.of("192.168.0.1").hasPrevious());
   assertTrue(Ipv4.LAST_IPV4_ADDRESS.hasPrevious());
 }
 @Test
 public void testBuilderWithNull() {
   thrown.expect(IllegalArgumentException.class);
   thrown.expectMessage("from cannot be null");
   Ipv4.of((BigInteger) null);
 }
 @Test
 public void shouldFailToCalculateUpperBoundWhenPrefixIsOutOfRange() {
   thrown.expect(IllegalArgumentException.class);
   thrown.expectMessage("Value [33] out of range: [0..32]");
   Ipv4.parse("192.168.0.100").upperBoundForPrefix(33);
 }
  @Test
  public void shouldCalculateBoundsGivenAnAddressAndAPrefix() {
    Ipv4 address = Ipv4.parse("192.168.0.100");
    assertEquals(Ipv4.parse("0.0.0.0"), address.lowerBoundForPrefix(0));
    assertEquals(Ipv4.parse("255.255.255.255"), address.upperBoundForPrefix(0));

    assertEquals(Ipv4.parse("192.168.0.0"), address.lowerBoundForPrefix(16));
    assertEquals(Ipv4.parse("192.168.255.255"), address.upperBoundForPrefix(16));

    assertEquals(Ipv4.parse("192.168.0.100"), address.lowerBoundForPrefix(32));
    assertEquals(Ipv4.parse("192.168.0.100"), address.upperBoundForPrefix(32));
  }
示例#10
0
 @Test
 public void shouldFailOnOutOfBoundsByte_NegativeByte() {
   thrown.expect(IllegalArgumentException.class);
   thrown.expectMessage("Invalid IPv4 address: 13.-40.0.0");
   Ipv4.parse("13.-40.0.0");
 }
示例#11
0
 @Test
 public void shouldFailOnOutOfBoundsByte() {
   thrown.expect(IllegalArgumentException.class);
   thrown.expectMessage("Value [256] out of range: [0..255]");
   Ipv4.parse("256.0.0.0");
 }
示例#12
0
 @Test
 public void shouldFailWhenOctetContainsNonDigit() {
   thrown.expect(IllegalArgumentException.class);
   thrown.expectMessage("Invalid IPv4 address: 10.a.1.0");
   Ipv4.parse("10.a.1.0");
 }
示例#13
0
 @Test
 public void shouldFailWhenStartingWithNonDigit() {
   thrown.expect(IllegalArgumentException.class);
   thrown.expectMessage("Invalid IPv4 address: .10.1.1.1");
   Ipv4.parse(".10.1.1.1");
 }