This file contains hidden or 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
public class ComputerTestUsingSetter { | |
@Test | |
public void testPlayVideo() { | |
Computer computer = new Computer(); | |
MotherBoard motherBoard = new MotherBoard(); | |
SoundCard soundCard = new SoundCard(); | |
VideoCard videoCard = new VideoCard(); | |
SoundSystem soundSystem = Mockito.mock(SoundSystem.class); | |
DisplaySystem displaySystem = Mockito.mock(DisplaySystem.class); |
This file contains hidden or 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
public class ComputerTestUsingTestModule { | |
@Test | |
public void testPlayVideo() { | |
Injector injector = Guice.createInjector(new TestModule() | |
.withMockedClasses(SoundSystem.class, DisplaySystem.class)); | |
Computer computer = injector.getInstance(Computer.class); | |
SoundSystem soundSystem = injector.getInstance(SoundSystem.class); | |
DisplaySystem displaySystem = injector.getInstance(DisplaySystem.class); |
This file contains hidden or 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
public class ComputerTestModule extends TestModule { | |
@Override | |
protected Collection<ClassInstancePair<?>> getDefaultInstances() { | |
return Arrays.asList( | |
createClassMockPair(DisplaySystem.class), | |
createClassMockPair(SoundSystem.class)); | |
} | |
} |
This file contains hidden or 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
public class IntegrationWithDisplaySystemTest { | |
@Test | |
public void testDisplaySystem() { | |
Injector injector = Guice.createInjector(new ComputerTestModule() | |
.withInstance(DisplaySystem.class, new DisplaySystem())); | |
Computer computer = injector.getInstance(Computer.class); | |
// We are satisfied with no exception being thrown |
This file contains hidden or 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
public class IntegrationWithSoundSystemTest { | |
@Test | |
public void testSoundSystem() { | |
Injector injector = Guice.createInjector(new ComputerTestModule() | |
.withInstance(SoundSystem.class, new SoundSystem())); | |
Computer computer = injector.getInstance(Computer.class); | |
// We will be satisfied with no exception being thrown |
OlderNewer