JUnit单元测试实践:测试工具类和方法(EmptyUtils) (二)

2014-11-24 09:46:40 · 作者: · 浏览: 1
y));

Map emptyMap = new HashMap();
assertTrue(EmptyUtils.isEmpty(emptyMap));
}

@Test
public static void testObjectArrayIsEmpty() {
Integer[] array = { 1, 2, 3 };
assertFalse(EmptyUtils.isEmpty(array));

Integer[] nullArray = null;
assertTrue(EmptyUtils.isEmpty(nullArray));

Integer[] emptyArray = {};
assertTrue(EmptyUtils.isEmpty(emptyArray));
}

@Test
public static void testCollectionNotEmpty() {
List list = Arrays.asList(1, 2, 3);
boolean listWithPositiveSize = EmptyUtils.notEmpty(list);
assertTrue(listWithPositiveSize);

List emptyList = new ArrayList();
boolean listWithZeroSize = EmptyUtils.notEmpty(emptyList);
assertFalse(listWithZeroSize);

List nullList = null;
boolean nullEmpty = EmptyUtils.notEmpty(nullList);
assertFalse(nullEmpty);

Set set = new HashSet();
set.add(100);
boolean setWithPositiveSize = EmptyUtils.notEmpty(set);
assertTrue(setWithPositiveSize);

Set nullSet = null;
assertFalse(EmptyUtils.notEmpty(nullSet));

Set emptySet = new HashSet();
assertFalse(EmptyUtils.notEmpty(emptySet));
}

@Test
public static void testMapNotEmpty() {
Map map = new HashMap();
map.put("mapTest", "mapTestValue");
assertTrue(EmptyUtils.notEmpty(map));

Map nullEmpty = null;
assertFalse(EmptyUtils.notEmpty(nullEmpty));

Map emptyMap = new HashMap();
assertFalse(EmptyUtils.notEmpty(emptyMap));
}

@Test
public static void testObjectArrayNotEmpty() {
Integer[] array = { 1, 2, 3 };
assertTrue(EmptyUtils.notEmpty(array));

Integer[] nullArray = null;
assertFalse(EmptyUtils.notEmpty(nullArray));

Integer[] emptyArray = {};
assertFalse(EmptyUtils.notEmpty(emptyArray));
}

}