@@ -194,8 +194,7 @@ public void test_setDnsCachePolicy() throws Exception {
194194 InetAddress .getByName (host ).getHostAddress ();
195195
196196 final DnsCacheEntry dnsCache = DnsCacheManipulator .getDnsCache (host );
197- assertTrue (tick < dnsCache .getExpiration ().getTime () &&
198- dnsCache .getExpiration ().getTime () < tick + 2001 );
197+ assertBetween (dnsCache .getExpiration ().getTime (), tick , tick + 2001 );
199198
200199 sleep (1001 );
201200
@@ -212,8 +211,7 @@ public void test_setDnsCachePolicy() throws Exception {
212211 InetAddress .getByName (host ).getHostAddress ();
213212 final DnsCacheEntry relookup = DnsCacheManipulator .getDnsCache (host );
214213 final long relookupTick = currentTimeMillis ();
215- assertTrue (relookupTick < relookup .getExpiration ().getTime () &&
216- relookup .getExpiration ().getTime () < relookupTick + 2001 );
214+ assertBetween (relookup .getExpiration ().getTime (), relookupTick , relookupTick + 2001 );
217215 }
218216
219217 @ Test
@@ -231,8 +229,7 @@ public void test_setNegativeDnsCachePolicy() throws Exception {
231229 final List <DnsCacheEntry > negativeCache = DnsCacheManipulator .getWholeDnsCache ().getNegativeCache ();
232230 assertEquals (1 , negativeCache .size ());
233231 final DnsCacheEntry dnsCache = negativeCache .get (0 );
234- assertTrue (tick < dnsCache .getExpiration ().getTime () &&
235- dnsCache .getExpiration ().getTime () < tick + 2001 );
232+ assertBetween (dnsCache .getExpiration ().getTime (), tick , tick + 2001 );
236233
237234 sleep (1000 );
238235 try {
@@ -254,7 +251,13 @@ public void test_setNegativeDnsCachePolicy() throws Exception {
254251 final List <DnsCacheEntry > relookupNegativeCache = DnsCacheManipulator .getWholeDnsCache ().getNegativeCache ();
255252 assertEquals (1 , relookupNegativeCache .size ());
256253 final DnsCacheEntry relookup = relookupNegativeCache .get (0 );
257- assertTrue (relookupTick < relookup .getExpiration ().getTime () &&
258- relookup .getExpiration ().getTime () < relookupTick + 2001 );
254+ assertBetween (relookup .getExpiration ().getTime (), relookupTick , relookupTick + 2001 );
255+ }
256+
257+ static void assertBetween (long actual , long start , long end ) {
258+ final boolean ok = (start <= actual ) && (actual <= end );
259+ if (!ok ) {
260+ fail (start + " <= " + actual + " <= " + end + ", failed!" );
261+ }
259262 }
260263}
0 commit comments