Commit 7300fcf8 authored by Matthew Dawson's avatar Matthew Dawson
Browse files

Make sure we throw an exception with duplicated names.

A missing throw keyword allowed an exceptional circumstance to continue, when
an enumeration name conflicted with either another enumeration name or with
a variable.  Add appropriate tests to catch such issues and add the throw
keyword.
parent 2a2ecb08
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ final public class VariableCollection {
            for(EnumerationVariableType enumType : enumerationTypes) {
                for(String enumValue : enumType.enumerationValues()) {
                    if (m_variablesAndEnumeratedValues.containsKey(enumValue)) {
                        new IllegalArgumentException("Enumerated value conflicts with existing variable!");
                        throw new IllegalArgumentException("Enumerated value conflicts with existing variable!");
                    }
                    m_variablesAndEnumeratedValues.put(enumValue, new Variable(enumValue, enumType));
                }
+16 −0
Original line number Diff line number Diff line
@@ -131,4 +131,20 @@ public class VariableCollectionTest {
        assertThat(vars.getVariablesAndEnumeratedValues().get("e3").name(), is("e3"));
        assertThat(vars.getVariablesAndEnumeratedValues().get("e3").type(), is((VariableType)type));
    }

    @Test(expected = IllegalArgumentException.class)
    public void ConflictingEnumeratedValuesThrow() {
        EnumerationVariableType type = new EnumerationVariableType("myenum");
        type.enumerationValues().add("e1");
        type.enumerationValues().add("e2");
        type.enumerationValues().add("e3");

        Set<EnumerationVariableType> enums = new HashSet<EnumerationVariableType>();
        enums.add(type);

        Map<String, Variable> var = new HashMap<String, Variable>();
        var.put("e1", new Variable("e1", type));

        new VariableCollection(var, enums); // Should throw as e1 the variable conflicts with the enumerated name e1.
    }
}