@Test public void shouldNotAllowDuplicateNames() { NameValuePairBuilder builder = new NameValuePairBuilder(); builder.addPair("unique", "value"); catchException(builder).addPair("unique", "newValue"); assertThat(caughtException()).isExactlyInstanceOf(RuntimeException.class); assertThat(caughtException()).hasMessage(NameValuePairBuilder.NOT_UNIQUE_KEY_ERROR + "unique"); }
public NameValuePairBuilder addPair(String name, String value) { if(nameValueMap.containsKey(name)) { throw new RuntimeException(NOT_UNIQUE_KEY_ERROR + name); } nameValueMap.put(name, value); return this; }
NameValuePairBuilder { public NameValuePairBuilder addPair(String name, String value) { if(nameValueMap.containsKey(name)) { throw new RuntimeException(NOT_UNIQUE_KEY_ERROR + name); } nameValueMap.put(name, value); return this; } }
NameValuePairBuilder { public NameValuePairBuilder addPair(String name, String value) { if(nameValueMap.containsKey(name)) { throw new RuntimeException(NOT_UNIQUE_KEY_ERROR + name); } nameValueMap.put(name, value); return this; }  }
NameValuePairBuilder { public NameValuePairBuilder addPair(String name, String value) { if(nameValueMap.containsKey(name)) { throw new RuntimeException(NOT_UNIQUE_KEY_ERROR + name); } nameValueMap.put(name, value); return this; }  NameValuePairBuilder addPair(String name, String value); NameValuePair[] build(); }
NameValuePairBuilder { public NameValuePairBuilder addPair(String name, String value) { if(nameValueMap.containsKey(name)) { throw new RuntimeException(NOT_UNIQUE_KEY_ERROR + name); } nameValueMap.put(name, value); return this; }  NameValuePairBuilder addPair(String name, String value); NameValuePair[] build(); static final String NOT_UNIQUE_KEY_ERROR; }