DecimalColumnParser implements ColumnParser { @Override public void parse(String column, Object t, Method method, String columnFormat) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, ParseException { if (columnFormat != null && !"".equals(columnFormat)) { DecimalFormatLocal dfLocal = dfMap.get(columnFormat); if (dfLocal == null) { dfLocal = new DecimalFormatLocal(columnFormat); dfMap.put(columnFormat, dfLocal); } DecimalFormat decimalFormat = dfLocal.get(); decimalFormat.setParseBigDecimal(true); method.invoke(t, decimalFormat.parse(column)); } else { method.invoke(t, new BigDecimal(column)); } }  @Override void parse(String column, Object t, Method method,
            String columnFormat);  }
@Test public void testParse01() throws Exception { DecimalColumnParser decimalColumnParser = new DecimalColumnParser(); String column = "123456"; DecimalColumnParser_FileLineObjectStub01 stub = new DecimalColumnParser_FileLineObjectStub01(); stub.setDecimal01(null); Method method = DecimalColumnParser_FileLineObjectStub01.class .getDeclaredMethod("setDecimal01", new Class[] { BigDecimal.class }); String columnFormat = null; decimalColumnParser.parse(column, stub, method, columnFormat); BigDecimal result = stub.getDecimal01(); assertNotNull(result); assertEquals(BigDecimal.valueOf(123456), result); }
@Test public void testParse02() throws Exception { DecimalColumnParser decimalColumnParser = new DecimalColumnParser(); String column = "-\\123,456.00"; DecimalColumnParser_FileLineObjectStub01 stub = new DecimalColumnParser_FileLineObjectStub01(); stub.setDecimal02(null); Method method = DecimalColumnParser_FileLineObjectStub01.class .getDeclaredMethod("setDecimal02", new Class[] { BigDecimal.class }); String columnFormat = "-\\###,###,###.##"; decimalColumnParser.parse(column, stub, method, columnFormat); BigDecimal result = stub.getDecimal02(); assertNotNull(result); assertEquals(BigDecimal.valueOf(12345600, 2), result); }
@Test public void testParse03() throws Exception { DecimalColumnParser decimalColumnParser = new DecimalColumnParser(); String column = "-\\123,456.00"; DecimalColumnParser_FileLineObjectStub01 stub = new DecimalColumnParser_FileLineObjectStub01(); stub.setDecimal03(null); Method method = DecimalColumnParser_FileLineObjectStub01.class .getDeclaredMethod("setDecimal03", new Class[] { BigDecimal.class }); String columnFormat = "###,###,###.##"; try { decimalColumnParser.parse(column, stub, method, columnFormat); fail("ParseExceptionが発生しませんでした。"); } catch (ParseException e) { assertTrue(e instanceof ParseException); } }
@Test public void testParse04() throws Exception { DecimalColumnParser decimalColumnParser = new DecimalColumnParser(); String column = "-\\123,456.00"; DecimalColumnParser_FileLineObjectStub01 stub = new DecimalColumnParser_FileLineObjectStub01(); ReflectionTestUtils.setField(stub, "decimal04", null); Method method = DecimalColumnParser_FileLineObjectStub01.class .getDeclaredMethod("setDecimal04", new Class[] { BigDecimal.class }); String columnFormat = "\\###,###,###.##"; try { decimalColumnParser.parse(column, stub, method, columnFormat); fail("IllegalAccessExceptionが発生しませんでした。"); } catch (IllegalAccessException e) { assertTrue(e instanceof IllegalAccessException); } }
@Test public void testParse05() throws Exception { DecimalColumnParser decimalColumnParser = new DecimalColumnParser(); String column = "-\\123,456.00"; DecimalColumnParser_FileLineObjectStub01 stub = new DecimalColumnParser_FileLineObjectStub01(); ReflectionTestUtils.setField(stub, "decimal05", null); Method method = DecimalColumnParser_FileLineObjectStub01.class .getDeclaredMethod("setDecimal05", new Class[] { BigDecimal.class }); String columnFormat = "-\\###,###,###.##"; try { decimalColumnParser.parse(column, stub, method, columnFormat); fail("InvocationTargetExceptionが発生しませんでした。"); } catch (InvocationTargetException e) { assertTrue(e instanceof InvocationTargetException); } }
@Test public void testParse06() throws Exception { DecimalColumnParser decimalColumnParser = new DecimalColumnParser(); String column = "-\\123,456.00"; DecimalColumnParser_FileLineObjectStub01 stub = new DecimalColumnParser_FileLineObjectStub01(); ReflectionTestUtils.setField(stub, "decimal06", null); Method method = DecimalColumnParser_FileLineObjectStub01.class .getDeclaredMethod("setDecimal06", new Class[] { BigDecimal.class, BigDecimal.class }); String columnFormat = "-\\###,###,###.##"; try { decimalColumnParser.parse(column, stub, method, columnFormat); fail("IllegalArgumentExceptionが発生しませんでした。"); } catch (IllegalArgumentException e) { assertTrue(e instanceof IllegalArgumentException); } }
@Test public void testParse07() throws Exception { DecimalColumnParser decimalColumnParser = new DecimalColumnParser(); String column = null; DecimalColumnParser_FileLineObjectStub01 stub = new DecimalColumnParser_FileLineObjectStub01(); ReflectionTestUtils.setField(stub, "decimal07", null); Method method = DecimalColumnParser_FileLineObjectStub01.class .getDeclaredMethod("setDecimal07", new Class[] { BigDecimal.class }); String columnFormat = "-\\###,###,###.##"; try { decimalColumnParser.parse(column, stub, method, columnFormat); fail("NullPointerExceptionが発生しませんでした。"); } catch (NullPointerException e) { assertTrue(e instanceof NullPointerException); } }
@Test public void testParse08() throws Exception { DecimalColumnParser decimalColumnParser = new DecimalColumnParser(); String column = "abcあいうアイウ愛有"; DecimalColumnParser_FileLineObjectStub01 stub = new DecimalColumnParser_FileLineObjectStub01(); ReflectionTestUtils.setField(stub, "decimal08", null); Method method = DecimalColumnParser_FileLineObjectStub01.class .getDeclaredMethod("setDecimal08", new Class[] { BigDecimal.class }); String columnFormat = "-\\###,###,###.##"; try { decimalColumnParser.parse(column, stub, method, columnFormat); fail("ParseExceptionが発生しませんでした。"); } catch (ParseException e) { assertTrue(e instanceof ParseException); String errorMessage = "Unparseable number: \"abcあいうアイウ愛有\""; assertEquals(errorMessage, e.getMessage()); } }
@Test public void testParse09() throws Exception { DecimalColumnParser decimalColumnParser = new DecimalColumnParser(); String column = "123456"; DecimalColumnParser_FileLineObjectStub01 stub = new DecimalColumnParser_FileLineObjectStub01(); stub.setDecimal09(null); Method method = DecimalColumnParser_FileLineObjectStub01.class .getDeclaredMethod("setDecimal09", new Class[] { BigDecimal.class }); String columnFormat = ""; decimalColumnParser.parse(column, stub, method, columnFormat); BigDecimal result = stub.getDecimal09(); assertNotNull(result); assertEquals(BigDecimal.valueOf(123456), result); }
@Test public void testParse10() throws Exception { DecimalColumnParser decimalColumnParser = new DecimalColumnParser(); String column = "-\\123,456.00"; DecimalColumnParser_FileLineObjectStub01 stub = new DecimalColumnParser_FileLineObjectStub01(); stub.setDecimal10(null); Method method = DecimalColumnParser_FileLineObjectStub01.class .getDeclaredMethod("setDecimal10", new Class[] { BigDecimal.class }); String columnFormat = "-\\###,###,###.##"; ConcurrentHashMap<String, DecimalFormatLocal> dfMap = new ConcurrentHashMap<String, DecimalFormatLocal>(); ReflectionTestUtils.setField(decimalColumnParser, "dfMap", dfMap); dfMap.clear(); DecimalFormatLocal dfl = Mockito.spy( new DecimalFormatLocal(columnFormat)); PowerMockito.whenNew(DecimalFormatLocal.class).withArguments( columnFormat).thenReturn(dfl); decimalColumnParser.parse(column, stub, method, columnFormat); BigDecimal result = stub.getDecimal10(); assertNotNull(result); assertEquals(BigDecimal.valueOf(12345600, 2), result); assertSame(dfMap, ReflectionTestUtils.getField(decimalColumnParser, "dfMap")); assertEquals(1, dfMap.size()); assertTrue(dfMap.containsKey(columnFormat)); DecimalFormatLocal dfMapValue = dfMap.get(columnFormat); assertNotNull(dfMapValue); assertEquals(columnFormat, ReflectionTestUtils.getField(dfMapValue, "pattern")); PowerMockito.verifyNew(DecimalFormatLocal.class).withArguments( columnFormat); }
@Test public void testParse11() throws Exception { DecimalColumnParser decimalColumnParser = new DecimalColumnParser(); String column = "-\\123,456.00"; DecimalColumnParser_FileLineObjectStub01 stub = new DecimalColumnParser_FileLineObjectStub01(); stub.setDecimal11(null); Method method = DecimalColumnParser_FileLineObjectStub01.class .getDeclaredMethod("setDecimal11", new Class[] { BigDecimal.class }); String columnFormat = "-\\###,###,###.##"; ConcurrentHashMap<String, DecimalFormatLocal> dfMap = new ConcurrentHashMap<String, DecimalFormatLocal>(); DecimalFormatLocal dfMapValue = new DecimalFormatLocal(columnFormat); dfMap.put(columnFormat, dfMapValue); ReflectionTestUtils.setField(decimalColumnParser, "dfMap", dfMap); decimalColumnParser.parse(column, stub, method, columnFormat); BigDecimal result = stub.getDecimal11(); assertNotNull(result); assertEquals(BigDecimal.valueOf(12345600, 2), result); assertSame(dfMap, ReflectionTestUtils.getField(decimalColumnParser, "dfMap")); assertEquals(1, dfMap.size()); assertTrue(dfMap.containsKey(columnFormat)); DecimalFormatLocal formatLocal = dfMap.get(columnFormat); assertSame(dfMapValue, formatLocal); }