Skip to content

Commit

Permalink
手工合并 #131 pull request的部分内容, thank you, @chenhaipeng
Browse files Browse the repository at this point in the history
  • Loading branch information
calvin1978 committed Nov 9, 2018
1 parent 8786a8b commit 419418f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* 目前主要参考 {@code com.google.common.math.MathPreconditions} , 补充数字为正数或非负数的校验
*
*/
public class MoreValidate {
public class MoreValidate extends org.apache.commons.lang3.Validate {

/**
* 校验为正数则返回该数字,否则抛出异常.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import org.junit.Test;

public class BeanUtilTest {
public class BooleanUtilTest {

@Test
public void test() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import static org.assertj.core.api.Assertions.*;

import java.util.List;
import java.util.Map;

import org.junit.Test;

import com.vip.vjtools.vjkit.collection.ListUtil;
import com.vip.vjtools.vjkit.mapper.BeanMapper;

public class BeanMapperTest {

Expand Down Expand Up @@ -59,6 +59,18 @@ public void copyArrayObject() {

}

@Test
public void copy2Map() {
Teacher teacher = new Teacher("zhang");
Map map = BeanMapper.map(teacher, Map.class);
assertThat(map).containsKeys("name").containsValues("zhang");

Student student = new Student("zhang3", 20, new Teacher("li4"), ListUtil.newArrayList("chinese", "english"));
Map mapStu = BeanMapper.map(student, Map.class);
assertThat(mapStu.containsKey("teacher"));
assertThat(mapStu.get("teacher")).hasFieldOrProperty("name");
}

public static class Student {
public String name;
private int age;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public void nullAndEmpty() {
String nullBeanString = JsonMapper.INSTANCE.toJson(nullBean);
assertThat(nullBeanString).isEqualTo("null");


// Empty List
List<String> emptyList = Lists.newArrayList();
String emptyListString = JsonMapper.INSTANCE.toJson(emptyList);
Expand All @@ -121,6 +122,14 @@ public void nullAndEmpty() {
nullBeanResult = JsonMapper.INSTANCE.fromJson("null", TestBean.class);
assertThat(nullBeanResult).isNull();

nullBeanResult = JsonMapper.INSTANCE.fromJson("", TestBean.class);
assertThat(nullBeanResult).isNull();

nullBeanResult = JsonMapper.INSTANCE.fromJson("{}", TestBean.class);
assertThat(nullBeanResult).isNotNull();
assertThat(nullBeanResult.getDefaultValue()).isEqualTo("hello");


// Null/Empty String for List
List nullListResult = JsonMapper.INSTANCE.fromJson(null, List.class);
assertThat(nullListResult).isNull();
Expand Down

0 comments on commit 419418f

Please sign in to comment.