add ClassUtilTest test case (#709)

* add BeanUtilTest test case

* add BeanUtilTest test case

* add BeanUtilTest test case

* add ClassUtilTest test case
pull/713/head
Gdk666 2 years ago committed by GitHub
parent 854b79d95f
commit deafe26db4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,13 +21,11 @@ import cn.hippo4j.common.toolkit.Assert;
import com.github.dozermapper.core.converters.ConversionException; import com.github.dozermapper.core.converters.ConversionException;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import lombok.*; import lombok.*;
import org.junit.Test; import org.junit.Test;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/** /**
* BeanUtil Test * BeanUtil Test
@ -75,6 +73,17 @@ public class BeanUtilTest {
Assert.isTrue(Objects.equals(list.size(), persons.size())); Assert.isTrue(Objects.equals(list.size(), persons.size()));
} }
@Test
public void SetToSetConvertTest() {
final Set<Person> sets = Sets.newHashSet();
sets.add(Person.builder().name("one").age(1).build());
sets.add(Person.builder().name("two").age(2).build());
sets.add(Person.builder().name("three").age(3).build());
final Set<PersonVo> persons = BeanUtil.convert(sets, PersonVo.class);
Assert.isTrue(Objects.equals(sets.size(), persons.size()));
}
@Test @Test
public void copyPropertiesBeanToMapTest() { public void copyPropertiesBeanToMapTest() {
// 测试BeanToMap // 测试BeanToMap

@ -17,8 +17,59 @@
package cn.hippo4j.config.toolkit; package cn.hippo4j.config.toolkit;
import cn.hippo4j.common.toolkit.Assert;
import cn.hutool.core.lang.caller.CallerUtil;
import org.junit.Test;
import java.util.Objects;
/** /**
* ClassUtil Test * ClassUtil Test
*/ */
public class ClassUtilTest { public class ClassUtilTest {
@Test
public void isAssignableFromTest() {
final boolean assignableFrom = ClassUtil.isAssignableFrom(TestClass.class, TestSubClass.class);
Assert.isTrue(assignableFrom);
}
@Test
public void isNotAssignableFromTest() {
final boolean assignableFrom = ClassUtil.isAssignableFrom(TestSubClass.class, TestClass.class);
Assert.isTrue(!assignableFrom);
}
@Test
public void getCanonicalNameTest() {
final String canonicalName = ClassUtil.getCanonicalName(TestClass.class);
Assert.isTrue(Objects.equals("cn.hippo4j.config.toolkit.ClassUtilTest.TestClass", canonicalName));
}
@SuppressWarnings("unused")
static class TestClass {
private String privateField;
protected String field;
private void privateMethod() {
}
public void publicMethod() {
}
}
@SuppressWarnings({"unused", "InnerClassMayBeStatic"})
class TestSubClass extends TestClass {
private String subField;
private void privateSubMethod() {
}
public void publicSubMethod() {
}
}
} }

Loading…
Cancel
Save