### Question:
CompassFormat extends NumberFormat { public String getDirectionCode(double direction) { direction = direction % 360; if (direction < 0.0) { direction = direction + 360.0; } int index = ((int) Math.floor(direction / 11.25) + 1) / 2; return directions[index]; } CompassFormat();  CompassFormat(String n, String e, String s, String w);  CompassFormat(String[] directions); String getDirectionCode(double direction); @Override StringBuffer format(double number, StringBuffer toAppendTo,
                               FieldPosition pos); @Override StringBuffer format(long number, StringBuffer toAppendTo,
                               FieldPosition pos); @Override Number parse(String source, ParsePosition parsePosition); final String[] directions; }### Answer:
@Test public void testDefaultConstructor() { final CompassFormat fmt = new CompassFormat(); assertEquals("N", fmt.getDirectionCode(0)); assertEquals("N", fmt.getDirectionCode(360)); }
@Test public void testCustomFormat() { final CompassFormat fmt = new CompassFormat(); final CompassFormat fmtCustom = new CompassFormat("N", "O", "S", "W"); assertEquals("E", fmt.getDirectionCode(90)); assertEquals("O", fmtCustom.getDirectionCode(90)); assertEquals("NNO", fmtCustom.getDirectionCode(22.5)); }