8000 Simplify assertions · codesplode/dnsjava@9c5c286 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9c5c286

Browse files
committed
Simplify assertions
1 parent a4b2ce6 commit 9c5c286

17 files changed

+135
-144
lines changed

src/test/java/org/xbill/DNS/A6RecordTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.net.UnknownHostException;
4343
import java.util.Arrays;
4444

45+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
4546
import static org.junit.jupiter.api.Assertions.assertEquals;
4647
import static org.junit.jupiter.api.Assertions.assertNull;
4748
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -242,8 +243,8 @@ public void test_rrToWire()
242243

243244
dout = new DNSOutput();
244245
ar.rrToWire(dout, null, true);
245-
246-
assertTrue(Arrays.equals(exp, dout.toByteArray()));
246+
247+
assertArrayEquals(exp, dout.toByteArray());
247248

248249
// case sensitiveform
249250
dout = new DNSOutput();
@@ -255,6 +256,6 @@ public void test_rrToWire()
255256

256257
dout = new DNSOutput();
257258
ar.rrToWire(dout, null, false);
258-
assertTrue(Arrays.equals(exp, dout.toByteArray()));
259+
assertArrayEquals(exp, dout.toByteArray());
259260
}
260261
}

src/test/java/org/xbill/DNS/AAAARecordTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.net.UnknownHostException;
4343
import java.util.Arrays;
4444

45+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
4546
import static org.junit.jupiter.api.Assertions.assertEquals;
4647
import static org.junit.jupiter.api.Assertions.assertNull;
4748
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -159,11 +160,11 @@ public void test_rrToWire()
159160
// canonical
160161
DNSOutput dout = new DNSOutput();
161162
ar.rrToWire(dout, null, true);
162-
assertTrue(Arrays.equals(m_addr_bytes, dout.toByteArray()));
163+
assertArrayEquals(m_addr_bytes, dout.toByteArray());
163164

164165
// case sensitive
165166
dout = new DNSOutput();
166167
ar.rrToWire(dout, null, false);
167-
assertTrue(Arrays.equals(m_addr_bytes, dout.toByteArray()));
168+
assertArrayEquals(m_addr_bytes, dout.toByteArray());
168169
}
169170
}

src/test/java/org/xbill/DNS/APLRecordTest.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
import java.util.Arrays;
4646
import java.util.List;
4747

48+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
4849
import static org.junit.jupiter.api.Assertions.assertEquals;
50+
import static org.junit.jupiter.api.Assertions.assertFalse;
4951
import static org.junit.jupiter.api.Assertions.assertNull;
5052
import static org.junit.jupiter.api.Assertions.assertTrue;
5153
import static org.junit.jupiter.api.As F438 sertions.fail;
@@ -70,7 +72,7 @@ public void test_valid_IPv4()
7072
{
7173
Element el = new Element(true, m_addr4, 16);
7274
assertEquals(Address.IPv4, el.family);
73-
assertEquals(true, el.negative);
75+
assertTrue(el.negative);
7476
assertEquals(m_addr4, el.address);
7577
assertEquals(16, el.prefixLength);
7678
}
@@ -90,7 +92,7 @@ public void test_valid_IPv6()
9092
{
9193
Element el = new Element(false, m_addr6, 74);
9294
assertEquals(Address.IPv6, el.family);
93-
assertEquals(false, el.negative);
95+
assertFalse(el.negative);
9496
assertEquals(m_addr6, el.address);
9597
assertEquals(74, el.prefixLength);
9698
}
@@ -343,10 +345,9 @@ public void test_valid_nonIP() throws IOException
343345

344346
Element el = (Element)l.get(0);
345347
assertEquals(3, el.family);
346-
assertEquals(true, el.negative);
348+
assertTrue(el.negative);
347349
assertEquals(130, el.prefixLength);
348-
assertTrue(Arrays.equals(new byte[] { 1, 2, 3, 4, 5 },
349-
(byte[])el.address));
350+
assertArrayEquals(new byte[]{1, 2, 3, 4, 5}, (byte[]) el.address);
350351
}
351352
}
352353

@@ -637,7 +638,7 @@ public void test_empty()
637638
DNSOutput dout = new DNSOutput();
638639

639640
ar.rrToWire(dout, null, true);
640-
assertTrue(Arrays.equals(new byte[0], dout.toByteArray()));
641+
assertArrayEquals(new byte[0], dout.toByteArray());
641642
}
642643

643644
@Test
@@ -661,7 +662,7 @@ public void test_basic()
661662
DNSOutput dout = new DNSOutput();
662663

663664
ar.rrToWire(dout, null, true);
664-
assertTrue(Arrays.equals(exp, dout.toByteArray()));
665+
assertArrayEquals(exp, dout.toByteArray());
665666
}
666667

667668
@Test
@@ -677,7 +678,7 @@ public void test_non_IP() throws IOException
677678
DNSOutput dout = new DNSOutput();
678679

679680
ar.rrToWire(dout, null, true);
680-
assertTrue(Arrays.equals(exp, dout.toByteArray()));
681+
assertArrayEquals(exp, dout.toByteArray());
681682
}
682683

683684
@Test
@@ -694,7 +695,7 @@ public void test_address_with_embedded_zero() throws UnknownHostException
694695
DNSOutput dout = new DNSOutput();
695696

696697
ar.rrToWire(dout, null, true);
697-
assertTrue(Arrays.equals(exp, dout.toByteArray()));
698+
assertArrayEquals(exp, dout.toByteArray());
698699
}
699700

700701
@Test
@@ -711,7 +712,7 @@ public void test_short_address() throws UnknownHostException
711712
DNSOutput dout = new DNSOutput();
712713

713714
ar.rrToWire(dout, null, true);
714-
assertTrue(Arrays.equals(exp, dout.toByteArray()));
715+
assertArrayEquals(exp, dout.toByteArray());
715716
}
716717

717718
@Test
@@ -728,7 +729,7 @@ public void test_wildcard_address() throws UnknownHostException
728729
DNSOutput dout = new DNSOutput();
729730

730731
ar.rrToWire(dout, null, true);
731-
assertTrue(Arrays.equals(exp, dout.toByteArray()));
732+
assertArrayEquals(exp, dout.toByteArray());
732733
}
733734
}
734735
}

src/test/java/org/xbill/DNS/ARecordTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.net.UnknownHostException;
4343
import java.util.Arrays;
4444

45+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
4546
import static org.junit.jupiter.api.Assertions.assertEquals;
4647
import static org.junit.jupiter.api.Assertions.assertNull;
4748
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -158,10 +159,10 @@ public void test_rrToWire()
158159
DNSOutput dout = new DNSOutput();
159160

160161
ar.rrToWire(dout, null, true);
161-
assertTrue(Arrays.equals(m_addr_bytes, dout.toByteArray()));
162+
assertArrayEquals(m_addr_bytes, dout.toByteArray());
162163

163164
dout = new DNSOutput();
164165
ar.rrToWire(dout, null, false);
165-
assertTrue(Arrays.equals(m_addr_bytes, dout.toByteArray()));
166+
assertArrayEquals(m_addr_bytes, dout.toByteArray());
166167
}
167168
}

src/test/java/org/xbill/DNS/DNSKEYRecordTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.net.UnknownHostException;
4141
import java.util.Arrays;
4242

43+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
4344
import static org.junit.jupiter.api.Assertions.assertEquals;
4445
import static org.junit.jupiter.api.Assertions.assertNull;
4546
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -85,7 +86,7 @@ public void test_ctor_7arg() throws TextParseException
8586
assertEquals(0x9832, kr.getFlags());
8687
assertEquals(0x12, kr.getProtocol());
8788
assertEquals(0x67, kr.getAlgorithm());
88-
assertTrue(Arrays.equals(key, kr.getKey()));
89+
assertArrayEquals(key, kr.getKey());
8990

9091
// a relative name
9192
try {
@@ -105,7 +106,7 @@ public void test_rdataFromString() throws IOException, TextParseException
105106
assertEquals(0xABCD, kr.getFlags());
106107
assertEquals(0x81, kr.getProtocol());
107108
assertEquals(DNSSEC.Algorithm.RSASHA1, kr.getAlgorithm());
108-
assertTrue(Arrays.equals(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, kr.getKey()));
109+
assertArrayEquals(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, kr.getKey());
109110

110111
// invalid algorithm
111112
kr = new DNSKEYRecord();

src/test/java/org/xbill/DNS/DSRecordTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.io.IOException;
4141
import java.util.Arrays;
4242

43+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
4344
import static org.junit.jupiter.api.Assertions.assertEquals;
4445
import static org.junit.jupiter.api.Assertions.assertNull;
4546
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -101,7 +102,7 @@ public void test_basic() throws TextParseException
101102
assertEquals(m_footprint, dr.getFootprint());
102103
assertEquals(m_algorithm, dr.getAlgorithm());
103104
assertEquals(m_digestid, dr.getDigestID());
104-
assertTrue(Arrays.equals(m_digest, dr.getDigest()));
105+
assertArrayEquals(m_digest, dr.getDigest());
105106
}
106107

107108
@Test
@@ -199,8 +200,7 @@ public void test_rrFromWire() throws IOException
199200
assertEquals(0xABCD, dr.getFootprint());
200201
assertEquals(0xEF, dr.getAlgorithm());
201202
assertEquals(0x01, dr.getDigestID());
202-
assertTrue(Arrays.equals(new byte[] { (byte)0x23, (byte)0x45, (byte)0x67, (byte)0x89 },
203-
dr.getDigest()));
203+
assertArrayEquals(new byte[]{(byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x89}, dr.getDigest());
204204
}
205205

206206
@Test
@@ -216,8 +216,7 @@ public void test_rdataFromString() throws IOException
216216
assertEquals(0xABCD, dr.getFootprint());
217217
assertEquals(0xEF, dr.getAlgorithm());
218218
assertEquals(0x01, dr.getDigestID());
219-
assertTrue(Arrays.equals(new byte[] { (byte)0x23, (byte)0x45, (byte)0x67, (byte)0x89, (byte)0xAB },
220-
dr.getDigest()));
219+
assertArrayEquals(new byte[]{(byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x89, (byte) 0xAB}, dr.getDigest());
221220
}
222221

223222
@Test
@@ -247,6 +246,6 @@ public void test_rrToWire() throws TextParseException
247246
DNSOutput out = new DNSOutput();
248247
dr.rrToWire(out, null, true);
249248

250-
assertTrue(Arrays.equals(exp, out.toByteArray()));
249+
assertArrayEquals(exp, out.toByteArray());
251250
}
252251
}

src/test/java/org/xbill/DNS/HINFORecordTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.io.IOException;
4040
import java.util.Arrays;
4141

42+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
4243
import static org.junit.jupiter.api.Assertions.assertEquals;
4344
import static org.junit.jupiter.api.Assertions.assertNull;
4445
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -200,6 +201,6 @@ public void test_rrToWire() throws TextParseException
200201
DNSOutput out = new DNSOutput();
201202
dr.rrToWire(out, null, true);
202203

203-
assertTrue(Arrays.equals(raw, out.toByteArray()));
204+
assertArrayEquals(raw, out.toByteArray());
204205
}
205206
}

src/test/java/org/xbill/DNS/KEYBaseTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.io.IOException;
4141
import java.util.Arrays;
4242

43+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
4344
import static org.junit.jupiter.api.Assertions.assertEquals;
4445
import static org.junit.jupiter.api.Assertions.assertNull;
4546
import static org.junit.jupiter.api.Assertions.assertSame;
@@ -89,7 +90,7 @@ public void test_ctor() throws TextParseException
8990
assertEquals(0xFF, tc.getFlags());
9091
assertEquals(0xF, tc.getProtocol());
9192
assertEquals(0xE, tc.getAlgorithm());
92-
assertTrue(Arrays.equals(key, tc.getKey()));
93+
assertArrayEquals(key, tc.getKey());
9394
}
9495

9596
@Test
@@ -104,7 +105,7 @@ public void test_rrFromWire() throws IOException
104105
assertEquals(0xABCD, tc.getFlags());
105106
assertEquals(0xEF, tc.getProtocol());
106107
assertEquals(0x19, tc.getAlgorithm());
107-
assertTrue(Arrays.equals(new byte[] { 1, 2, 3, 4, 5 }, tc.getKey()));
108+
assertArrayEquals(new byte[]{1, 2, 3, 4, 5}, tc.getKey());
108109

109110

110111
raw = new byte[] { (byte)0xBA, (byte)0xDA, (byte)0xFF, (byte)0x28 };
@@ -188,11 +189,11 @@ public void test_rrToWire() throws IOException, TextParseException
188189

189190
// canonical
190191
tc.rrToWire(o, null, true);
191-
assertTrue(Arrays.equals(exp, o.toByteArray()));
192+
assertArrayEquals(exp, o.toByteArray());
192193

193194
// not canonical
194195
o = new DNSOutput();
195196
tc.rrToWire(o, null, false);
196-
assertTrue(Arrays.equals(exp, o.toByteArray()));
197+
assertArrayEquals(exp, o.toByteArray());
197198
}
198199
}

src/test/java/org/xbill/DNS/KEYRecordTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.net.UnknownHostException;
4141
import java.util.Arrays;
4242

43+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
4344
import static org.junit.jupiter.api.Assertions.assertEquals;
4445
import static org.junit.jupiter.api.Assertions.assertNull;
4546
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -85,7 +86,7 @@ public void test_ctor_7arg() throws TextParseException
8586
assertEquals(0x9832, kr.getFlags());
8687
assertEquals(0x12, kr.getProtocol());
8788
assertEquals(0x67, kr.getAlgorithm());
88-
assertTrue(Arrays.equals(key, kr.getKey()));
89+
assertArrayEquals(key, kr.getKey());
8990

9091
// a relative name
9192
try {
@@ -169,7 +170,7 @@ public void test_rdataFromString() throws IOException, TextParseException
169170
kr.getFlags());
170171
assertEquals(KEYRecord.Protocol.EMAIL, kr.getProtocol());
171172
assertEquals(DNSSEC.Algorithm.RSASHA1, kr.getAlgorithm());
172-
assertTrue(Arrays.equals(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, kr.getKey()));
173+
assertArrayEquals(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, kr.getKey());
173174

174175
// basic w/o key
175176
kr = new KEYRecord();

src/test/java/org/xbill/DNS/MXRecordTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
import java.util.Arrays;
4040

41+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
4142
import static org.junit.jupiter.api.Assertions.assertEquals;
4243
import static org.junit.jupiter.api.Assertions.assertTrue;
4344

@@ -80,13 +81,13 @@ public void test_rrToWire() throws TextParseException
8081
mr.rrToWire(dout, null, true);
8182
byte[] out = dout.toByteArray();
8283
byte[] exp = new byte[] { 0x1F, 0x2B, 1, 'm', 1, 'o', 1, 'n', 0 };
83-
assertTrue(Arrays.equals(exp, out));
84+
assertArrayEquals(exp, out);
8485

8586
// case sensitive
8687
dout = new DNSOutput();
8788
mr.rrToWire(dout, null, false);
8889
out = dout.toByteArray();
8990
exp = new byte[] { 0x1F, 0x2B, 1, 'M', 1, 'O', 1, 'n', 0 };
90-
assertTrue(Arrays.equals(exp, out));
91+
assertArrayEquals(exp, out);
9192
}
9293
}

0 commit comments

Comments
 (0)
0