/** * Provides a message for use with exceptions when no valid constructor is * found. The message is built using the suggestions from {@link * #suggest(Class)}. * * @param key the constructor key to build the message for * @return a message listing possible constructors */ private String getSuggestionMessage(ConstructorKey key) { StringBuilder sb = new StringBuilder(200); sb.append("No constructor found for '").append(key); sb.append("' candidates are: "); Iterator<ConstructorKey> iterator = suggest(key.intf()); while (iterator.hasNext()) { sb.append(iterator.next()); if (iterator.hasNext()) { sb.append(", "); } } return sb.toString(); }
/** * Provides a message for use with exceptions when no valid constructor is * found. The message is built using the suggestions from {@link * #suggest(Class)}. * * @param key the constructor key to build the message for * @return a message listing possible constructors */ private String getSuggestionMessage(ConstructorKey key) { StringBuilder sb = new StringBuilder(200); sb.append("No constructor found for '").append(key); sb.append("' candidates are: "); Iterator<ConstructorKey> iterator = suggest(key.intf()); while (iterator.hasNext()) { sb.append(iterator.next()); if (iterator.hasNext()) { sb.append(", "); } } return sb.toString(); }
/** * Kind of already tested in other methods. */ @Test public void testSuggest() throws Exception { DynamicFactory factory = new DynamicFactory(5); IAtom atom = mock(MockedAtom.class); assertFalse(factory.suggest(IAtom.class).hasNext()); factory.register(IAtom.class, atom.getClass()); assertTrue(factory.suggest(IAtom.class).hasNext()); }
@Test public void testRegister_PrivateConstructor() throws Exception { DynamicFactory factory = new DynamicFactory(5); assertTrue(factory.implementorsOf(ICDKObject.class).isEmpty()); // register the mock class factory.register(ICDKObject.class, DynamicFactoryTestMock.class); Iterator<?> it = factory.suggest(ICDKObject.class); List<Object> list = new ArrayList<Object>(5); while (it.hasNext()) { list.add(it.next()); } assertThat("mocked atom should have two public constructors", list.size(), is(2)); }