public void setType(TypedIF typed, Topic type) { if (type == null) { return; } TopicIF resolved = topic.resolve(typed.getTopicMap(), type); if (!typed.getType().equals(resolved)) { typed.setType(resolved); } } }
public void testType() { if (typed instanceof TopicNameIF) { TopicMapIF tm = typed.getTopicMap(); TopicIF defaultNameType = tm.getTopicBySubjectIdentifier(PSI .getSAMNameType()); assertTrue("type not equal to the default name type initially", typed .getType().equals(defaultNameType)); } else { assertTrue("type null initially", typed.getType() != null); } TopicIF type = builder.makeTopic(); typed.setType(type); assertTrue("type identity not retained", typed.getType().equals(type)); if (typed instanceof TopicNameIF) { typed.setType(null); TopicMapIF tm = typed.getTopicMap(); TopicIF defaultNameType = tm.getTopicBySubjectIdentifier(PSI .getSAMNameType()); assertTrue("type is not equal to the default name type when set to null", typed.getType().equals(defaultNameType)); } else { try { typed.setType(null); fail("type could be set to null"); } catch (NullPointerException e) { } assertTrue("type identity not retained", typed.getType().equals(type)); } }