AlternateIndexFormatter implements PropertyNameFormatter { public String format( String name ) { String formattedName = name; int indexDelimiter = name.lastIndexOf( '_' ); if ( indexDelimiter > 0 ) { String possibleIndex = name.substring( indexDelimiter + 1 ); try { int index = Integer.parseInt( possibleIndex ); String propertyName = name.substring( 0, indexDelimiter ); formattedName = propertyName + "[" + index + "]"; return formattedName; } catch ( NumberFormatException e ) { } } return formattedName; }  String format( String name );  }
@Test public void testFormat_indexed() { AlternateIndexFormatter formatter = new AlternateIndexFormatter(); String actual = formatter.format( INDEXED_NAME ); assertEquals( "indexed name should be formated", INDEXED_NAME_CONVERTED, actual ); }
@Test public void testFormat_underscore() { AlternateIndexFormatter formatter = new AlternateIndexFormatter(); String actual = formatter.format( UNDERSCORE_NAME ); assertEquals( "underscore without number should not be formated", UNDERSCORE_NAME, actual ); }
@Test public void testFormat_simpleName() { AlternateIndexFormatter formatter = new AlternateIndexFormatter(); String actual = formatter.format( SIMPLE_NAME ); assertEquals( "simple name should not be formated", SIMPLE_NAME, actual ); }