Skip to content

Instantly share code, notes, and snippets.

@mrwilson
Created November 2, 2020 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrwilson/afe76f7714f3ea2cf253878cf139b7c2 to your computer and use it in GitHub Desktop.
Save mrwilson/afe76f7714f3ea2cf253878cf139b7c2 to your computer and use it in GitHub Desktop.
Build Your Own Di Library (Part 1)
class TinyInjector {
public <T> T get(Class<T> klass) {
try {
return klass.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
class Zero {
public String say() {
return "Hello, world!";
}
}
class ZeroTest {
@Test
void canInstantiateAZeroArgumentClass() {
var injector = new TinyInjector();
var instance = injector.get(Zero.class);
assertThat(instance.say(), is("Hello, world!"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment