PrependingNameTranslator implements NameTranslator<T> { @Override public String translate(T value) { return getPrefix() + translator.translate(value); } PrependingNameTranslator(NameTranslator<T> translator);  PrependingNameTranslator(NameTranslator<T> translator, String prefix); @Override String translate(T value);  }
@Test public void translate_prependsString() throws Exception { final Index<?> index = mock(Index.class); NameTranslator<Index<?>> translator = new NameTranslator<Index<?>>() { @Override public String translate(Index<?> value) { return (value == index) ? "INDEX" : null; } }; PrependingNameTranslator<Index<?>> prepender = new PrependingNameTranslator<>(translator, "PRE_"); assertEquals("PRE_INDEX", prepender.translate(index)); }
@Test public void translate_withGetPrefixOverride_prependsString() throws Exception { final Index<?> index = mock(Index.class); NameTranslator<Index<?>> translator = new NameTranslator<Index<?>>() { @Override public String translate(Index<?> value) { return (value == index) ? "INDEX" : null; } }; PrependingNameTranslator<Index<?>> prepender = new PrependingNameTranslator<Index<?>>(translator) { @Override protected String getPrefix() { return "FOO_"; } }; assertEquals("FOO_INDEX", prepender.translate(index)); }