单元测试由Junit4变更为Junit5

This commit is contained in:
Looly
2024-08-09 14:32:30 +08:00
parent 155c43a6a3
commit c7e0bc5d9f
568 changed files with 7794 additions and 7671 deletions

View File

@@ -6,9 +6,9 @@ import cn.hutool.cache.impl.WeakCache;
import cn.hutool.core.lang.Console;
import cn.hutool.core.thread.ConcurrencyTester;
import cn.hutool.core.thread.ThreadUtil;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.util.concurrent.atomic.AtomicInteger;
@@ -21,7 +21,7 @@ import java.util.concurrent.atomic.AtomicInteger;
public class CacheConcurrentTest {
@Test
@Ignore
@Disabled
public void fifoCacheTest() {
int threadCount = 4000;
final Cache<String, String> cache = new FIFOCache<>(3);
@@ -52,7 +52,7 @@ public class CacheConcurrentTest {
}
@Test
@Ignore
@Disabled
public void lruCacheTest() {
int threadCount = 40000;
final Cache<String, String> cache = new LRUCache<>(1000);
@@ -102,6 +102,6 @@ public class CacheConcurrentTest {
});
long interval = concurrencyTester.getInterval();
// 总耗时应与单次操作耗时在同一个数量级
Assert.assertTrue(interval < delay * 2);
assertTrue(interval < delay * 2);
}
}

View File

@@ -4,8 +4,8 @@ import cn.hutool.cache.impl.TimedCache;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.RandomUtil;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
/**
* 缓存测试用例
@@ -19,8 +19,8 @@ public class CacheTest {
Cache<String,String> fifoCache = CacheUtil.newFIFOCache(3);
fifoCache.setListener((key, value)->{
// 监听测试此测试中只有key1被移除测试是否监听成功
Assert.assertEquals("key1", key);
Assert.assertEquals("value1", value);
assertEquals("key1", key);
assertEquals("value1", value);
});
fifoCache.put("key1", "value1", DateUnit.SECOND.getMillis() * 3);
@@ -30,7 +30,7 @@ public class CacheTest {
//由于缓存容量只有3当加入第四个元素的时候根据FIFO规则最先放入的对象将被移除
String value1 = fifoCache.get("key1");
Assert.assertNull(value1);
assertNull(value1);
}
@Test
@@ -39,7 +39,7 @@ public class CacheTest {
for (int i = 0; i < RandomUtil.randomInt(100, 1000); i++) {
fifoCache.put("key" + i, "value" + i);
}
Assert.assertEquals(100, fifoCache.size());
assertEquals(100, fifoCache.size());
}
@Test
@@ -56,16 +56,16 @@ public class CacheTest {
String value1 = lfuCache.get("key1");
String value2 = lfuCache.get("key2");
String value3 = lfuCache.get("key3");
Assert.assertNotNull(value1);
Assert.assertNull(value2);
Assert.assertNull(value3);
assertNotNull(value1);
assertNull(value2);
assertNull(value3);
}
@Test
public void lfuCacheTest2(){
Cache<String, String> lfuCache = CacheUtil.newLFUCache(3);
final String s = lfuCache.get(null);
Assert.assertNull(s);
assertNull(s);
}
@Test
@@ -81,10 +81,10 @@ public class CacheTest {
lruCache.put("key4", "value4", DateUnit.SECOND.getMillis() * 3);
String value1 = lruCache.get("key1");
Assert.assertNotNull(value1);
assertNotNull(value1);
//由于缓存容量只有3当加入第四个元素的时候根据LRU规则最少使用的将被移除2被移除
String value2 = lruCache.get("key2");
Assert.assertNull(value2);
assertNull(value2);
}
@Test
@@ -103,20 +103,20 @@ public class CacheTest {
//5毫秒后由于value2设置了5毫秒过期因此只有value2被保留下来
String value1 = timedCache.get("key1");
Assert.assertNull(value1);
assertNull(value1);
String value2 = timedCache.get("key2");
Assert.assertEquals("value2", value2);
assertEquals("value2", value2);
//5毫秒后由于设置了默认过期key3只被保留4毫秒因此为null
String value3 = timedCache.get("key3");
Assert.assertNull(value3);
assertNull(value3);
String value3Supplier = timedCache.get("key3", () -> "Default supplier");
Assert.assertEquals("Default supplier", value3Supplier);
assertEquals("Default supplier", value3Supplier);
// 永不过期
String value4 = timedCache.get("key4");
Assert.assertEquals("value4", value4);
assertEquals("value4", value4);
//取消定时清理
timedCache.cancelPruneSchedule();

View File

@@ -1,7 +1,7 @@
package cn.hutool.cache;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import cn.hutool.cache.file.LFUFileCache;
@@ -14,6 +14,6 @@ public class FileCacheTest {
@Test
public void lfuFileCacheTest() {
LFUFileCache cache = new LFUFileCache(1000, 500, 2000);
Assert.assertNotNull(cache);
assertNotNull(cache);
}
}

View File

@@ -1,8 +1,8 @@
package cn.hutool.cache;
import cn.hutool.cache.impl.FIFOCache;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
public class Issue3618Test {
@Test
@@ -12,11 +12,11 @@ public class Issue3618Test {
cache.put(2, 1);
cache.put(3, 1);
Assert.assertEquals(3, cache.size());
assertEquals(3, cache.size());
// issue#3618 对于替换的键值对,不做满队列检查和清除
cache.put(3, 2);
Assert.assertEquals(3, cache.size());
assertEquals(3, cache.size());
}
}

View File

@@ -3,13 +3,13 @@ package cn.hutool.cache;
import cn.hutool.cache.impl.TimedCache;
import cn.hutool.core.lang.Console;
import cn.hutool.core.thread.ThreadUtil;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
public class IssueI8MEIXTest {
@Test
@Ignore
@Disabled
public void getRemoveTest() {
final TimedCache<String, String> cache = new TimedCache<>(200);
cache.put("a", "123");

View File

@@ -4,9 +4,9 @@ import cn.hutool.cache.impl.LRUCache;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
@@ -19,7 +19,7 @@ import java.util.concurrent.atomic.AtomicInteger;
public class LRUCacheTest {
@Test
@Ignore
@Disabled
public void putTest(){
//https://github.com/dromara/hutool/issues/2227
final LRUCache<String, String> cache = CacheUtil.newLRUCache(100, 10);
@@ -55,7 +55,7 @@ public class LRUCacheTest {
for (int i = 0; i < 10; i++) {
sb1.append(cache.get(i));
}
Assert.assertEquals("0123456789", sb1.toString());
assertEquals("0123456789", sb1.toString());
// 新加11此时0最久未使用应该淘汰0
cache.put(11, 11);
@@ -64,7 +64,7 @@ public class LRUCacheTest {
for (int i = 0; i < 10; i++) {
sb2.append(cache.get(i));
}
Assert.assertEquals("null123456789", sb2.toString());
assertEquals("null123456789", sb2.toString());
}
@Test
@@ -82,7 +82,7 @@ public class LRUCacheTest {
cache.put(StrUtil.format("key-{}", i), i);
}
Assert.assertEquals(7, removeCount.get());
Assert.assertEquals(3, cache.size());
assertEquals(7, removeCount.get());
assertEquals(3, cache.size());
}
}

View File

@@ -2,9 +2,9 @@ package cn.hutool.cache;
import cn.hutool.cache.impl.WeakCache;
import cn.hutool.core.lang.Console;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
public class WeakCacheTest {
@@ -14,16 +14,16 @@ public class WeakCacheTest {
cache.put("abc", "123");
cache.put("def", "456");
Assert.assertEquals(2, cache.size());
assertEquals(2, cache.size());
// 检查被MutableObj包装的key能否正常移除
cache.remove("abc");
Assert.assertEquals(1, cache.size());
assertEquals(1, cache.size());
}
@Test
@Ignore
@Disabled
public void removeByGcTest(){
// https://gitee.com/dromara/hutool/issues/I51O7M
WeakCache<String, String> cache = new WeakCache<>(-1);
@@ -31,7 +31,7 @@ public class WeakCacheTest {
cache.put("b", "2");
// 监听
Assert.assertEquals(2, cache.size());
assertEquals(2, cache.size());
cache.setListener(Console::log);
// GC测试