### Question:
MutableDataSet implements DataSet { @Override public <T extends Serializable, S extends Individual<T, S>> S individual(T id, Class<? extends S> clazz) { Individual<T,?> result=individualOfId(id); if(result==null) { result=factory.newIndividual(clazz,id); this.individuals.put(id,result); } else if (!clazz.isInstance(result)) { throw new IllegalStateException("Existing individual '"+id+"' is not compatible with '"+clazz.getCanonicalName()+"' ("+result.getClass().getCanonicalName()+")"); } return clazz.cast(result); } MutableDataSet(Name<?> name); @Override Name<?> name(); @Override int numberOfIndividuals(); @Override boolean hasIndividuals(); @Override Collection<Individual<?, ?>> individuals(); @Override Set<Serializable> individualIds(); @Override boolean hasIndividual(Object id); @SuppressWarnings("unchecked") @Override S individualOfId(T id); @Override S individual(T id, Class<? extends S> clazz); @Override Iterator<Individual<?, ?>> iterator(); @Override boolean isEmpty(); @Override void remove(final Individual<?, ?> src); @Override String toString();  }### Answer:
@Test public void testIndividual$unsupportedClass() throws Exception { try { sut.individual("urn:individual", UnsupportedIndividual.class); fail("Should not create individuals for unsupported individual types"); } catch (IllegalStateException e) { assertThat(e.getMessage(),equalTo("Unsupported individual type 'org.ldp4j.application.data.MutableDataSetTest.UnsupportedIndividual'")); } }
@Test public void testIdentifierReuseIsForbidden() throws Exception { sut.individual(URI.create("urn:individual"), ExternalIndividual.class); try { sut.individual(URI.create("urn:individual"), NewIndividual.class); } catch (IllegalStateException e) { assertThat(e.getMessage(),equalTo("Existing individual 'urn:individual' is not compatible with 'org.ldp4j.application.data.NewIndividual' (org.ldp4j.application.data.MutableExternalIndividual)")); } }
@Test public void testIndividualsAreOnlyCreatedOnce() throws Exception { ExternalIndividual individual = sut.individual(URI.create("urn:individual"), ExternalIndividual.class); assertThat(sut.individual(URI.create("urn:individual"), ExternalIndividual.class),sameInstance(individual)); }