@Test public void testWrongType() throws Exception { expectedEx.expect(RuntimeException.class); expectedEx.expectMessage(Matchers.containsString("must be assignable to TupleTag")); InstanceBuilder.ofType(TupleTag.class) .fromClassName(InstanceBuilderTest.class.getName()) .build(); } }
@Test public void testBadReturnType() throws Exception { expectedEx.expect(RuntimeException.class); expectedEx.expectMessage(Matchers.containsString("must be assignable to String")); InstanceBuilder.ofType(String.class) .fromClassName(InstanceBuilderTest.class.getName()) .fromFactoryMethod("createTag") .withArg(String.class, "hello") .build(); }
@Test public void testBadMethod() throws Exception { expectedEx.expect(RuntimeException.class); expectedEx.expectMessage(Matchers.containsString("Unable to find factory method")); InstanceBuilder.ofType(String.class) .fromClassName(InstanceBuilderTest.class.getName()) .fromFactoryMethod("nonexistantFactoryMethod") .withArg(String.class, "hello") .withArg(String.class, " world!") .build(); }
@Test public void testBadArgs() throws Exception { expectedEx.expect(RuntimeException.class); expectedEx.expectMessage(Matchers.containsString("Unable to find factory method")); InstanceBuilder.ofType(TupleTag.class) .fromClassName(InstanceBuilderTest.class.getName()) .fromFactoryMethod("createTag") .withArg(String.class, "hello") .withArg(Integer.class, 42) .build(); }
@Test public void testFullNameLookup() throws Exception { TupleTag tag = InstanceBuilder.ofType(TupleTag.class) .fromClassName(InstanceBuilderTest.class.getName()) .fromFactoryMethod("createTag") .withArg(String.class, "hello world!") .build(); Assert.assertEquals("hello world!", tag.getId()); }