<orderEntry type="inheritedJdk" /> | <orderEntry type="inheritedJdk" /> | ||||
<orderEntry type="sourceFolder" forTests="false" /> | <orderEntry type="sourceFolder" forTests="false" /> | ||||
<orderEntry type="library" name="junit.jupiter" level="project" /> | <orderEntry type="library" name="junit.jupiter" level="project" /> | ||||
<orderEntry type="library" name="mockito.core" level="project" /> | |||||
</component> | </component> | ||||
</module> | </module> |
package Praktikum02; | |||||
public class ErrorWriter implements IHelloWorldWriter{ | |||||
@Override | |||||
public void writeHelloWorld() { | |||||
System.err.println("Hello World"); | |||||
} | |||||
} |
package Praktikum02; | |||||
public class Executor { | |||||
public static void printHellowWorld(IHelloWorldWriter writer1 , IHelloWorldWriter writer2 , boolean second) { | |||||
if (!second) { | |||||
writer1.writeHelloWorld(); | |||||
}else{ | |||||
writer2.writeHelloWorld(); | |||||
} | |||||
} | |||||
} |
package Praktikum02; | |||||
public interface IHelloWorldWriter { | |||||
void writeHelloWorld(); | |||||
} |
package Praktikum02; | |||||
public class OutWriter implements IHelloWorldWriter{ | |||||
@Override | |||||
public void writeHelloWorld() { | |||||
System.out.println("Hello World"); | |||||
} | |||||
} |
package Praktikum02; | |||||
import org.junit.jupiter.api.Test; | |||||
import static org.junit.jupiter.api.Assertions.*; | |||||
import static org.mockito.Mockito.*; | |||||
class ExecutorTest { | |||||
@Test | |||||
void printHelloWorldOnStdOut() { | |||||
IHelloWorldWriter outMock = mock(OutWriter.class); | |||||
IHelloWorldWriter errMock = mock(ErrorWriter.class); | |||||
Executor.printHellowWorld(outMock, errMock ,false); | |||||
verify(outMock,times(1)).writeHelloWorld(); | |||||
verify(errMock,times(0)).writeHelloWorld(); | |||||
} | |||||
@Test | |||||
void printHelloWorldOnErrorOut() { | |||||
IHelloWorldWriter outMock = mock(OutWriter.class); | |||||
IHelloWorldWriter errMock = mock(ErrorWriter.class); | |||||
Executor.printHellowWorld(outMock, errMock ,true); | |||||
verify(outMock,times(0)).writeHelloWorld(); | |||||
verify(errMock,times(1)).writeHelloWorld(); | |||||
} | |||||
} |