InlineMemberFormatter implements MemberFormatter { @Override public String formatMember( Member member ) { Annotation annot = member.getLevel().getAnnotationMap().get( FORMAT_STRING ); if ( annot == null ) { throw new IllegalStateException( "Missing InlineMemberFormatString on level " + member.getLevel().getUniqueName() ); } Object key = member.getPropertyValue( Property.KEY.getName() ); Format format = Format.get( annot.getValue().toString(), Locale.getDefault() ); return format.format( key ); }  @Override String formatMember( Member member ); static String FORMAT_STRING; }
@Test public void testFormatMember() { Level level = mock( Level.class ); Member member = mock( Member.class ); when( member.getLevel() ).thenReturn( level ); when( member.getPropertyValue( Property.KEY.getName() ) ).thenReturn( ( new GregorianCalendar( 1997, 0, 2 ).getTime() ) ); InlineMemberFormatter formatter = new InlineMemberFormatter(); try { formatter.formatMember( member ); fail(); } catch ( IllegalStateException execption ) { } Annotation annotation = mock( Annotation.class ); when( annotation.getValue() ).thenReturn( FORMAT ); Map<String, Annotation> annotationMap = new HashMap<>(); annotationMap.put( InlineMemberFormatter.FORMAT_STRING, annotation ); when( level.getAnnotationMap() ).thenReturn( annotationMap ); String formatterMember = formatter.formatMember( member ); System.out.println( formatterMember ); assertEquals( "1997-01-02", formatterMember ); }