@@ -9,5 +9,6 @@ | |||
<orderEntry type="inheritedJdk" /> | |||
<orderEntry type="sourceFolder" forTests="false" /> | |||
<orderEntry type="library" name="junit.jupiter" level="project" /> | |||
<orderEntry type="library" name="mockito.core" level="project" /> | |||
</component> | |||
</module> |
@@ -0,0 +1,8 @@ | |||
package Praktikum02; | |||
public class ErrorWriter implements IHelloWorldWriter{ | |||
@Override | |||
public void writeHelloWorld() { | |||
System.err.println("Hello World"); | |||
} | |||
} |
@@ -0,0 +1,11 @@ | |||
package Praktikum02; | |||
public class Executor { | |||
public static void printHellowWorld(IHelloWorldWriter writer1 , IHelloWorldWriter writer2 , boolean second) { | |||
if (!second) { | |||
writer1.writeHelloWorld(); | |||
}else{ | |||
writer2.writeHelloWorld(); | |||
} | |||
} | |||
} |
@@ -0,0 +1,5 @@ | |||
package Praktikum02; | |||
public interface IHelloWorldWriter { | |||
void writeHelloWorld(); | |||
} |
@@ -0,0 +1,9 @@ | |||
package Praktikum02; | |||
public class OutWriter implements IHelloWorldWriter{ | |||
@Override | |||
public void writeHelloWorld() { | |||
System.out.println("Hello World"); | |||
} | |||
} |
@@ -0,0 +1,32 @@ | |||
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(); | |||
} | |||
} |