### Question:
Creator { public static <T> T newOf( Class<T> type, Object... args ) { Map<?, ?> map = Maps.mapFromArray( args ); Context context = DependencyInjection.fromMap(map); context.add( DependencyInjection.classes(type) ); return context.get( type ); }  static T create(Class<T> type, Map<?, ?> map); static T create(Class<T> type, Context context); static T newOf( Class<T> type, Object... args );  }### Answer:
@Test public void testCreateWithInstance2() { Bar bar = new Bar(); bar.name = "baz"; Foo foo = newOf( fooType, "bar", bar ); boolean ok = foo != null || die(); ok = foo.bar != null || die(); ok = foo.bar.name.equals( "baz" ) || die(); }
@Test public void testCreateWithInstance3() { Bar bar = new Bar(); bar.name = "baz"; Foo foo = newOf( fooType, "bar", bar ); boolean ok = foo != null || die(); ok = foo.bar != null || die(); ok = foo.bar.name.equals( "baz" ) || die(); }
@Test public void testCreateWithInstance4() { Foo foo = newOf( fooType, "bar", map("class", "org.boon.di.CreatorTest$Bar", "name", "barFromMap") ); boolean ok = foo != null || die(); ok = foo.bar != null || die(); ok = foo.bar.name.equals( "barFromMap" ) || die(); }
@Test public void testCreateWithStuff() { Foo foo = newOf( fooType, "bar", Bar.class, "someClass", new SomeClass(), "object2", SomeClass.class ); boolean ok = foo != null || die(); ok = foo.bar != null || die(); ok = foo.object != null || die(); ok = foo.object2 != null || die(); ok = foo.object != foo.object2 || die(); ok = foo.bar.name.equals( "bar" ) || die(); }
@Test public void testCreateWithStuff2() { Foo foo = newOf( fooType, "bar", Bar.class, "someClass", new SomeClass() ); boolean ok = foo != null || die(); ok = foo.bar != null || die(); ok = foo.object != null || die(); ok = foo.object2 != null || die(); ok = foo.object == foo.object2 || die(); ok = foo.bar.name.equals( "bar" ) || die(); }