NamesProviderImpl implements NamesProvider { @NotNull @Override public String buildMessageName(@NotNull String methodName) { StringBuilder name = new StringBuilder(StringUtils.capitalize(methodName)); name.append("Message"); final int length = name.length(); int index = 0; while (mUsed.contains(name)) { name.setLength(length); name.append(++index); } String result = name.toString(); mUsed.add(result); return result; }  @NotNull @Override String buildMessageName(@NotNull String methodName);  }
@Test public void buildMessageName_sameName_uniqueName() { NamesProviderImpl namesProvider = new NamesProviderImpl(); Assert.assertEquals("TestMethodMessage", namesProvider.buildMessageName("testMethod")); }
@Test public void buildMessageName_sameNameWithCounter_nonUniqueName() { NamesProviderImpl namesProvider = new NamesProviderImpl(); namesProvider.buildMessageName("testMethod"); Assert.assertEquals("TestMethodMessage1", namesProvider.buildMessageName("testMethod")); }