### Question:
AbstractImmutableVocabulary implements Vocabulary { protected final void initialize() { checkStatus(Status.INITIALIZING); if(this.terms.size()!=this.nameOrdinal.size()) { throw new IllegalStateException( String.format( "Vocabulary '%s' (%s) initialization failure: not all reserved names have been registered", this.namespace, getClass().getName())); } this.status=Status.INITIALIZED; } AbstractImmutableVocabulary(Class<T> clazz, String namespace, String prefix); final UUID getId(); @Override final String getNamespace(); @Override final String getPreferredPrefix(); @Override final T[] terms(); @Override final int size(); @Override final T fromName(String name); @Override T fromOrdinal(int ordinal); @Override final T fromValue(V value); @Override final Iterator<Term> iterator();  }### Answer:
@Test(expected=IllegalStateException.class) public void testBadRegistration$afterInitialized() throws Exception { V v=new V(); new ImmutableTerm(v,"entity"); v.initialize(); new ImmutableTerm(v,"entity"); }
@Test(expected=IllegalStateException.class) public void testInitialize$cannotReinit() throws Exception { V v=new V(); new ImmutableTerm(v,"entity"); v.initialize(); v.initialize(); }
@Test public void testBadRegistration$incomplete() throws Exception { V v = new V(); new MockUp<AbstractImmutableVocabulary<ImmutableTerm>>() { @Mock public void registerTerm(ImmutableTerm term) { } }; new ImmutableTerm(v, "one"); try { v.initialize(); fail("Shot not initialize vocabulary without completing term registration"); } catch (IllegalStateException e) { assertThat(e.getMessage(),containsString("Vocabulary 'namespace' (")); assertThat(e.getMessage(),containsString(") initialization failure: not all reserved names have been registered")); } }