Created
November 2, 2020 16:30
-
-
Save mrwilson/afe76f7714f3ea2cf253878cf139b7c2 to your computer and use it in GitHub Desktop.
Build Your Own Di Library (Part 1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TinyInjector { | |
public <T> T get(Class<T> klass) { | |
try { | |
return klass.newInstance(); | |
} catch (InstantiationException | IllegalAccessException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Zero { | |
public String say() { | |
return "Hello, world!"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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