Skip to content
Permalink
Browse files

Prefer assertThrows to try/fail (#62)

  • Loading branch information...
kingle authored and ibauersachs committed Jun 17, 2019
1 parent 25fc5e0 commit 0ae8feab57dba10affb04ab4a0f31502cc783243
Showing with 476 additions and 1,471 deletions.
  1. +12 −36 src/test/java/org/xbill/DNS/A6RecordTest.java
  2. +9 −19 src/test/java/org/xbill/DNS/AAAARecordTest.java
  3. +26 −90 src/test/java/org/xbill/DNS/APLRecordTest.java
  4. +9 −19 src/test/java/org/xbill/DNS/ARecordTest.java
  5. +13 −53 src/test/java/org/xbill/DNS/AddressTest.java
  6. +5 −14 src/test/java/org/xbill/DNS/DClassTest.java
  7. +15 −56 src/test/java/org/xbill/DNS/DNSInputTest.java
  8. +7 −17 src/test/java/org/xbill/DNS/DNSKEYRecordTest.java
  9. +11 −52 src/test/java/org/xbill/DNS/DNSOutputTest.java
  10. +17 −41 src/test/java/org/xbill/DNS/DSRecordTest.java
  11. +5 −14 src/test/java/org/xbill/DNS/ExtendedFlagsTest.java
  12. +7 −26 src/test/java/org/xbill/DNS/FlagsTest.java
  13. +7 −22 src/test/java/org/xbill/DNS/FormattedTimeTest.java
  14. +31 −99 src/test/java/org/xbill/DNS/GPOSRecordTest.java
  15. +8 −24 src/test/java/org/xbill/DNS/HINFORecordTest.java
  16. +29 −76 src/test/java/org/xbill/DNS/HeaderTest.java
  17. +11 −41 src/test/java/org/xbill/DNS/KEYRecordTest.java
  18. +8 −16 src/test/java/org/xbill/DNS/MessageTest.java
  19. +7 −6 src/test/java/org/xbill/DNS/MnemonicTest.java
  20. +28 −122 src/test/java/org/xbill/DNS/NameTest.java
  21. +5 −14 src/test/java/org/xbill/DNS/OpcodeTest.java
  22. +16 −40 src/test/java/org/xbill/DNS/RRsetTest.java
  23. +7 −26 src/test/java/org/xbill/DNS/RcodeTest.java
  24. +32 −118 src/test/java/org/xbill/DNS/RecordTest.java
  25. +12 −27 src/test/java/org/xbill/DNS/ReverseMapTest.java
  26. +33 −89 src/test/java/org/xbill/DNS/SOARecordTest.java
  27. +5 −14 src/test/java/org/xbill/DNS/SectionTest.java
  28. +9 −44 src/test/java/org/xbill/DNS/SerialTest.java
  29. +11 −35 src/test/java/org/xbill/DNS/SetResponseTest.java
  30. +5 −11 src/test/java/org/xbill/DNS/SingleNameBaseTest.java
  31. +11 −18 src/test/java/org/xbill/DNS/TTLTest.java
  32. +40 −133 src/test/java/org/xbill/DNS/TokenizerTest.java
  33. +4 −8 src/test/java/org/xbill/DNS/TypeTest.java
  34. +9 −23 src/test/java/org/xbill/DNS/U16NameBaseTest.java
  35. +12 −28 src/test/java/org/xbill/DNS/URIRecordTest.java
@@ -34,19 +34,19 @@
//
package org.xbill.DNS;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class A6RecordTest
{
private Name m_an;
@@ -115,25 +115,13 @@ void test_ctor_6arg()
assertEquals(m_an2, ar.getPrefix());

// a relative name
try {
new A6Record(m_rn, DClass.IN, m_ttl, m_prefix_bits, m_addr, null);
fail("RelativeNameException not thrown");
}
catch( RelativeNameException e ){}
assertThrows(RelativeNameException.class, () -> new A6Record(m_rn, DClass.IN, m_ttl, m_prefix_bits, m_addr, null));

// a relative prefix name
try {
new A6Record(m_an, DClass.IN, m_ttl, m_prefix_bits, m_addr, m_rn);
fail("RelativeNameException not thrown");
}
catch( RelativeNameException e ){}
assertThrows(RelativeNameException.class, () -> new A6Record(m_an, DClass.IN, m_ttl, m_prefix_bits, m_addr, m_rn));

// invalid prefix bits
try {
new A6Record(m_rn, DClass.IN, m_ttl, 0x100, m_addr, null);
fail("IllegalArgumentException not thrown");
}
catch( RelativeNameException e ){}
assertThrows(RelativeNameException.class, () -> new A6Record(m_rn, DClass.IN, m_ttl, 0x100, m_addr, null));

// an IPv4 address
try {
@@ -200,22 +188,10 @@ void test_rdataFromString() throws
assertEquals(m_an2, ar.getPrefix());

// record with invalid prefixBits
t = new Tokenizer("129");
ar = new A6Record();
try {
ar.rdataFromString(t, null);
fail("TextParseException not thrown");
}
catch( TextParseException e ){}
assertThrows(TextParseException.class, () -> new A6Record().rdataFromString(new Tokenizer("129"), null));

// record with invalid ipv6 address
t = new Tokenizer("0 " + m_addr_string.substring(4));
ar = new A6Record();
try {
ar.rdataFromString(t, null);
fail("TextParseException not thrown");
}
catch( TextParseException e ){}
assertThrows(TextParseException.class, () -> new A6Record().rdataFromString(new Tokenizer("0 " + m_addr_string.substring(4)), null));
}

@Test
@@ -34,19 +34,19 @@
//
package org.xbill.DNS;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class AAAARecordTest
{
private Name m_an;
@@ -97,11 +97,7 @@ void test_ctor_4arg()
assertEquals(m_addr, ar.getAddress());

// a relative name
try {
new AAAARecord(m_rn, DClass.IN, m_ttl, m_addr);
fail("RelativeNameException not thrown");
}
catch( RelativeNameException e ){}
assertThrows(RelativeNameException.class, () -> new AAAARecord(m_rn, DClass.IN, m_ttl, m_addr));

// an IPv4 address
try {
@@ -135,13 +131,7 @@ void test_rdataFromString() throws IOException
assertEquals(m_addr, ar.getAddress());

// invalid address
t = new Tokenizer("193.160.232.1");
ar = new AAAARecord();
try {
ar.rdataFromString(t, null);
fail("TextParseException not thrown");
}
catch( TextParseException e ){}
assertThrows(TextParseException.class, () -> new AAAARecord().rdataFromString(new Tokenizer("193.160.232.1"), null));
}

@Test
@@ -34,23 +34,23 @@
//
package org.xbill.DNS;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.xbill.DNS.APLRecord.Element;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.xbill.DNS.APLRecord.Element;

public class APLRecordTest
{
static class Test_Element_init
@@ -79,11 +79,7 @@ void test_valid_IPv4()
@Test
void test_invalid_IPv4()
{
try {
new Element(true, m_addr4, 33);
fail("IllegalArgumentException not thrown");
}
catch( IllegalArgumentException e ){}
assertThrows(IllegalArgumentException.class, () -> new Element(true, m_addr4, 33));
}

@Test
@@ -99,11 +95,7 @@ void test_valid_IPv6()
@Test
void test_invalid_IPv6()
{
try {
new Element(true, m_addr6, 129);
fail("IllegalArgumentException not thrown");
}
catch( IllegalArgumentException e ){}
assertThrows(IllegalArgumentException.class, () -> new Element(true, m_addr6, 129));
}
}

@@ -181,11 +173,7 @@ void test_4arg_empty_elements()
@Test
void test_4arg_relative_name()
{
try {
new APLRecord(m_rn, DClass.IN, m_ttl, m_elements);
fail("RelativeNameException not thrown");
}
catch( RelativeNameException e ){}
assertThrows(RelativeNameException.class, () -> new APLRecord(m_rn, DClass.IN, m_ttl, m_elements));
}
}

@@ -250,11 +238,7 @@ void test_invalid_IPv4_prefix() throws IOException

DNSInput di = new DNSInput(raw);
APLRecord ar = new APLRecord();
try {
ar.rrFromWire(di);
fail("WireParseException not thrown");
}
catch( WireParseException e ){}
assertThrows(WireParseException.class, () -> ar.rrFromWire(di));
}

@Test
@@ -266,11 +250,7 @@ void test_invalid_IPv4_length() throws IOException

DNSInput di = new DNSInput(raw);
APLRecord ar = new APLRecord();
try {
ar.rrFromWire(di);
fail("WireParseException not thrown");
}
catch( WireParseException e ){}
assertThrows(WireParseException.class, () -> ar.rrFromWire(di));
}

@Test
@@ -410,131 +390,87 @@ void test_no_colon() throws IOException
{
Tokenizer t = new Tokenizer("!1192.68.0.1/20");
APLRecord ar = new APLRecord();
try {
ar.rdataFromString(t, null);
fail("TextParseException not thrown");
}
catch( TextParseException e ){}
assertThrows(TextParseException.class, () -> ar.rdataFromString(t, null));
}

@Test
void test_colon_and_slash_swapped() throws IOException
{
Tokenizer t = new Tokenizer("!1/192.68.0.1:20");
APLRecord ar = new APLRecord();
try {
ar.rdataFromString(t, null);
fail("TextParseException not thrown");
}
catch( TextParseException e ){}
assertThrows(TextParseException.class, () -> ar.rdataFromString(t, null));
}

@Test
void test_no_slash() throws IOException
{
Tokenizer t = new Tokenizer("!1:192.68.0.1|20");
APLRecord ar = new APLRecord();
try {
ar.rdataFromString(t, null);
fail("TextParseException not thrown");
}
catch( TextParseException e ){}
assertThrows(TextParseException.class, () -> ar.rdataFromString(t, null));
}

@Test
void test_empty_family() throws IOException
{
Tokenizer t = new Tokenizer("!:192.68.0.1/20");
APLRecord ar = new APLRecord();
try {
ar.rdataFromString(t, null);
fail("TextParseException not thrown");
}
catch( TextParseException e ){}
assertThrows(TextParseException.class, () -> ar.rdataFromString(t, null));
}

@Test
void test_malformed_family() throws IOException
{
Tokenizer t = new Tokenizer("family:192.68.0.1/20");
APLRecord ar = new APLRecord();
try {
ar.rdataFromString(t, null);
fail("TextParseException not thrown");
}
catch( TextParseException e ){}
assertThrows(TextParseException.class, () -> ar.rdataFromString(t, null));
}

@Test
void test_invalid_family() throws IOException
{
Tokenizer t = new Tokenizer("3:192.68.0.1/20");
APLRecord ar = new APLRecord();
try {
ar.rdataFromString(t, null);
fail("TextParseException not thrown");
}
catch( TextParseException e ){}
assertThrows(TextParseException.class, () -> ar.rdataFromString(t, null));
}

@Test
void test_empty_prefix() throws IOException
{
Tokenizer t = new Tokenizer("1:192.68.0.1/");
APLRecord ar = new APLRecord();
try {
ar.rdataFromString(t, null);
fail("TextParseException not thrown");
}
catch( TextParseException e ){}
assertThrows(TextParseException.class, () -> ar.rdataFromString(t, null));
}

@Test
void test_malformed_prefix() throws IOException
{
Tokenizer t = new Tokenizer("1:192.68.0.1/prefix");
APLRecord ar = new APLRecord();
try {
ar.rdataFromString(t, null);
fail("TextParseException not thrown");
}
catch( TextParseException e ){}
assertThrows(TextParseException.class, () -> ar.rdataFromString(t, null));
}

@Test
void test_invalid_prefix() throws IOException
{
Tokenizer t = new Tokenizer("1:192.68.0.1/33");
APLRecord ar = new APLRecord();
try {
ar.rdataFromString(t, null);
fail("TextParseException not thrown");
}
catch( TextParseException e ){}
assertThrows(TextParseException.class, () -> ar.rdataFromString(t, null));
}

@Test
void test_empty_address() throws IOException
{
Tokenizer t = new Tokenizer("1:/33");
APLRecord ar = new APLRecord();
try {
ar.rdataFromString(t, null);
fail("TextParseException not thrown");
}
catch( TextParseException e ){}
assertThrows(TextParseException.class, () -> ar.rdataFromString(t, null));
}

@Test
void test_malformed_address() throws IOException
{
Tokenizer t = new Tokenizer("1:A.B.C.D/33");
APLRecord ar = new APLRecord();
try {
ar.rdataFromString(t, null);
fail("TextParseException not thrown");
}
catch( TextParseException e ){}
assertThrows(TextParseException.class, () -> ar.rdataFromString(t, null));
}
}

0 comments on commit 0ae8fea

Please sign in to comment.
You can’t perform that action at this time.