Browse Source

Mock test

master
Tim Lachmann 3 weeks ago
parent
commit
def506778a

+ 1
- 0
Softwareengeneering.iml View File

<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>

+ 8
- 0
src/Praktikum02/ErrorWriter.java View File

package Praktikum02;

public class ErrorWriter implements IHelloWorldWriter{
@Override
public void writeHelloWorld() {
System.err.println("Hello World");
}
}

+ 11
- 0
src/Praktikum02/Executor.java View File

package Praktikum02;

public class Executor {
public static void printHellowWorld(IHelloWorldWriter writer1 , IHelloWorldWriter writer2 , boolean second) {
if (!second) {
writer1.writeHelloWorld();
}else{
writer2.writeHelloWorld();
}
}
}

+ 5
- 0
src/Praktikum02/IHelloWorldWriter.java View File

package Praktikum02;

public interface IHelloWorldWriter {
void writeHelloWorld();
}

+ 9
- 0
src/Praktikum02/OutWriter.java View File

package Praktikum02;

public class OutWriter implements IHelloWorldWriter{

@Override
public void writeHelloWorld() {
System.out.println("Hello World");
}
}

+ 32
- 0
test/Praktikum02/ExecutorTest.java View File

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();

}
}

Loading…
Cancel
Save