Skip to content

Commit 3e369c8

Browse files
committed
test: cleanup unit test, use domain method name instead of implementation
1 parent fe58d13 commit 3e369c8

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

library/src/test/java/com/alibaba/dcm/DnsCacheManipulatorTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void test_setDnsCache_getAllDnsCache() {
9595
host, new String[]{IP1}, Long.MAX_VALUE);
9696
DnsCacheEntry actual = allDnsCacheEntries.get(0);
9797

98-
assertEqualsIgnoreHostCase(expected, actual);
98+
assertEqualsDnsCacheEntry(expected, actual);
9999

100100
DnsCacheEntry another = DnsCacheManipulator.getDnsCache(host);
101101
DnsCacheEntry another2 = DnsCacheManipulator.getDnsCache(host);
@@ -132,7 +132,7 @@ public void test_setNotExistedDomain_RemoveThenReLookupAndNotExisted() throws Ex
132132

133133
final List<DnsCacheEntry> negativeCache = DnsCacheManipulator.listDnsNegativeCache();
134134
assertEquals(1, negativeCache.size());
135-
assertEqualsIgnoreCase(DOMAIN_NOT_EXISTED, negativeCache.get(0).getHost());
135+
assertEqualsHostName(DOMAIN_NOT_EXISTED, negativeCache.get(0).getHost());
136136
}
137137

138138
@Test
@@ -149,7 +149,7 @@ public void test_setNotExistedDomain_canExpire_thenReLookupAndNotExisted() throw
149149

150150
final List<DnsCacheEntry> negativeCache = DnsCacheManipulator.listDnsNegativeCache();
151151
assertEquals(1, negativeCache.size());
152-
assertEqualsIgnoreCase(DOMAIN_NOT_EXISTED, negativeCache.get(0).getHost());
152+
assertEqualsHostName(DOMAIN_NOT_EXISTED, negativeCache.get(0).getHost());
153153
}
154154

155155
////////////////////////////////////////////////////////////////////
@@ -295,14 +295,14 @@ public void test_multi_ips_in_config_file() {
295295
new String[]{IP1, IP2}, Long.MAX_VALUE);
296296

297297
final DnsCacheEntry actual = DnsCacheManipulator.getDnsCache(host);
298-
assertEqualsIgnoreHostCase(expected, actual);
298+
assertEqualsDnsCacheEntry(expected, actual);
299299

300300
final String hostLoose = "www.hello-multi-ips-loose.com";
301301
DnsCacheEntry expectedLoose = new DnsCacheEntry(hostLoose,
302302
new String[]{IP1, IP2, IP3, IP4}, Long.MAX_VALUE);
303303

304304
DnsCacheEntry actualLoose = DnsCacheManipulator.getDnsCache(hostLoose);
305-
assertEqualsIgnoreHostCase(expectedLoose, actualLoose);
305+
assertEqualsDnsCacheEntry(expectedLoose, actualLoose);
306306
}
307307

308308
@Test

library/src/test/java/com/alibaba/dcm/Util.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ static void assertOnlyNegativeCache(long start, long end) {
6161
assertBetween(first.getExpiration().getTime(), start, end);
6262
}
6363

64-
static void assertEqualsIgnoreHostCase(DnsCacheEntry expected, DnsCacheEntry actual) {
65-
assertEqualsIgnoreCase(expected.getHost(), actual.getHost());
64+
static void assertEqualsDnsCacheEntry(DnsCacheEntry expected, DnsCacheEntry actual) {
65+
assertEqualsHostName(expected.getHost(), actual.getHost());
6666
assertArrayEquals(expected.getIps(), actual.getIps());
6767

6868
final long expectedExpiration = expected.getExpiration().getTime();
@@ -80,8 +80,13 @@ static void assertEqualsIgnoreHostCase(DnsCacheEntry expected, DnsCacheEntry act
8080
}
8181
}
8282

83-
static void assertEqualsIgnoreCase(String expected, String actual) {
84-
assertEquals(expected.toLowerCase(), actual.toLowerCase());
83+
static void assertEqualsHostName(String expected, String actual) {
84+
if (isJdkAtMost8()) {
85+
// java 8-, host name is unified to lower case by InetAddress
86+
assertEquals(expected.toLowerCase(), actual.toLowerCase());
87+
} else {
88+
assertEquals(expected, actual);
89+
}
8590
}
8691

8792
static void assertBetween(long actual, long start, long end) {

0 commit comments

Comments
 (0)