DateFormatLocal extends ThreadLocal<DateFormat> { @Override protected DateFormat initialValue() { SimpleDateFormat sdf = new SimpleDateFormat(pattern); sdf.setLenient(false); return sdf; } DateFormatLocal(String pattern);   }
@Test public void testDateFormatinitialValue01() throws Exception { DateFormatLocal dateFormatLocal = new DateFormatLocal(null); ReflectionTestUtils.setField(dateFormatLocal, "pattern", null); try { dateFormatLocal.initialValue(); fail("NullPointerExceptionが発生しませんでした。"); } catch (NullPointerException e) { assertTrue(e instanceof NullPointerException); } }
@Test public void testDateFormatinitialValue02() throws Exception { DateFormatLocal dateFormatLocal = new DateFormatLocal(null); String pattern = "yyyy/MM/dd"; ReflectionTestUtils.setField(dateFormatLocal, "pattern", pattern); DateFormat result = dateFormatLocal.initialValue(); assertNotNull(result); assertTrue(result instanceof SimpleDateFormat); assertEquals(pattern, SimpleDateFormat.class.cast(result).toPattern()); assertFalse(result.isLenient()); }