mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
Merge remote-tracking branch 'origin/v5-dev' into v5-dev
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package cn.hutool.core.codec;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -14,6 +15,24 @@ public class Base32Test {
|
||||
|
||||
String decodeStr = Base32.decodeStr(encode);
|
||||
Assert.assertEquals(a, decodeStr);
|
||||
|
||||
// 支持小写模式解码
|
||||
decodeStr = Base32.decodeStr(encode.toLowerCase());
|
||||
Assert.assertEquals(a, decodeStr);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hexEncodeAndDecodeTest(){
|
||||
String a = "伦家是一个非常长的字符串";
|
||||
String encode = Base32.encodeHex(StrUtil.utf8Bytes(a));
|
||||
Assert.assertEquals("SIUADPDEMRJ9HBV4N20E9E5AT6EPTPDON3KPBFV7JA2EBBCNSUMADP5OM8======", encode);
|
||||
|
||||
String decodeStr = Base32.decodeStrHex(encode);
|
||||
Assert.assertEquals(a, decodeStr);
|
||||
|
||||
// 支持小写模式解码
|
||||
decodeStr = Base32.decodeStrHex(encode.toLowerCase());
|
||||
Assert.assertEquals(a, decodeStr);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package cn.hutool.core.codec;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -20,4 +21,30 @@ public class Base62Test {
|
||||
String decodeStr = Base62.decodeStr(encode);
|
||||
Assert.assertEquals(a, decodeStr);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encodeAndDecodeInvertedTest() {
|
||||
String a = "伦家是一个非常长的字符串66";
|
||||
String encode = Base62.encodeInverted(a);
|
||||
Assert.assertEquals("17Vku8w4jmg8Dqf8LK9vnNKDmoEwN4RjmVA6f0xSlRRt53IkbNQO", encode);
|
||||
|
||||
String decodeStr = Base62.decodeStrInverted(encode);
|
||||
Assert.assertEquals(a, decodeStr);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encodeAndDecodeRandomTest() {
|
||||
String a = RandomUtil.randomString(RandomUtil.randomInt(1000));
|
||||
String encode = Base62.encode(a);
|
||||
String decodeStr = Base62.decodeStr(encode);
|
||||
Assert.assertEquals(a, decodeStr);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encodeAndDecodeInvertedRandomTest() {
|
||||
String a = RandomUtil.randomString(RandomUtil.randomInt(1000));
|
||||
String encode = Base62.encodeInverted(a);
|
||||
String decodeStr = Base62.decodeStrInverted(encode);
|
||||
Assert.assertEquals(a, decodeStr);
|
||||
}
|
||||
}
|
||||
|
@@ -42,4 +42,32 @@ public class LazyFunLoaderTest {
|
||||
|
||||
Assert.assertFalse(loader.isInitialize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnLoadStaticFactoryMethod1() {
|
||||
|
||||
LazyFunLoader<BigObject> loader = LazyFunLoader.on(BigObject::new);
|
||||
|
||||
Assert.assertNotNull(loader.get());
|
||||
Assert.assertTrue(loader.isInitialize());
|
||||
|
||||
// 对于某些对象,在程序关闭时,需要进行销毁操作
|
||||
loader.ifInitialized(BigObject::destroy);
|
||||
|
||||
Assert.assertTrue(loader.get().isDestroy);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnLoadStaticFactoryMethod2() {
|
||||
|
||||
LazyFunLoader<BigObject> loader = LazyFunLoader.on(BigObject::new);
|
||||
|
||||
// 若从未使用,则可以避免不必要的初始化
|
||||
loader.ifInitialized(it -> {
|
||||
|
||||
Assert.fail();
|
||||
it.destroy();
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user