|
|
@ -26,8 +26,7 @@ import java.util.ArrayList; |
|
|
|
import java.util.LinkedHashMap; |
|
|
|
import java.util.LinkedHashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
import static org.junit.Assert.assertNull; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class JSONUtilsTest { |
|
|
|
public class JSONUtilsTest { |
|
|
|
|
|
|
|
|
|
|
@ -73,7 +72,7 @@ public class JSONUtilsTest { |
|
|
|
result = JSONUtils.toJsonString(null); |
|
|
|
result = JSONUtils.toJsonString(null); |
|
|
|
logger.info(result); |
|
|
|
logger.info(result); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals(result,"null"); |
|
|
|
assertEquals("null", result); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -86,25 +85,27 @@ public class JSONUtilsTest { |
|
|
|
//Invoke toList
|
|
|
|
//Invoke toList
|
|
|
|
List<LinkedHashMap> result = JSONUtils.toList(expected ,LinkedHashMap.class); |
|
|
|
List<LinkedHashMap> result = JSONUtils.toList(expected ,LinkedHashMap.class); |
|
|
|
//Equal list size=1
|
|
|
|
//Equal list size=1
|
|
|
|
assertEquals(result.size(),1); |
|
|
|
assertEquals(1,result.size()); |
|
|
|
|
|
|
|
|
|
|
|
//Transform entity to LinkedHashMap<String, Object>
|
|
|
|
//Transform entity to LinkedHashMap<String, Object>
|
|
|
|
LinkedHashMap<String, Object> entity = result.get(0); |
|
|
|
LinkedHashMap<String, Object> entity = result.get(0); |
|
|
|
|
|
|
|
|
|
|
|
//Equal expected values
|
|
|
|
//Equal expected values
|
|
|
|
assertEquals(entity.get("mysql service name"),"mysql200"); |
|
|
|
assertEquals("mysql200",entity.get("mysql service name")); |
|
|
|
assertEquals(entity.get("mysql address"),"192.168.xx.xx"); |
|
|
|
assertEquals("192.168.xx.xx", entity.get("mysql address")); |
|
|
|
assertEquals(entity.get("port"),"3306"); |
|
|
|
assertEquals("3306", entity.get("port")); |
|
|
|
assertEquals(entity.get("no index of number"),"80"); |
|
|
|
assertEquals("80", entity.get("no index of number")); |
|
|
|
assertEquals(entity.get("database client connections"),"190"); |
|
|
|
assertEquals("190", entity.get("database client connections")); |
|
|
|
|
|
|
|
|
|
|
|
//If param is null, then return null
|
|
|
|
//If param is null, then return empty list
|
|
|
|
result = JSONUtils.toList(null ,LinkedHashMap.class); |
|
|
|
result = JSONUtils.toList(null ,LinkedHashMap.class); |
|
|
|
assertNull(result); |
|
|
|
assertNotNull(result); |
|
|
|
|
|
|
|
assertTrue(result.isEmpty()); |
|
|
|
|
|
|
|
|
|
|
|
//If param is incorrect, then return null and log error message
|
|
|
|
//If param is incorrect, then return empty list and log error message
|
|
|
|
result = JSONUtils.toList("}{" ,LinkedHashMap.class); |
|
|
|
result = JSONUtils.toList("}{" ,LinkedHashMap.class); |
|
|
|
assertNull(result); |
|
|
|
assertNotNull(result); |
|
|
|
|
|
|
|
assertTrue(result.isEmpty()); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|