### Question:
ImmutableTerm implements Term { @Override public int compareTo(Term other) { ImmutableTerm self = this; if(self.getDeclaringVocabulary() != other.getDeclaringVocabulary()) { throw new ClassCastException(); } return self.ordinal - other.ordinal(); } ImmutableTerm(AbstractImmutableVocabulary<? extends ImmutableTerm> vocabulary, String entityName); @Override final int ordinal(); @Override final String name(); @Override final String entityName(); @Override final String qualifiedEntityName(); @Override final Vocabulary getDeclaringVocabulary(); @Override V as(Class<? extends V> valueClass); @Override final boolean equals(Object other); @Override final int hashCode(); @Override String toString(); @Override int compareTo(Term other);  }### Answer:
@Test public void testCompareTo$differentInstancesSameVocabulary() throws Exception { V v=new V(); ImmutableTerm term1 = new ImmutableTerm(v,"termA"); V v2=new V(); ImmutableTerm term2 = new ImmutableTerm(v2,"termA"); try { term1.compareTo(term2); fail("Should not be able to compare between different instances of the same vocabulary"); } catch(ClassCastException e) { } }
@Test public void testCompareTo$differentVocabularies() throws Exception { class VV extends V { private static final long serialVersionUID = 6590572386564141355L; } V v=new V(); ImmutableTerm term1 = new ImmutableTerm(v,"termA"); VV v2=new VV(); ImmutableTerm term2 = new ImmutableTerm(v2,"termA"); try { term1.compareTo(term2); fail("Should not be able to compare between different vocabularies"); } catch(ClassCastException e) { } }
@Test public void testCompareTo$sameVocabulary() throws Exception { V v=new V(); ImmutableTerm term1 = new ImmutableTerm(v,"termA"); ImmutableTerm term2 = new ImmutableTerm(v,"termB"); assertThat(term1.compareTo(term2),not(greaterThanOrEqualTo(0))); assertThat(term2.compareTo(term1),greaterThanOrEqualTo(0)); assertThat(term1.compareTo(term1),equalTo(0)); }