CollectionOfMocksFieldSet implements Iterable<CollectionOfMocksField<Collection<Object>, Object>> { @SuppressWarnings({ "rawtypes", "unchecked" }) public void add(CollectionOfMocksField collectionOfMocksField) { if (hasMatchingInjectableCollection(collectionOfMocksField)) { throw new IllegalArgumentException("There is more than one CollectionOfMocks of type of collection " + collectionOfMocksField.getTypeOfCollection() + " and type of element " + collectionOfMocksField.getTypeOfElements()); } this.collectionOfMocksFields.add(collectionOfMocksField); } @SuppressWarnings("rawtypes")  CollectionOfMocksFieldSet(CollectionOfMocksField... collections); @SuppressWarnings("rawtypes")  CollectionOfMocksFieldSet(Collection<CollectionOfMocksField> collections); @SuppressWarnings({ "rawtypes", "unchecked" }) void add(CollectionOfMocksField collectionOfMocksField); int size(); Iterator<CollectionOfMocksField<Collection<Object>, Object>> iterator(); Set<CollectionOfMocksField<Collection<Object>, Object>> asSet();  }
@Test @SuppressWarnings("rawtypes") public void shouldFailToAddMatchingMockCollection() { CollectionOfMocksField mocksField1 = mock(CollectionOfMocksField.class); CollectionOfMocksField mocksField2 = mock(CollectionOfMocksField.class); given(mocksField1.matches(mocksField2)).willReturn(true); given(mocksField2.matches(mocksField1)).willReturn(true); CollectionOfMocksFieldSet set = new CollectionOfMocksFieldSet(mocksField1); try { set.add(mocksField2); fail(); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().contains("more than one")); } }