ImmutableSubjects implements Subjects { public static ImmutableSubjects of(final Iterable<Subject> subjects) { checkNotNull(subjects, "subjects"); final Map<SubjectId, Subject> subjectsMap = new HashMap<>(); subjects.forEach(subject -> { final Subject existingSubject = subjectsMap.put(subject.getId(), subject); if (null != existingSubject) { final String msgTemplate = "There is more than one Subject with the ID <{0}>!"; throw new IllegalArgumentException(MessageFormat.format(msgTemplate, subject.getId())); } }); return new ImmutableSubjects(subjectsMap); } private  ImmutableSubjects(final Map<SubjectId, Subject> theSubjects); static ImmutableSubjects of(final Iterable<Subject> subjects); static ImmutableSubjects fromJson(final JsonObject jsonObject); @Override Optional<Subject> getSubject(final SubjectId subjectId); @Override Subjects setSubject(final Subject subject); @Override Subjects removeSubject(final SubjectId subjectId); @Override int getSize(); @Override boolean isEmpty(); @Override JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate); @Override Iterator<Subject> iterator(); @Override Stream<Subject> stream(); @SuppressWarnings({"squid:MethodCyclomaticComplexity", "squid:S1067"}) @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }
@Test public void createResourcesWithSamePathsShouldFail() { final Collection<Subject> subjectList = Arrays.asList(SUBJECT_1, SUBJECT_1); assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> ImmutableSubjects.of(subjectList)) .withMessageStartingWith("There is more than one Subject with the ID") .withNoCause(); }