Java tutorial
/* * Copyright (c) 2007 NTT DATA Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package jp.terasoluna.fw.util; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.lang.reflect.InvocationTargetException; import java.math.BigInteger; import java.security.AlgorithmParameterGenerator; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Vector; import org.apache.commons.beanutils.BeanUtilsBean; import org.apache.commons.beanutils.ConversionException; import org.apache.commons.beanutils.PropertyUtilsBean; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.springframework.test.util.ReflectionTestUtils; /** * {@link jp.terasoluna.fw.client.util.ConvertUtil} ? * <p> * <h4>???</h4> ????? * <p> * @see jp.terasoluna.fw.client.util.ConvertUtil */ public class ConvertUtilTest { /** * PropertyUtilsBean */ private PropertyUtilsBean defaultPropertyUtilsBean = null; /** * ??? */ @Before public void setUp() { BeanUtilsBean beanUtilsBean = BeanUtilsBean.getInstance(); defaultPropertyUtilsBean = beanUtilsBean.getPropertyUtils(); } /** * ?? * @throws Exception ????? */ @After public void tearDown() throws Exception { BeanUtilsBean beanUtilsBean = BeanUtilsBean.getInstance(); ReflectionTestUtils.setField(beanUtilsBean, "propertyUtilsBean", defaultPropertyUtilsBean); } /** * testToArray01() <br> * <br> * () <br> * () obj:null<br> * <br> * () Object[]:?????Object[] (??0?????)<br> * <br> * obj?null??????????Object[]??????? <br> * @throws Exception ????? */ @Test public void testToArray01() throws Exception { // Object[] result = ConvertUtil.toArray(null); // assertEquals(0, result.length); } /** * testToArray02() <br> * <br> * () <br> * C <br> * <br> * () obj:""()<br> * <br> * () Object[]:???Object[] (???????)<br> * *?0:""()<br> * <br> * obj?""()????????Object[]??????? <br> * @throws Exception ????? */ @Test public void testToArray02() throws Exception { // Object[] result = ConvertUtil.toArray(""); // assertEquals(1, result.length); assertEquals("", result[0]); } /** * testToArray03() <br> * <br> * () <br> * C <br> * <br> * () obj:" "()<br> * <br> * () Object[]:???Object[] (???????)<br> * *?0:" "()<br> * <br> * obj?" "()????????Object[]??????? <br> * @throws Exception ????? */ @Test public void testToArray03() throws Exception { // Object[] result = ConvertUtil.toArray(" "); // assertEquals(1, result.length); assertEquals(" ", result[0]); } /** * testToArray04() <br> * <br> * () <br> * E <br> * <br> * () obj:"array"<br> * <br> * () Object[]:???Object[] (???????)<br> * *?0:"array"<br> * <br> * obj??????????Object[]??????? <br> * @throws Exception ????? */ @Test public void testToArray04() throws Exception { // Object[] result = ConvertUtil.toArray("array"); // assertEquals(1, result.length); assertEquals("array", result[0]); } /** * testToArray05() <br> * <br> * () <br> * D <br> * <br> * () obj:?????Object[]<br> * <br> * () Object[]:?????Object[] (????????)<br> * <br> * obj?????????????????Object[]??????? <br> * @throws Exception ????? */ @Test public void testToArray05() throws Exception { // ?? Object obj = new Object[0]; // Object[] result = ConvertUtil.toArray(obj); // assertEquals(0, result.length); } /** * testToArray06() <br> * <br> * () <br> * D <br> * <br> * () obj:????String[]<br> * *??:"array"<br> * <br> * () Object[]:???Object[] (???????)<br> * *?0:"array"<br> * <br> * obj???????????????Object[]??????? <br> * @throws Exception ????? */ @Test public void testToArray06() throws Exception { // ?? String[] obj = { "array" }; // Object[] result = ConvertUtil.toArray(obj); // assertEquals(1, result.length); assertEquals("array", result[0]); } /** * testToArray07() <br> * <br> * () <br> * D <br> * <br> * () obj:????Object[]<br> * *??:"array"<br> * *?:1<br> * *?:Map (key="foo" value="something")<br> * <br> * () Object[]:???Object[] (???????)<br> * *?0:"array"<br> * *?1:1<br> * *?2:Map(key="foo" value="something")<br> * <br> * obj???????????????Object[]??????? <br> * @throws Exception ????? */ @Test public void testToArray07() throws Exception { // ?? Object[] obj = new Object[3]; obj[0] = "array"; obj[1] = 1; Map<String, String> map = new HashMap<String, String>(); map.put("foo", "something"); obj[2] = map; // Object[] result = ConvertUtil.toArray(obj); // assertEquals(3, result.length); assertEquals("array", result[0]); assertEquals(1, result[1]); assertEquals(map, result[2]); Map<?, ?> mapResult = (Map<?, ?>) result[2]; assertEquals("something", mapResult.get("foo")); } /** * testToArray08() <br> * <br> * () <br> * D <br> * <br> * () obj:?????Collection<br> * <br> * () Object[]:?????Object[] (????????)<br> * <br> * obj??????Collection??????????Object[]??????? <br> * @throws Exception ????? */ @Test public void testToArray08() throws Exception { // ?? Collection<?> obj = new Vector<Object>(); // Object[] result = ConvertUtil.toArray(obj); // assertEquals(0, result.length); } /** * testToArray09() <br> * <br> * () <br> * D <br> * <br> * () obj:????Collection<br> * *?0:"collection"<br> * <br> * () Object[]:???Object[] (???????)<br> * *?0:"collection"<br> * <br> * obj?????Collection?????????Object[]??????? <br> * @throws Exception ????? */ @Test public void testToArray09() throws Exception { // ?? Collection<String> obj = new Vector<String>(); obj.add("collection"); // Object[] result = ConvertUtil.toArray(obj); // assertEquals(1, result.length); assertEquals("collection", result[0]); } /** * testToArray10() <br> * <br> * () <br> * D <br> * <br> * () obj:????Collection<br> * *?0:"collection"<br> * *?1:1<br> * *?2:Map(key="key" value="something")<br> * <br> * () Object[]:???Object[] (???????)<br> * *?0:"collection"<br> * *?1:1<br> * *?2:Map(key="foo" value="something")<br> * <br> * obj?????collection?????????Object[]??????? <br> * @throws Exception ????? */ @Test public void testToArray10() throws Exception { // ?? Collection<Object> obj = new Vector<Object>(); obj.add("collection"); obj.add(1); Map<String, String> map = new HashMap<String, String>(); map.put("foo", "something"); obj.add(map); // Object[] result = ConvertUtil.toArray(obj); // assertEquals(3, result.length); assertEquals("collection", result[0]); assertEquals(1, result[1]); Map<?, ?> mapResult = (Map<?, ?>) result[2]; assertEquals("something", mapResult.get("foo")); } /** * testToList01() <br> * <br> * () <br> * C,G <br> * <br> * () obj:null<br> * () elementClass:null<br> * <br> * () :IllegalArgumentException<br> * ?: "Argument 'elementClass' (" + Class.class.getName() + ") is null"<br> * <br> * elementClass?null?????IllegalArgumentException?????? <br> * @throws Exception ????? */ @Test public void testToList01() throws Exception { // try { ConvertUtil.toList(null, null); fail("IllegalArgumentException???????"); } catch (IllegalArgumentException e) { // assertEquals(IllegalArgumentException.class.getName(), e.getClass().getName()); assertEquals("Argument 'elementClass' (" + Class.class.getName() + ") is null", e.getMessage()); } } /** * testToList02() <br> * <br> * () <br> * C <br> * <br> * () obj:null<br> * () elementClass:Object.class<br> * <br> * () List:?????List<Object> (????????)<br> * <br> * obj?null?????elementsClass????List??????? <br> * @throws Exception ????? */ @Test public void testToList02() throws Exception { // List<Object> result = ConvertUtil.toList(null, Object.class); // assertEquals(0, result.size()); } /** * testToList03() <br> * <br> * () <br> * C <br> * <br> * () obj:""()<br> * () elementClass:Object.class<br> * <br> * () List:???List<Object> (???????)<br> * *?0:""()<br> * <br> * obj?""()?????elementsClass????List??????? <br> * @throws Exception ????? */ @Test public void testToList03() throws Exception { // List<Object> result = ConvertUtil.toList("", Object.class); // assertEquals(1, result.size()); assertEquals("", result.get(0)); } /** * testToList04() <br> * <br> * () <br> * C <br> * <br> * () obj:" "()<br> * () elementClass:Object.class<br> * <br> * () List:???List<Object> (???????)<br> * *?0:" "()<br> * <br> * obj?""()?????elementsClass????List??????? <br> * @throws Exception ????? */ @Test public void testToList04() throws Exception { // List<Object> result = ConvertUtil.toList(" ", Object.class); // assertEquals(1, result.size()); assertEquals(" ", result.get(0)); } /** * testToList05() <br> * <br> * () <br> * E <br> * <br> * () obj:"list"<br> * () elementClass:Object.class<br> * <br> * () List:???List<Object> (???????)<br> * *?0:"list"<br> * <br> * obj??????elementsClass????List??????? <br> * @throws Exception ????? */ @Test public void testToList05() throws Exception { // List<Object> result = ConvertUtil.toList("list", Object.class); // assertEquals(1, result.size()); assertEquals("list", result.get(0)); } /** * testToList06() <br> * <br> * () <br> * G <br> * <br> * () obj:"list"<br> * () elementClass:Thread.class<br> * <br> * () :IllegalArgumentException<br> * ?: "Unable to cast '" + obj??? + "' to '" + elementClass??? + "'"<br> * ??:ClassCastException<br> * ???:"Unable to cast '" + obj??? + "' to '" + elementClass??? + "'"<br> * <br> * obj??elementClass???????????? ??????IllegalArgumentException?????? <br> * @throws Exception ????? */ @Test public void testToList06() throws Exception { // try { ConvertUtil.toList("list", Thread.class); fail("IllegalArgumentException???????"); } catch (IllegalArgumentException e) { // assertEquals(IllegalArgumentException.class.getName(), e.getClass().getName()); assertEquals("Unable to cast '" + "list".getClass().getName() + "' to '" + Thread.class.getName() + "'", e.getMessage()); assertEquals(ClassCastException.class.getName(), e.getCause().getClass().getName()); assertEquals("Unable to cast '" + "list".getClass().getName() + "' to '" + Thread.class.getName() + "'", e.getCause().getMessage()); } } /** * testToList07() <br> * <br> * () <br> * D <br> * <br> * () obj:?????Object[]<br> * () elementClass:String.class<br> * <br> * () List:?????List<String> (????????)<br> * <br> * obj????????????elementsClass????List??????? <br> * @throws Exception ????? */ @Test public void testToList07() throws Exception { // ?? Object[] obj = new Object[0]; // List<String> result = ConvertUtil.toList(obj, String.class); // assertEquals(0, result.size()); } /** * testToList08() <br> * <br> * () <br> * D <br> * <br> * () obj:????Object[]<br> * *?0:"foo"<br> * () elementClass:String.class<br> * <br> * () List:???List<String> (???????)<br> * *?0:"foo"<br> * <br> * obj???????????elementsClass????List??????? <br> * @throws Exception ????? */ @Test public void testToList08() throws Exception { // ?? Object[] obj = { "foo" }; // List<String> result = ConvertUtil.toList(obj, String.class); // assertEquals(1, result.size()); assertEquals("foo", result.get(0)); } /** * testToList09() <br> * <br> * () <br> * D <br> * <br> * () obj:????Object[]<br> * *?0:"foo"<br> * *?2:"bar"<br> * *?3:"baz"<br> * () elementClass:String.class<br> * <br> * () List:???List<String> (???????)<br> * *?0:"foo"<br> * *?1:"bar"<br> * *?2:"baz"<br> * <br> * obj???????????elementsClass????List??????? <br> * @throws Exception ????? */ @Test public void testToList09() throws Exception { // ?? Object[] obj = new Object[3]; obj[0] = "foo"; obj[1] = "bar"; obj[2] = "baz"; // List<String> result = ConvertUtil.toList(obj, String.class); // assertEquals(3, result.size()); assertEquals("foo", result.get(0)); assertEquals("bar", result.get(1)); assertEquals("baz", result.get(2)); } /** * testToList10() <br> * <br> * () <br> * G <br> * <br> * () obj:????Object[]<br> * *?0:"foo"<br> * *?2:Thread<br> * *?3:"baz"<br> * () elementClass:String.class<br> * <br> * () :IllegalArgumentException<br> * ?: "Unable to cast '" + Thread??? + "' to '" + elementClass??? + "'"<br> * ??:ClassCastException<br> * ???: "Unable to cast '" + Thread??? + "' to '" + elementClass??? + "'"<br> * <br> * obj???elementClass?????????????? ?????????IllegalArgumentException???? ?? <br> * @throws Exception ????? */ @Test public void testToList10() throws Exception { // ?? Object[] obj = new Object[3]; obj[0] = "foo"; obj[1] = new Thread(); obj[2] = "baz"; // try { ConvertUtil.toList(obj, String.class); fail("IllegalArgumentException???????"); } catch (IllegalArgumentException e) { // assertEquals(IllegalArgumentException.class.getName(), e.getClass().getName()); assertEquals("Unable to cast '" + Thread.class.getName() + "' to '" + String.class.getName() + "'", e.getMessage()); assertEquals(ClassCastException.class.getName(), e.getCause().getClass().getName()); assertEquals("Unable to cast '" + Thread.class.getName() + "' to '" + String.class.getName() + "'", e.getCause().getMessage()); } } /** * testToList11() <br> * <br> * () <br> * D <br> * <br> * () obj:?????Collection<br> * () elementClass:String.class<br> * <br> * () List:?????List<String> (????????)<br> * <br> * obj??????Collection?????elementsClass????List??????? <br> * @throws Exception ????? */ @Test public void testToList11() throws Exception { // ?? Collection<?> obj = new Vector<Object>(); // List<String> result = ConvertUtil.toList(obj, String.class); // assertEquals(0, result.size()); } /** * testToList12() <br> * <br> * () <br> * D <br> * <br> * () obj:????Collection<br> * *?0:"foo"<br> * () elementClass:String.class<br> * <br> * () List:???List<String> (???????)<br> * *?0:"foo"<br> * <br> * obj?????Collection?????elementsClass????List??????? <br> * @throws Exception ????? */ @Test public void testToList12() throws Exception { // ?? Collection<String> obj = new Vector<String>(); obj.add("foo"); // List<String> result = ConvertUtil.toList(obj, String.class); // assertEquals(1, result.size()); assertEquals("foo", result.get(0)); } /** * testToList13() <br> * <br> * () <br> * D <br> * <br> * () obj:????Collection<br> * *?0:"foo"<br> * *?2:"bar"<br> * *?3:"baz"<br> * () elementClass:String.class<br> * <br> * () List:???List<String> (???????)<br> * *?0:"foo"<br> * *?1:"bar"<br> * *?2:"baz"<br> * <br> * obj?????Collection?????elementsClass????List??????? <br> * @throws Exception ????? */ @Test public void testToList13() throws Exception { // ?? Collection<String> obj = new Vector<String>(); obj.add("foo"); obj.add("bar"); obj.add("baz"); // List<String> result = ConvertUtil.toList(obj, String.class); // assertEquals(3, result.size()); assertEquals("foo", result.get(0)); assertEquals("bar", result.get(1)); assertEquals("baz", result.get(2)); } /** * testToList14() <br> * <br> * () <br> * G <br> * <br> * () obj:????Collection<br> * *?0:"foo"<br> * *?2:Thread<br> * *?3:"baz"<br> * () elementClass:String.class<br> * <br> * () :IllegalArgumentException<br> * ?: "Unable to cast '" + Thread??? + "' to '" + elementClass??? + "'"<br> * ??:ClassCastException<br> * ???: "Unable to cast '" + Thread??? + "' to '" + elementClass??? + "'"<br> * <br> * obj?Collection?elementClass?????????? ?????????????IllegalArgumentException???? ?? <br> * @throws Exception ????? */ @Test public void testToList14() throws Exception { // ?? Object[] obj = new Object[3]; obj[0] = "foo"; obj[1] = new Thread(); obj[2] = "baz"; // try { ConvertUtil.toList(obj, String.class); fail("IllegalArgumentException???????"); } catch (IllegalArgumentException e) { // assertEquals(IllegalArgumentException.class.getName(), e.getClass().getName()); assertEquals("Unable to cast '" + Thread.class.getName() + "' to '" + String.class.getName() + "'", e.getMessage()); assertEquals(ClassCastException.class.getName(), e.getCause().getClass().getName()); assertEquals("Unable to cast '" + Thread.class.getName() + "' to '" + String.class.getName() + "'", e.getCause().getMessage()); } } /** * testConvertObjectClass01() <br> * <br> * () <br> * G <br> * <br> * () obj:"object"<br> * () clazz:null<br> * <br> * () :IllegalArgumentException<br> * ?: "Argument 'clazz' (" + Object.class.getName() + ") is null"<br> * <br> * clazz?null?????IllegalArgumentException?????? <br> * @throws Exception ????? */ @Test public void testConvertObjectClass01() throws Exception { // try { ConvertUtil.convert("object", null); fail("IllegalArgumentException???????"); } catch (IllegalArgumentException e) { // assertEquals(IllegalArgumentException.class.getName(), e.getClass().getName()); assertEquals("Argument 'clazz' (" + Object.class.getName() + ") is null", e.getMessage()); } } /** * testConvertObjectClass02() <br> * <br> * () <br> * C <br> * <br> * () obj:null<br> * () clazz:Object.class<br> * <br> * () <T>:null<br> * <br> * obj?null?????null??????? <br> * @throws Exception ????? */ @Test public void testConvertObjectClass02() throws Exception { // // assertNull(ConvertUtil.convert(null, Object.class)); } /** * testConvertObjectClass03() <br> * <br> * () <br> * E <br> * <br> * () obj:List (ArrayList??)<br> * () clazz:ArrayList.class<br> * <br> * () <T>:List (obj????????)<br> * <br> * obj????????? <br> * @throws Exception ????? */ @Test public void testConvertObjectClass03() throws Exception { // ?? List<?> list = new ArrayList<Object>(); // List<?> result = ConvertUtil.convert(list, ArrayList.class); // assertSame(list, result); } /** * testConvertObjectClass04() <br> * <br> * () <br> * E <br> * <br> * () obj:Thread<br> * () clazz:AlgorithmParameterGenerator.class<br> * <br> * () <T>:IllegalArgumentException??<br> * <br> * obj??clazz????????IllegalArgumentException?????? <br> * @throws Exception ????? */ @Test public void testConvertObjectClass04() throws Exception { // ?? Thread thread = new Thread(); // try { ConvertUtil.convert(thread, AlgorithmParameterGenerator.class); fail(); } catch (IllegalArgumentException e) { } } /** * testConvertIfNotNull01() <br> * <br> * () <br> * G <br> * <br> * () obj:"object"<br> * () clazz:null<br> * <br> * () :IllegalArgumentException<br> * ?: "Argument 'clazz' (" + Object.class.getName() + ") is null"<br> * <br> * clazz?null?????IllegalArgumentException?????? <br> * @throws Exception ????? */ @Test public void testConvertIfNotNull01() throws Exception { // try { ConvertUtil.convertIfNotNull("object", null); fail("IllegalArgumentException???????"); } catch (IllegalArgumentException e) { // assertEquals(IllegalArgumentException.class.getName(), e.getClass().getName()); assertEquals("Argument 'clazz' (" + Object.class.getName() + ") is null", e.getMessage()); } } /** * testConvertIfNotNull02() <br> * <br> * () <br> * C <br> * <br> * () obj:null<br> * () clazz:Object.class<br> * <br> * () :IllegalArgumentException<br> * ?: "Unable to cast 'null' to '" + clazz??? + "'"<br> * ??:ClassCastException<br> * ???: "Unable to cast 'null' to '" + clazz??? + "'"<br> * <br> * obj?null?????IllegalArgumentException?????? <br> * @throws Exception ????? */ @Test public void testConvertIfNotNull02() throws Exception { // try { ConvertUtil.convertIfNotNull(null, Object.class); fail("IllegalArgumentException???????"); } catch (IllegalArgumentException e) { // assertEquals(IllegalArgumentException.class.getName(), e.getClass().getName()); assertEquals("Unable to cast 'null' to '" + Object.class.getName() + "'", e.getMessage()); assertEquals(ClassCastException.class.getName(), e.getCause().getClass().getName()); assertEquals("Unable to cast 'null' to '" + Object.class.getName() + "'", e.getCause().getMessage()); } } /** * testConvertIfNotNull03() <br> * <br> * () <br> * E <br> * <br> * () obj:List (ArrayList??)<br> * () clazz:ArrayList.class<br> * <br> * () <T>:List (obj????????)<br> * <br> * obj????????? <br> * @throws Exception ????? */ @Test public void testConvertIfNotNull03() throws Exception { // ?? List<?> list = new ArrayList<Object>(); // List<?> result = ConvertUtil.convertIfNotNull(list, ArrayList.class); // assertSame(list, result); } /** * testConvertIfNotNull04() <br> * <br> * () <br> * E <br> * <br> * () obj:Thread<br> * () clazz:AlgorithmParameterGenerator.class<br> * <br> * () IllegalArgumentException????<br> * <br> * obj??clazz????????IllegalArgumentException?????? <br> * @throws Exception ????? */ @Test public void testConvertIfNotNull04() throws Exception { // ?? Thread thread = new Thread(); // try { ConvertUtil.convert(thread, AlgorithmParameterGenerator.class); fail(); } catch (IllegalArgumentException e) { e.printStackTrace(); } } /** * testConvertObjectClassboolean01() <br> * <br> * () <br> * G <br> * <br> * () obj:null<br> * () clazz:null<br> * () allowsNull:true<br> * <br> * () :IllegalArgumentException<br> * ?: "Argument 'clazz' (" + Object.class.getName() + ") is null"<br> * <br> * clazz?null?????IllegalArgumentException?????? <br> * @throws Exception ????? */ @Test public void testConvertObjectClassboolean01() throws Exception { // try { ConvertUtil.convert(null, null, true); fail("IllegalArgumentException???????"); } catch (IllegalArgumentException e) { // assertEquals(IllegalArgumentException.class.getName(), e.getClass().getName()); assertEquals("Argument 'clazz' (" + Object.class.getName() + ") is null", e.getMessage()); } } /** * testConvertObjectClassboolean02() <br> * <br> * () <br> * G <br> * <br> * () obj:null<br> * () clazz:Object.class<br> * () allowsNull:false<br> * <br> * () :IllegalArgumentException<br> * ?: "Unable to cast 'null' to '" + clazz??? + "'"<br> * ??:ClassCastException<br> * ???: "Unable to cast 'null' to '" + clazz??? + "'"<br> * <br> * clazz?null??????obj?null?allowsNull?false????? IllegalArgumentException?????? <br> * @throws Exception ????? */ @Test public void testConvertObjectClassboolean02() throws Exception { // try { ConvertUtil.convert(null, Object.class, false); fail("IllegalArgumentException???????"); } catch (IllegalArgumentException e) { // assertEquals(IllegalArgumentException.class.getName(), e.getClass().getName()); assertEquals("Unable to cast 'null' to '" + Object.class.getName() + "'", e.getMessage()); assertEquals(ClassCastException.class.getName(), e.getCause().getClass().getName()); assertEquals("Unable to cast 'null' to '" + Object.class.getName() + "'", e.getCause().getMessage()); } } /** * testConvertObjectClassboolean03() <br> * <br> * () <br> * C <br> * <br> * () obj:null<br> * () clazz:Object.class<br> * () allowsNull:true<br> * <br> * () <T>:null<br> * <br> * clazz?null??????obj?null?allowsNull?true?????null??????? <br> * @throws Exception ????? */ @Test public void testConvertObjectClassboolean03() throws Exception { // // assertNull(ConvertUtil.convert(null, Object.class, true)); } /** * testConvertObjectClassboolean04() <br> * <br> * () <br> * E <br> * <br> * () obj:Thread<br> * () clazz:Thread.class<br> * () allowsNull:true<br> * <br> * () <T>:Thread (obj???????)<br> * <br> * clazz??obj?????????clazz????????? <br> * @throws Exception ????? */ @Test public void testConvertObjectClassboolean04() throws Exception { // ?? Thread thread = new Thread(); // Thread result = ConvertUtil.convert(thread, Thread.class, true); // assertSame(thread, result); } /** * testConvertObjectClassboolean05() <br> * <br> * () <br> * E <br> * <br> * () obj:List (ArrayList??)<br> * () clazz:ArrayList.class<br> * () allowsNull:true<br> * <br> * () <T>:List (obj????????)<br> * <br> * obj????????? <br> * @throws Exception ????? */ @Test public void testConvertObjectClassboolean05() throws Exception { // ?? List<?> list = new ArrayList<Object>(); // List<?> result = ConvertUtil.convert(list, ArrayList.class, true); // assertNotNull(result); assertSame(list, result); } /** * testConvertObjectClassboolean06() <br> * <br> * () <br> * E <br> * <br> * () obj:Thread<br> * () clazz:AlgorithmParameterGenerator.class<br> * () allowsNull:true<br> * <br> * () <T>:IllegalArgumentException????<br> * <br> * clazz??obj??????????IllegalArgumentException?????? <br> * @throws Exception ????? */ @Test public void testConvertObjectClassboolean06() throws Exception { // ?? Thread thread = new Thread(); // try { ConvertUtil.convert(thread, AlgorithmParameterGenerator.class, true); fail(); } catch (IllegalArgumentException e) { } } /** * testConvertObjectClassboolean07() <br> * <br> * () <br> * G <br> * <br> * () obj:"abc"<br> * () clazz:BigInteger.class<br> * () allowsNull:false<br> * <br> * () :IllegalArgumentException<br> * ??:ConversionException<br> * <br> * CnvertUtils#convert??????IllegalArgumentException?????? <br> * @throws Exception ????? */ @Test public void testConvertObjectClassboolean07() throws Exception { // try { ConvertUtil.convert("abc", BigInteger.class, false); fail("IllegalArgumentException???????"); } catch (IllegalArgumentException e) { // assertEquals(IllegalArgumentException.class.getName(), e.getClass().getName()); assertTrue(e.getCause() instanceof ConversionException); } } /** * testConvertPrimitiveArrayToList01() <br> * <br> * () <br> * C <br> * <br> * () value:null<br> * <br> * () Object:null<br> * <br> * value?null?????null??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList01() throws Exception { // // assertNull(ConvertUtil.convertPrimitiveArrayToList(null)); } /** * testConvertPrimitiveArrayToList02() <br> * <br> * () <br> * C <br> * <br> * () value:""()<br> * <br> * () Object:""()<br> * <br> * value?""()?????""()??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList02() throws Exception { // Object result = ConvertUtil.convertPrimitiveArrayToList(""); // assertNotNull(result); assertEquals("", result); } /** * testConvertPrimitiveArrayToList03() <br> * <br> * () <br> * C <br> * <br> * () value:" "()<br> * <br> * () Object:" "()<br> * <br> * value?" "()?????""()??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList03() throws Exception { // Object result = ConvertUtil.convertPrimitiveArrayToList(" "); // assertNotNull(result); assertEquals(" ", result); } /** * testConvertPrimitiveArrayToList04() <br> * <br> * () <br> * E <br> * <br> * () value:"noArray"<br> * <br> * () Object:"noArray"<br> * <br> * value??????????????????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList04() throws Exception { // Object result = ConvertUtil.convertPrimitiveArrayToList("noarray"); // assertNotNull(result); assertEquals("noarray", result); } /** * testConvertPrimitiveArrayToList05() <br> * <br> * () <br> * D,E <br> * <br> * () value:??????Object[]<br> * <br> * () Object:??????Object[] (??0?????)<br> * <br> * value???(?0)?????????????????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList05() throws Exception { // ?? Object[] value = new Object[0]; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof Object[]); Object[] arrayResult = (Object[]) result; assertEquals(0, arrayResult.length); } /** * testConvertPrimitiveArrayToList06() <br> * <br> * () <br> * D,E <br> * <br> * () value:?????Object[]<br> * *?0:"foo"<br> * <br> * () Object:?????Object[] (??1?????)<br> * *?0:"foo"<br> * <br> * value???(?1)?????????????????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList06() throws Exception { // ?? Object[] value = { "foo" }; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof Object[]); Object[] arrayResult = (Object[]) result; assertEquals(1, arrayResult.length); assertEquals("foo", arrayResult[0]); } /** * testConvertPrimitiveArrayToList07() <br> * <br> * () <br> * D,E <br> * <br> * () value:?????Object[]<br> * *?0:"foo"<br> * *?1:"bar"<br> * *?2:"baz"<br> * <br> * () Object:?????Object[] (??3?????)<br> * *?0:"foo"<br> * *?1:"bar"<br> * *?3:"baz"<br> * <br> * value???(?3)?????????????????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList07() throws Exception { // ?? Object[] value = { "foo", "bar", "baz" }; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof Object[]); Object[] arrayResult = (Object[]) result; assertEquals(3, arrayResult.length); assertEquals("foo", arrayResult[0]); assertEquals("bar", arrayResult[1]); assertEquals("baz", arrayResult[2]); } /** * testConvertPrimitiveArrayToList08() <br> * <br> * () <br> * D,E <br> * <br> * () value:??????boolean[]<br> * <br> * () Object:??????List (size?0?????)<br> * <br> * value???????boolean?????????????List??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList08() throws Exception { // ?? boolean[] value = new boolean[0]; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof List); List<?> listResult = (List<?>) result; assertEquals(0, listResult.size()); } /** * testConvertPrimitiveArrayToList09() <br> * <br> * () <br> * D,E <br> * <br> * () value:?????boolean[]<br> * *?0:true<br> * <br> * () Object:?????List(size?1?????)<br> * *?0:true<br> * <br> * value?boolean??(?1)?????boolean????List??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList09() throws Exception { // ?? boolean[] value = { true }; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof List); List<?> listResult = (List<?>) result; assertEquals(1, listResult.size()); assertTrue((Boolean) listResult.get(0)); } /** * testConvertPrimitiveArrayToList10() <br> * <br> * () <br> * D,E <br> * <br> * () value:?????boolean[]<br> * *?0:true<br> * *?1:false<br> * *?2:true<br> * <br> * () Object:?????List(size?3?????)<br> * *?0:true<br> * *?1:false<br> * *?2:true<br> * <br> * value?boolean??(?3)?????boolean????List??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList10() throws Exception { // ?? boolean[] value = { true, false, true }; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof List); List<?> listResult = (List<?>) result; assertEquals(3, listResult.size()); assertTrue((Boolean) listResult.get(0)); assertFalse((Boolean) listResult.get(1)); assertTrue((Boolean) listResult.get(2)); } /** * testConvertPrimitiveArrayToList11() <br> * <br> * () <br> * D,E <br> * <br> * () value:??????byte[]<br> * <br> * () Object:??????List (size?0?????)<br> * <br> * value???????byte?????????????List??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList11() throws Exception { // ?? byte[] value = new byte[0]; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof List); List<?> listResult = (List<?>) result; assertEquals(0, listResult.size()); } /** * testConvertPrimitiveArrayToList12() <br> * <br> * () <br> * D,E <br> * <br> * () value:?????byte[]<br> * *?0: (byte) 1<br> * <br> * () Object:?????List(size?1?????)<br> * *?0:"1"<br> * <br> * value?byte??(?1)?????String???????List??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList12() throws Exception { // ?? byte[] value = { 1 }; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof List); List<?> listResult = (List<?>) result; assertEquals(1, listResult.size()); assertEquals("1", listResult.get(0)); } /** * testConvertPrimitiveArrayToList13() <br> * <br> * () <br> * D,E <br> * <br> * () value:?????byte[]<br> * *?0: (byte) 1<br> * *?1: (byte) 2<br> * *?2: (byte) 3<br> * <br> * () Object:?????List(size?3?????)<br> * *?0:"1"<br> * *?1:"2"<br> * *?2:"3"<br> * <br> * value?byte??(?3)?????String???????List??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList13() throws Exception { // ?? byte[] value = { 1, 2, 3 }; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof List); List<?> listResult = (List<?>) result; assertEquals(3, listResult.size()); assertEquals("1", listResult.get(0)); assertEquals("2", listResult.get(1)); assertEquals("3", listResult.get(2)); } /** * testConvertPrimitiveArrayToList14() <br> * <br> * () <br> * D,E <br> * <br> * () value:??????char[]<br> * <br> * () Object:??????List (size?0?????)<br> * <br> * value???????char?????????????List??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList14() throws Exception { // ?? char[] value = new char[0]; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof List); List<?> listResult = (List<?>) result; assertEquals(0, listResult.size()); } /** * testConvertPrimitiveArrayToList15() <br> * <br> * () <br> * D,E <br> * <br> * () value:?????char[]<br> * *?0: 'A'<br> * <br> * () Object:?????List(size?1?????)<br> * *?0: "A"<br> * <br> * value?char??(?1)?????String???????List??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList15() throws Exception { // ?? char[] value = { 'A' }; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof List); List<?> listResult = (List<?>) result; assertEquals(1, listResult.size()); assertEquals("A", listResult.get(0)); } /** * testConvertPrimitiveArrayToList16() <br> * <br> * () <br> * D,E <br> * <br> * () value:?????char[]<br> * *?0: 'A'<br> * *?1: 'B'<br> * *?2: 'C'<br> * <br> * () Object:?????List(size?3?????)<br> * *?0: "A"<br> * *?1: "B"<br> * *?2: "C"<br> * <br> * value?char??(?3)?????String???????List??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList16() throws Exception { // ?? char[] value = { 'A', 'B', 'C' }; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof List); List<?> listResult = (List<?>) result; assertEquals(3, listResult.size()); assertEquals("A", listResult.get(0)); assertEquals("B", listResult.get(1)); assertEquals("C", listResult.get(2)); } /** * testConvertPrimitiveArrayToList17() <br> * <br> * () <br> * D,E <br> * <br> * () value:??????double[]<br> * <br> * () Object:??????List (size?0?????)<br> * <br> * value???????double?????????????List??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList17() throws Exception { // ?? double[] value = new double[0]; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof List); List<?> listResult = (List<?>) result; assertEquals(0, listResult.size()); } /** * testConvertPrimitiveArrayToList18() <br> * <br> * () <br> * D,E <br> * <br> * () value:?????double[]<br> * *?0: 123.456<br> * <br> * () Object:?????List(size?1?????)<br> * *?0: "123.456"<br> * <br> * value?double??(?1)?????String???????List??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList18() throws Exception { // ?? double[] value = { 123.456 }; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof List); List<?> listResult = (List<?>) result; assertEquals(1, listResult.size()); assertEquals("123.456", listResult.get(0)); } /** * testConvertPrimitiveArrayToList19() <br> * <br> * () <br> * D,E <br> * <br> * () value:?????double[]<br> * *?0: 123.456<br> * *?1: 12.34<br> * *?2: 1.2<br> * <br> * () Object:?????List(size?3?????)<br> * *?0: "123.456"<br> * *?1: "12.34"<br> * *?2: "1.2"<br> * <br> * value?double??(?3)?????String???????List??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList19() throws Exception { // ?? double[] value = { 123.456, 12.34, 1.2 }; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof List); List<?> listResult = (List<?>) result; assertEquals(3, listResult.size()); assertEquals("123.456", listResult.get(0)); assertEquals("12.34", listResult.get(1)); assertEquals("1.2", listResult.get(2)); } /** * testConvertPrimitiveArrayToList20() <br> * <br> * () <br> * D,E <br> * <br> * () value:??????float[]<br> * <br> * () Object:??????List (size?0?????)<br> * <br> * value???????float?????????????List??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList20() throws Exception { // ?? float[] value = new float[0]; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof List); List<?> listResult = (List<?>) result; assertEquals(0, listResult.size()); } /** * testConvertPrimitiveArrayToList21() <br> * <br> * () <br> * D,E <br> * <br> * () value:?????float[]<br> * *?0: 12.3F<br> * <br> * () Object:?????List(size?1?????)<br> * *?0: "12.3"<br> * <br> * value?float??(?1)?????String???????List??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList21() throws Exception { // ?? float[] value = { 12.3F }; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof List); List<?> listResult = (List<?>) result; assertEquals(1, listResult.size()); assertEquals("12.3", listResult.get(0)); } /** * testConvertPrimitiveArrayToList22() <br> * <br> * () <br> * D,E <br> * <br> * () value:?????float[]<br> * *?0: 12.3F<br> * *?1: 1.2F<br> * *?2: 1F<br> * <br> * () Object:?????List(size?3?????)<br> * *?0: "12.3"<br> * *?1: "1.2"<br> * *?2: "1.0"<br> * <br> * value?float??(?3)?????String???????List??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList22() throws Exception { // ?? float[] value = { 12.3F, 1.2F, 1F }; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof List); List<?> listResult = (List<?>) result; assertEquals(3, listResult.size()); assertEquals("12.3", listResult.get(0)); assertEquals("1.2", listResult.get(1)); assertEquals("1.0", listResult.get(2)); } /** * testConvertPrimitiveArrayToList23() <br> * <br> * () <br> * D,E <br> * <br> * () value:??????int[]<br> * <br> * () Object:??????List (size?0?????)<br> * <br> * value???????int?????????????List??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList23() throws Exception { // ?? int[] value = new int[0]; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof List); List<?> listResult = (List<?>) result; assertEquals(0, listResult.size()); } /** * testConvertPrimitiveArrayToList24() <br> * <br> * () <br> * D,E <br> * <br> * () value:?????int[]<br> * *?0: 1<br> * <br> * () Object:?????List(size?1?????)<br> * *?0: "1"<br> * <br> * value?int??(?1)?????String???????List??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList24() throws Exception { // ?? int[] value = { 1 }; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof List); List<?> listResult = (List<?>) result; assertEquals(1, listResult.size()); assertEquals("1", listResult.get(0)); } /** * testConvertPrimitiveArrayToList25() <br> * <br> * () <br> * D,E <br> * <br> * () value:?????int[]<br> * *?0: 1<br> * *?1: 2<br> * *?2: 3<br> * <br> * () Object:?????List(size?3?????)<br> * *?0: "1"<br> * *?1: "2"<br> * *?2: "3"<br> * <br> * value?int??(?3)?????String???????List??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList25() throws Exception { // ?? int[] value = { 1, 2, 3 }; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof List); List<?> listResult = (List<?>) result; assertEquals(3, listResult.size()); assertEquals("1", listResult.get(0)); assertEquals("2", listResult.get(1)); assertEquals("3", listResult.get(2)); } /** * testConvertPrimitiveArrayToList26() <br> * <br> * () or () <br> * D,E <br> * <br> * () value:??????long[]<br> * <br> * () Object:??????List (size?0?????)<br> * <br> * value???????long?????????????List??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList26() throws Exception { // ?? long[] value = new long[0]; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof List); List<?> listResult = (List<?>) result; assertEquals(0, listResult.size()); } /** * testConvertPrimitiveArrayToList27() <br> * <br> * () <br> * D,E <br> * <br> * () value:?????lobg[]<br> * *?0: 1L<br> * <br> * () Object:?????List(size?1?????)<br> * *?0: "1"<br> * <br> * value?long??(?1)?????String???????List??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList27() throws Exception { // ?? long[] value = { 1L }; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof List); List<?> listResult = (List<?>) result; assertEquals(1, listResult.size()); assertEquals("1", listResult.get(0)); } /** * testConvertPrimitiveArrayToList28() <br> * <br> * () <br> * D,E <br> * <br> * () value:?????long[]<br> * *?0: 1L<br> * *?1: 2L<br> * *?2: 3L<br> * <br> * () Object:?????List(size?3?????)<br> * *?0: "1"<br> * *?1: "2"<br> * *?2: "3"<br> * <br> * value?long??(?3)?????String???????List??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList28() throws Exception { // ?? long[] value = { 1L, 2L, 3L }; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof List); List<?> listResult = (List<?>) result; assertEquals(3, listResult.size()); assertEquals("1", listResult.get(0)); assertEquals("2", listResult.get(1)); assertEquals("3", listResult.get(2)); } /** * testConvertPrimitiveArrayToList29() <br> * <br> * () <br> * D,E <br> * <br> * () value:??????short[]<br> * <br> * () Object:??????List (size?0?????)<br> * <br> * value???????short?????????????List??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList29() throws Exception { // ?? short[] value = new short[0]; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof List); List<?> listResult = (List<?>) result; assertEquals(0, listResult.size()); } /** * testConvertPrimitiveArrayToList30() <br> * <br> * () <br> * D,E <br> * <br> * () value:?????short[]<br> * *?0: (short) 1<br> * <br> * () Object:?????List(size?1?????)<br> * *?0: "1"<br> * <br> * value?short??(?1)?????String???????List??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList30() throws Exception { // ?? short[] value = { (short) 1 }; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof List); List<?> listResult = (List<?>) result; assertEquals(1, listResult.size()); } /** * testConvertPrimitiveArrayToList31() <br> * <br> * () <br> * D,E <br> * <br> * () value:?????short[]<br> * *?0: (short) 1<br> * *?1: (short) 2<br> * *?2: (short) 3<br> * <br> * () Object:?????List(size?3?????)<br> * *?0: "1"<br> * *?1: "2"<br> * *?2: "3"<br> * <br> * value?short??(?3)?????String???????List??????? <br> * @throws Exception ????? */ @Test public void testConvertPrimitiveArrayToList31() throws Exception { // ?? short[] value = { (short) 1, (short) 2, (short) 3 }; // Object result = ConvertUtil.convertPrimitiveArrayToList(value); // assertNotNull(result); assertTrue(result instanceof List); List<?> listResult = (List<?>) result; assertEquals(3, listResult.size()); assertEquals("1", listResult.get(0)); assertEquals("2", listResult.get(1)); assertEquals("3", listResult.get(2)); } /** * testToListOfMap01() <br> * <br> * () <br> * D, E <br> * <br> * () obj:null<br> * <br> * () List<Map<String, Object>:?????Object[]<br> * <br> * obj?null????????List<Map<String,Object>????? <br> * @throws Exception ????? */ @Test public void testToListOfMap01() throws Exception { // ?? // List<Map<String, Object>> actual = ConvertUtil.toListOfMap(null); // assertNotNull(actual); assertTrue(actual.isEmpty()); } /** * testToListOfMap02() <br> * <br> * () <br> * D, E <br> * <br> * () obj:3???JavaBean?<br> * ?0=JavaBean<br> * A="value00"<br> * ?1=JavaBean<br> * A="value01"<br> * ?2=JavaBean<br> * A="value02"<br> * <br> * () List<Map<String, Object>: 3???List<Map<String, Object>><br> * <br> * ?0-=Map<String,Object><br> * key="a",value="value00"<br> * ?1=Map<String,Object><br> * key="a",value="value01"<br> * ?2=Map<String,Object><br> * key="a",value="value02"<br> * <br> * obj??JavaBean?????? 3?????List<Map<String,Object>????? <br> * @throws Exception ????? */ @Test public void testToListOfMap02() throws Exception { List<ConvertUtil_Stub01> obj = new ArrayList<ConvertUtil_Stub01>(); ConvertUtil_Stub01 bean = new ConvertUtil_Stub01(); bean.setA("value00"); obj.add(bean); ConvertUtil_Stub01 bean02 = new ConvertUtil_Stub01(); bean02.setA("value01"); obj.add(bean02); ConvertUtil_Stub01 bean03 = new ConvertUtil_Stub01(); bean03.setA("value02"); obj.add(bean03); // List<Map<String, Object>> actual = ConvertUtil.toListOfMap(obj); // assertNotNull(actual); assertEquals(3, actual.size()); assertEquals("value00", actual.get(0).get("a")); assertEquals("value01", actual.get(1).get("a")); assertEquals("value02", actual.get(2).get("a")); } /** * testToListOfMap03() <br> * <br> * () <br> * D, E <br> * <br> * () obj:3???JavaBean?<br> * ?0=JavaBean<br> * A="value00"<br> * ?1=JavaBean<br> * A="value01"<br> * ?2=JavaBean<br> * A="value02"<br> * <br> * () List<Map<String, Object>: 3???List<Map<String, Object>><br> * <br> * ?0-=Map<String,Object><br> * key="a",value="value00"<br> * ?1=Map<String,Object><br> * key="a",value="value01"<br> * ?2=Map<String,Object><br> * key="a",value="value02"<br> * <br> * obj??JavaBean??????? 3?????List<Map<String,Object>????? <br> * @throws Exception ????? */ @Test public void testToListOfMap03() throws Exception { ConvertUtil_Stub01 bean = new ConvertUtil_Stub01(); bean.setA("value00"); ConvertUtil_Stub01 bean02 = new ConvertUtil_Stub01(); bean02.setA("value01"); ConvertUtil_Stub01 bean03 = new ConvertUtil_Stub01(); bean03.setA("value02"); ConvertUtil_Stub01[] obj = new ConvertUtil_Stub01[] { bean, bean02, bean03 }; // List<Map<String, Object>> actual = ConvertUtil.toListOfMap(obj); // assertNotNull(actual); assertEquals(3, actual.size()); assertEquals("value00", actual.get(0).get("a")); assertEquals("value01", actual.get(1).get("a")); assertEquals("value02", actual.get(2).get("a")); } /** * testToListOfMap04() <br> * <br> * () <br> * D, E <br> * <br> * () obj:3???List<Map<String, Object>><br> * <br> * ?0=Map<String,Object><br> * key="a",value="value00"<br> * ?1=Map<String,Object><br> * key="a",value="value01"<br> * ?2=Map<String,Object><br> * key="a",value="value02"<br> * <br> * () List<Map<String, Object>: 3???List<Map<String, Object>><br> * <br> * ?0-=Map<String,Object><br> * key="a",value="value00"<br> * ?1=Map<String,Object><br> * key="a",value="value01"<br> * ?2=Map<String,Object><br> * key="a",value="value02"<br> * <br> * obj??Map?????? 3?????List<Map<String,Object>????? <br> * @throws Exception ????? */ @Test public void testToListOfMap04() throws Exception { List<Map<String, Object>> obj = new ArrayList<Map<String, Object>>(); Map<String, Object> row = new HashMap<String, Object>(); row.put("a", "value00"); obj.add(row); Map<String, Object> row02 = new HashMap<String, Object>(); row02.put("a", "value01"); obj.add(row02); Map<String, Object> row03 = new HashMap<String, Object>(); row03.put("a", "value02"); obj.add(row03); // List<Map<String, Object>> actual = ConvertUtil.toListOfMap(obj); // assertNotNull(actual); assertEquals(3, actual.size()); assertEquals("value00", actual.get(0).get("a")); assertEquals("value01", actual.get(1).get("a")); assertEquals("value02", actual.get(2).get("a")); } /** * testToListOfMap05() <br> * <br> * () <br> * D, E <br> * <br> * () obj:3???Map<String, Object>??<br> * <br> * ?0=Map<String,Object><br> * key="a",value="value00"<br> * ?1=Map<String,Object><br> * key="a",value="value01"<br> * ?2=Map<String,Object><br> * key="a",value="value02"<br> * <br> * () List<Map<String, Object>: 3???List<Map<String, Object>><br> * <br> * ?0-=Map<String,Object><br> * key="a",value="value00"<br> * ?1=Map<String,Object><br> * key="a",value="value01"<br> * ?2=Map<String,Object><br> * key="a",value="value02"<br> * <br> * obj??Map??????? 3?????List<Map<String,Object>????? <br> * @throws Exception ????? */ @Test public void testToListOfMap05() throws Exception { Map<String, Object> row = new HashMap<String, Object>(); row.put("a", "value00"); Map<String, Object> row02 = new HashMap<String, Object>(); row02.put("a", "value01"); Map<String, Object> row03 = new HashMap<String, Object>(); row03.put("a", "value02"); @SuppressWarnings("rawtypes") Map[] obj = new Map[] { row, row02, row03 }; // List<Map<String, Object>> actual = ConvertUtil.toListOfMap(obj); // assertNotNull(actual); assertEquals(3, actual.size()); assertEquals("value00", actual.get(0).get("a")); assertEquals("value01", actual.get(1).get("a")); assertEquals("value02", actual.get(2).get("a")); } /** * testToListOfMap06() <br> * <br> * () <br> * G <br> * <br> * () obj:JavaBean<br> * A="value00"<br> * <br> * () List<Map<String, Object>: 1???List<Map<String, Object>><br> * <br> * ?0-=Map<String,Object><br> * key=A,value="value00"<br> * <br> * obj?JavaBean???1????? List<Map<String,Object>????? <br> * @throws Exception ????? */ @Test public void testToListOfMap06() throws Exception { ConvertUtil_Stub01 obj = new ConvertUtil_Stub01(); obj.setA("value00"); // List<Map<String, Object>> actual = ConvertUtil.toListOfMap(obj); // assertNotNull(actual); assertEquals(1, actual.size()); assertEquals("value00", actual.get(0).get("a")); } /** * testToListOfMap08() <br> * <br> * () <br> * G <br> * <br> * () obj:JavaBean<br> * A="value00"<br> * () PropertyUtils#describe??: InvocationTargetException JavaBean?getter?RuntimeException<br> * <br> * () :IllegalArgumentException<br> * ??InvocationTargetException<br> * <br> * PropertyUtils#descrive?InvocationTargetException????? <br> * @throws Exception ????? */ @Test public void testToListOfMap08() throws Exception { // ?? ConvertUtil_Stub02 obj = new ConvertUtil_Stub02(); obj.setA("value00"); try { // ConvertUtil.toListOfMap(obj); fail(); } catch (IllegalArgumentException e) { // assertEquals(IllegalArgumentException.class.getName(), e.getClass().getName()); assertTrue(e.getCause() instanceof InvocationTargetException); } } /** * testToListOfMap09() <br> * <br> * () <br> * G <br> * <br> * () obj:JavaBean<br> * A="value00"<br> * () PropertyUtils#describe??: IllegalAccessException PropertyUtilsBean??IllegalAccessException<br> * <br> * () :IllegalArgumentException<br> * ??IllegalAccessException<br> * <br> * PropertyUtils#descrive?IllegalAccessException????? <br> * @throws Exception ????? */ @Test public void testToListOfMap09() throws Exception { // ?? List<ConvertUtil_Stub01> obj = new ArrayList<ConvertUtil_Stub01>(); ConvertUtil_Stub01 bean = new ConvertUtil_Stub01(); bean.setA("value00"); obj.add(bean); BeanUtilsBean beanUtilsBean = BeanUtilsBean.getInstance(); ReflectionTestUtils.setField(beanUtilsBean, "propertyUtilsBean", new ConvertUtil_PropertyUtilsBeanStub01()); try { // ConvertUtil.toListOfMap(obj); fail(); } catch (IllegalArgumentException e) { // assertEquals(IllegalArgumentException.class.getName(), e.getClass().getName()); assertTrue(e.getCause() instanceof IllegalAccessException); } } /** * testToListOfMap10() <br> * <br> * () <br> * G <br> * <br> * () obj:JavaBean<br> * A="value00"<br> * () PropertyUtils#describe??: NoSuchMethodException PropertyUtilsBean??NoSuchMethodException<br> * <br> * () :IllegalArgumentException<br> * ??NoSuchMethodException<br> * <br> * PropertyUtils#descrive?NoSuchMethodException????? <br> * @throws Exception ????? */ @Test public void testToListOfMap10() throws Exception { // ?? List<ConvertUtil_Stub01> obj = new ArrayList<ConvertUtil_Stub01>(); ConvertUtil_Stub01 bean = new ConvertUtil_Stub01(); bean.setA("value00"); obj.add(bean); BeanUtilsBean beanUtilsBean = BeanUtilsBean.getInstance(); ReflectionTestUtils.setField(beanUtilsBean, "propertyUtilsBean", new ConvertUtil_PropertyUtilsBeanStub02()); try { // ConvertUtil.toListOfMap(obj); fail(); } catch (IllegalArgumentException e) { // assertEquals(IllegalArgumentException.class.getName(), e.getClass().getName()); assertTrue(e.getCause() instanceof NoSuchMethodException); } } }