mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
6.x
This commit is contained in:
87
hutool-extra/src/test/java/cn/hutool/extra/aop/AopTest.java
Normal file
87
hutool-extra/src/test/java/cn/hutool/extra/aop/AopTest.java
Normal file
@@ -0,0 +1,87 @@
|
||||
package cn.hutool.extra.aop;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.extra.aop.aspects.TimeIntervalAspect;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* AOP模块单元测试
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
public class AopTest {
|
||||
|
||||
@Test
|
||||
public void aopTest() {
|
||||
Animal cat = ProxyUtil.proxy(new Cat(), TimeIntervalAspect.class);
|
||||
String result = cat.eat();
|
||||
Assert.assertEquals("猫吃鱼", result);
|
||||
cat.seize();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aopByAutoCglibTest() {
|
||||
Dog dog = ProxyUtil.proxy(new Dog(), TimeIntervalAspect.class);
|
||||
String result = dog.eat();
|
||||
Assert.assertEquals("狗吃肉", result);
|
||||
|
||||
dog.seize();
|
||||
}
|
||||
|
||||
interface Animal {
|
||||
String eat();
|
||||
|
||||
void seize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 有接口
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
static class Cat implements Animal {
|
||||
|
||||
@Override
|
||||
public String eat() {
|
||||
return "猫吃鱼";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void seize() {
|
||||
Console.log("抓了条鱼");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 无接口
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
static class Dog {
|
||||
public String eat() {
|
||||
return "狗吃肉";
|
||||
}
|
||||
|
||||
public void seize() {
|
||||
Console.log("抓了只鸡");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCGLIBProxy() {
|
||||
TagObj target = new TagObj();
|
||||
//目标类设置标记
|
||||
target.setTag("tag");
|
||||
|
||||
TagObj proxy = ProxyUtil.proxy(target, TimeIntervalAspect.class);
|
||||
//代理类获取标记tag (断言错误)
|
||||
Assert.assertEquals("tag", proxy.getTag());
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class TagObj{
|
||||
private String tag;
|
||||
}
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.extra.qrcode;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.img.ImgUtil;
|
||||
import cn.hutool.swing.img.ImgUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
|
@@ -0,0 +1,16 @@
|
||||
package cn.hutool.extra.system;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.extra.system.oshi.OshiUtil;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@Ignore
|
||||
public class OshiPrintTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void printCpuInfo(){
|
||||
Console.log(OshiUtil.getCpuInfo());
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
package cn.hutool.extra.system;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.extra.system.oshi.CpuInfo;
|
||||
import cn.hutool.extra.system.oshi.OshiUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import oshi.software.os.OSProcess;
|
||||
|
||||
/**
|
||||
* 测试参考:<a href="https://github.com/oshi/oshi/blob/master/oshi-core/src/test/java/oshi/SystemInfoTest.java">https://github.com/oshi/oshi/blob/master/oshi-core/src/test/java/oshi/SystemInfoTest.java</a>
|
||||
*/
|
||||
public class OshiTest {
|
||||
|
||||
@Test
|
||||
public void getMemoryTest() {
|
||||
long total = OshiUtil.getMemory().getTotal();
|
||||
Assert.assertTrue(total > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCupInfo() {
|
||||
CpuInfo cpuInfo = OshiUtil.getCpuInfo();
|
||||
Assert.assertNotNull(cpuInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCurrentProcessTest() {
|
||||
final OSProcess currentProcess = OshiUtil.getCurrentProcess();
|
||||
Assert.assertEquals("java", currentProcess.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void getUsedTest() {
|
||||
while (true) {
|
||||
Console.log(OshiUtil.getCpuInfo().getUsed());
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
package cn.hutool.extra.system;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class SystemUtilTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void dumpTest() {
|
||||
SystemUtil.dumpSystemInfo();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCurrentPidTest() {
|
||||
long pid = SystemUtil.getCurrentPID();
|
||||
Assert.assertTrue(pid > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getJavaInfoTest() {
|
||||
JavaInfo javaInfo = SystemUtil.getJavaInfo();
|
||||
Assert.assertNotNull(javaInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getJavaRuntimeInfoTest() {
|
||||
JavaRuntimeInfo info = SystemUtil.getJavaRuntimeInfo();
|
||||
Assert.assertNotNull(info);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getOsInfoTest() {
|
||||
OsInfo osInfo = SystemUtil.getOsInfo();
|
||||
Assert.assertNotNull(osInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHostInfo() {
|
||||
HostInfo hostInfo = SystemUtil.getHostInfo();
|
||||
Assert.assertNotNull(hostInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUserInfoTest(){
|
||||
// https://gitee.com/dromara/hutool/issues/I3NM39
|
||||
final UserInfo userInfo = SystemUtil.getUserInfo();
|
||||
Assert.assertTrue(userInfo.getTempDir().endsWith(File.separator));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user