NullColumnFormatter implements ColumnFormatter { @Override public String format(Object t, Method method, String columnFormat) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { Object column = method.invoke(t); if (column == null) { return ""; } return column.toString(); }  @Override String format(Object t, Method method, String columnFormat);  }
@Test public void testFormat01() throws Exception { ColumnFormatter columnFormatter = new NullColumnFormatter(); NullColumnFormatter_Stub01 stub = new NullColumnFormatter_Stub01(); ReflectionTestUtils.setField(stub, "string", "aaa"); Method method = stub.getClass().getDeclaredMethod("getString"); String columnFormat = new String(); String testResult = columnFormatter.format(stub, method, columnFormat); assertEquals("aaa", testResult); }
@Test public void testFormat02() throws Exception { ColumnFormatter columnFormatter = new NullColumnFormatter(); NullColumnFormatter_Stub02 stub = new NullColumnFormatter_Stub02(); ReflectionTestUtils.setField(stub, "string", "aaa"); Method method = stub.getClass().getDeclaredMethod("getString"); String columnFormat = new String(); try { columnFormatter.format(stub, method, columnFormat); fail("IllegalAccessExceptionが発生しませんでした。失敗です。"); } catch (Exception e) { assertEquals(IllegalAccessException.class, e.getClass()); } }
@Test public void testFormat03() throws Exception { ColumnFormatter columnFormatter = new NullColumnFormatter(); NullColumnFormatter_Stub03 stub = new NullColumnFormatter_Stub03(); ReflectionTestUtils.setField(stub, "string", "aaa"); Method method = stub.getClass().getMethod("getString"); String columnFormat = new String(); try { columnFormatter.format(stub, method, columnFormat); fail("InvocationTargetExceptionが発生しませんでした。失敗です。"); } catch (Exception e) { assertEquals(InvocationTargetException.class, e.getClass()); } }
@Test public void testFormat04() throws Exception { ColumnFormatter columnFormatter = new NullColumnFormatter(); NullColumnFormatter_Stub04 stub = new NullColumnFormatter_Stub04(); ReflectionTestUtils.setField(stub, "string", "aaa"); Method method = stub.getClass().getDeclaredMethod("getString", new Class[] { String.class }); String columnFormat = new String(); try { columnFormatter.format(stub, method, columnFormat); fail("IllegalArgumentExceptionが発生しませんでした。失敗です。"); } catch (Exception e) { assertEquals(IllegalArgumentException.class, e.getClass()); } }
@Test public void testFormat05() throws Exception { ColumnFormatter columnFormatter = new NullColumnFormatter(); NullColumnFormatter_Stub01 stub = new NullColumnFormatter_Stub01(); Method method = stub.getClass().getDeclaredMethod("getString"); String columnFormat = new String(); String testResult = columnFormatter.format(stub, method, columnFormat); assertEquals("", testResult); }
@Test public void testFormat06() throws Exception { ColumnFormatter columnFormatter = new NullColumnFormatter(); NullColumnFormatter_Stub01 stub = new NullColumnFormatter_Stub01(); Method method = stub.getClass().getDeclaredMethod("getString"); String columnFormat = new String(); try { columnFormatter.format(null, method, columnFormat); fail("NullPointerExceptionが発生しませんでした。失敗です。"); } catch (Exception e) { assertEquals(NullPointerException.class, e.getClass()); } }
@Test public void testFormat07() throws Exception { ColumnFormatter columnFormatter = new NullColumnFormatter(); NullColumnFormatter_Stub01 stub = new NullColumnFormatter_Stub01(); ReflectionTestUtils.setField(stub, "string", "aaa"); String columnFormat = new String(); try { columnFormatter.format(stub, null, columnFormat); fail("NullPointerExceptionが発生しませんでした。失敗です。"); } catch (Exception e) { assertEquals(NullPointerException.class, e.getClass()); } }
@Test public void testFormat08() throws Exception { ColumnFormatter columnFormatter = new NullColumnFormatter(); NullColumnFormatter_Stub01 stub = new NullColumnFormatter_Stub01(); ReflectionTestUtils.setField(stub, "string", "aaa"); Method method = stub.getClass().getDeclaredMethod("getString"); String columnFormat = null; String testResult = columnFormatter.format(stub, method, columnFormat); assertEquals("aaa", testResult); }