DecimalFormatLocal extends ThreadLocal<DecimalFormat> { @Override protected DecimalFormat initialValue() { DecimalFormat df = new DecimalFormat(pattern); return df; } DecimalFormatLocal(String pattern);   }
@Test public void testInitialValue01() throws Exception { DecimalFormatLocal decimalFormatLocal = new DecimalFormatLocal(null); ReflectionTestUtils.setField(decimalFormatLocal, "pattern", null); try { decimalFormatLocal.initialValue(); fail("NullPointerExceptionが発生しませんでした。"); } catch (NullPointerException e) { assertTrue(e instanceof NullPointerException); } }
@Test public void testInitialValue02() throws Exception { DecimalFormatLocal decimalFormatLocal = new DecimalFormatLocal(null); String pattern = "-\\#,##0.##"; ReflectionTestUtils.setField(decimalFormatLocal, "pattern", pattern); DecimalFormat result = decimalFormatLocal.initialValue(); assertNotNull(result); assertTrue(result instanceof DecimalFormat); assertEquals(pattern, DecimalFormat.class.cast(result).toPattern()); }