DateColumnParser implements ColumnParser { @Override public void parse(String column, Object t, Method method, String columnFormat) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, ParseException { String pattern = columnFormat; if (pattern == null || "".equals(pattern)) { pattern = "yyyyMMdd"; } DateFormatLocal dflocal = null; dflocal = map.get(pattern); if (dflocal == null) { dflocal = new DateFormatLocal(pattern); map.put(pattern, dflocal); } DateFormat df = dflocal.get(); method.invoke(t, df.parse(column)); }  @Override void parse(String column, Object t, Method method,
            String columnFormat);  }
@Test public void testParse01() throws Exception { DateColumnParser dateColumnParser = new DateColumnParser(); String column = "20060101"; DateColumnParser_Stub01 t = new DateColumnParser_Stub01(); Method method = DateColumnParser_Stub01.class.getDeclaredMethod("setA", new Class[] { Date.class }); String columnFormat = ""; Map<String, DateFormatLocal> map = Mockito.spy( new ConcurrentHashMap<String, DateFormatLocal>()); ReflectionTestUtils.setField(dateColumnParser, "map", map); dateColumnParser.parse(column, t, method, columnFormat); Object result = ReflectionTestUtils.getField(t, "a"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd"); simpleDateFormat.setLenient(false); Date expected = simpleDateFormat.parse(column); assertEquals(expected, result); Mockito.verify(map).get(Mockito.anyString()); Mockito.verify(map).put(Mockito.anyString(), Mockito.any( DateFormatLocal.class)); assertEquals(1, map.size()); assertNotNull(map.get("yyyyMMdd")); }
@Test public void testParse02() throws Exception { DateColumnParser dateColumnParser = new DateColumnParser(); String column = "20060101"; DateColumnParser_Stub01 t = new DateColumnParser_Stub01(); Method method = DateColumnParser_Stub01.class.getDeclaredMethod("setA", new Class[] { Date.class }); String columnFormat = ""; Map<String, DateFormatLocal> map = new ConcurrentHashMap<String, DateFormatLocal>(); DateFormatLocal cache = new DateFormatLocal("yyyyMMdd"); map.put("yyyyMMdd", cache); map = Mockito.spy(map); ReflectionTestUtils.setField(dateColumnParser, "map", map); dateColumnParser.parse(column, t, method, columnFormat); Object result = ReflectionTestUtils.getField(t, "a"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd"); simpleDateFormat.setLenient(false); Date expected = simpleDateFormat.parse(column); assertEquals(expected, result); Mockito.verify(map).get(Mockito.anyString()); Mockito.verify(map, Mockito.never()).put(Mockito.anyString(), Mockito .any(DateFormatLocal.class)); assertEquals(1, map.size()); assertSame(cache, map.get("yyyyMMdd")); }
@Test public void testParse03() throws Exception { DateColumnParser dateColumnParser = new DateColumnParser(); String column = "20060101"; DateColumnParser_Stub01 t = new DateColumnParser_Stub01(); Method method = DateColumnParser_Stub01.class.getDeclaredMethod("setA", new Class[] { Date.class }); String columnFormat = ""; Map<String, DateFormatLocal> map = new ConcurrentHashMap<String, DateFormatLocal>(); DateFormatLocal cache = new DateFormatLocal("yyyy-MM-dd"); map.put("yyyy-MM-dd", cache); map = Mockito.spy(map); ReflectionTestUtils.setField(dateColumnParser, "map", map); dateColumnParser.parse(column, t, method, columnFormat); Object result = ReflectionTestUtils.getField(t, "a"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd"); simpleDateFormat.setLenient(false); Date expected = simpleDateFormat.parse(column); assertEquals(expected, result); Mockito.verify(map).get(Mockito.anyString()); Mockito.verify(map).put(Mockito.anyString(), Mockito.any( DateFormatLocal.class)); assertEquals(2, map.size()); assertNotNull(map.get("yyyyMMdd")); assertSame(cache, map.get("yyyy-MM-dd")); }
@Test public void testParse04() throws Exception { DateColumnParser dateColumnParser = new DateColumnParser(); String column = "2006-01-01"; DateColumnParser_Stub01 t = new DateColumnParser_Stub01(); Method method = DateColumnParser_Stub01.class.getDeclaredMethod("setA", new Class[] { Date.class }); String columnFormat = "yyyy-MM-dd"; Map<String, DateFormatLocal> map = new ConcurrentHashMap<String, DateFormatLocal>(); map = Mockito.spy(map); ReflectionTestUtils.setField(dateColumnParser, "map", map); dateColumnParser.parse(column, t, method, columnFormat); Object result = ReflectionTestUtils.getField(t, "a"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); simpleDateFormat.setLenient(false); Date expected = simpleDateFormat.parse(column); assertEquals(expected, result); Mockito.verify(map).get(Mockito.anyString()); Mockito.verify(map).put(Mockito.anyString(), Mockito.any( DateFormatLocal.class)); assertEquals(1, map.size()); assertNotNull(map.get("yyyy-MM-dd")); }
@Test public void testParse05() throws Exception { DateColumnParser dateColumnParser = new DateColumnParser(); String column = "2006-01-01"; DateColumnParser_Stub01 t = new DateColumnParser_Stub01(); Method method = DateColumnParser_Stub01.class.getDeclaredMethod("setA", new Class[] { Date.class }); String columnFormat = "yyyy-MM-dd"; Map<String, DateFormatLocal> map = new ConcurrentHashMap<String, DateFormatLocal>(); DateFormatLocal cache = new DateFormatLocal(columnFormat); map.put(columnFormat, cache); map = Mockito.spy(map); ReflectionTestUtils.setField(dateColumnParser, "map", map); dateColumnParser.parse(column, t, method, columnFormat); Object result = ReflectionTestUtils.getField(t, "a"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); simpleDateFormat.setLenient(false); Date expected = simpleDateFormat.parse(column); assertEquals(expected, result); Mockito.verify(map).get(Mockito.anyString()); Mockito.verify(map, Mockito.never()).put(Mockito.anyString(), Mockito .any(DateFormatLocal.class)); assertEquals(1, map.size()); assertSame(cache, map.get("yyyy-MM-dd")); }
@Test public void testParse06() throws Exception { DateColumnParser dateColumnParser = new DateColumnParser(); String column = "2006-01-01"; DateColumnParser_Stub01 t = new DateColumnParser_Stub01(); Method method = DateColumnParser_Stub01.class.getDeclaredMethod("setA", new Class[] { Date.class }); String columnFormat = "yyyy-MM-dd"; Map<String, DateFormatLocal> map = new ConcurrentHashMap<String, DateFormatLocal>(); DateFormatLocal cache = new DateFormatLocal("yyyy/MM/dd"); map.put("yyyy/MM/dd", cache); map = Mockito.spy(map); ReflectionTestUtils.setField(dateColumnParser, "map", map); dateColumnParser.parse(column, t, method, columnFormat); Object result = ReflectionTestUtils.getField(t, "a"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); simpleDateFormat.setLenient(false); Date expected = simpleDateFormat.parse(column); assertEquals(expected, result); Mockito.verify(map).get(Mockito.anyString()); Mockito.verify(map).put(Mockito.anyString(), Mockito.any( DateFormatLocal.class)); assertEquals(2, map.size()); assertSame(cache, map.get("yyyy/MM/dd")); assertNotNull(map.get("yyyy-MM-dd")); }
@Test public void testParse07() throws Exception { DateColumnParser dateColumnParser = new DateColumnParser(); String column = "2006-01-01"; DateColumnParser_Stub01 t = new DateColumnParser_Stub01(); Method method = DateColumnParser_Stub01.class.getDeclaredMethod("setA", new Class[] { Date.class }); String columnFormat = "yyyy-MM-dd-MM"; try { dateColumnParser.parse(column, t, method, columnFormat); fail("ParseExceptionがスローされました。"); } catch (ParseException e) { assertEquals(ParseException.class, e.getClass()); assertEquals("Unparseable date: \"2006-01-01\"", e.getMessage()); } }
@Test public void testParse08() throws Exception { DateColumnParser dateColumnParser = new DateColumnParser(); String column = "2006-01-01"; DateColumnParser_Stub01 t = new DateColumnParser_Stub01(); Method method = DateColumnParser_Stub01.class.getDeclaredMethod( "setAPrivate", new Class[] { Date.class }); String columnFormat = "yyyy-MM-dd"; try { dateColumnParser.parse(column, t, method, columnFormat); fail("IllegalAccessExceptionがスローされませんでした。"); } catch (IllegalAccessException e) { assertEquals(IllegalAccessException.class, e.getClass()); } }
@Test public void testParse09() throws Exception { DateColumnParser dateColumnParser = new DateColumnParser(); String column = "2006-01-01"; DateColumnParser_Stub01 t = new DateColumnParser_Stub01(); Method method = DateColumnParser_Stub01.class.getDeclaredMethod( "setAException", new Class[] { Date.class }); String columnFormat = "yyyy-MM-dd"; try { dateColumnParser.parse(column, t, method, columnFormat); fail("InvocationTargetExceptionがスローされました。"); } catch (InvocationTargetException e) { assertEquals(InvocationTargetException.class, e.getClass()); } }
@Test public void testParse10() throws Exception { DateColumnParser dateColumnParser = new DateColumnParser(); String column = "2006-01-01"; DateColumnParser_Stub01 t = new DateColumnParser_Stub01(); Method method = DateColumnParser_Stub01.class.getDeclaredMethod( "setAAndB", new Class[] { Date.class, Date.class }); String columnFormat = "yyyy-MM-dd"; try { dateColumnParser.parse(column, t, method, columnFormat); fail("IllegalArgumentExceptionがスローされませんでした。"); } catch (IllegalArgumentException e) { assertEquals(IllegalArgumentException.class, e.getClass()); } }
@Test public void testParse11() throws Exception { DateColumnParser dateColumnParser = new DateColumnParser(); String column = "2008-01-32"; DateColumnParser_Stub01 t = new DateColumnParser_Stub01(); Method method = DateColumnParser_Stub01.class.getDeclaredMethod("setA", new Class[] { Date.class }); String columnFormat = "yyyy-MM-dd"; try { dateColumnParser.parse(column, t, method, columnFormat); fail("ParseExceptionがスローされませんでした。"); } catch (ParseException e) { assertEquals(ParseException.class, e.getClass()); assertEquals("Unparseable date: \"2008-01-32\"", e.getMessage()); } }
@Test public void testParse12() throws Exception { DateColumnParser dateColumnParser = new DateColumnParser(); String column = null; DateColumnParser_Stub01 t = new DateColumnParser_Stub01(); Method method = DateColumnParser_Stub01.class.getDeclaredMethod("setA", new Class[] { Date.class }); String columnFormat = "yyyy-MM-dd"; try { dateColumnParser.parse(column, t, method, columnFormat); fail("NullPointerExceptionがスローされませんでした。"); } catch (NullPointerException e) { assertEquals(NullPointerException.class, e.getClass()); } }
@Test public void testParse13() throws Exception { DateColumnParser dateColumnParser = new DateColumnParser(); String column = "20080101"; DateColumnParser_Stub01 t = new DateColumnParser_Stub01(); Method method = DateColumnParser_Stub01.class.getDeclaredMethod("setA", new Class[] { Date.class }); String columnFormat = "yyyy-MM-dd"; try { dateColumnParser.parse(column, t, method, columnFormat); fail("ParseExceptionがスローされませんでした。"); } catch (ParseException e) { assertEquals(ParseException.class, e.getClass()); assertEquals("Unparseable date: \"20080101\"", e.getMessage()); } }