RequiredParameters { public Option add(String name) throws RequiredParametersException { if (!this.data.containsKey(name)) { Option option = new Option(name); this.data.put(name, option); return option; } else { throw new RequiredParametersException("Option with key " + name + " already exists."); } } RequiredParameters(); Option add(String name); void add(Option option); void applyTo(ParameterTool parameterTool); String getHelp(); String getHelp(List<String> missingArguments);  }
@Test public void testAddWithAlreadyExistingParameter() throws RequiredParametersException { expectedException.expect(RequiredParametersException.class); expectedException.expectMessage("Option with key berlin already exists."); RequiredParameters required = new RequiredParameters(); required.add(new Option("berlin")); required.add(new Option("berlin")); }
@Test public void testStringBasedAddWithAlreadyExistingParameter() throws RequiredParametersException { expectedException.expect(RequiredParametersException.class); expectedException.expectMessage("Option with key berlin already exists."); RequiredParameters required = new RequiredParameters(); required.add("berlin"); required.add("berlin"); }