-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathKpjTestingTest.java
64 lines (45 loc) · 1.36 KB
/
KpjTestingTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package cz.inventi.kpj.kpjtesting;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
/**
* 1. Create Spy on the {@link KpjTesting#helloWorldService} field <br/>
* 2. Add JUnit annotations <br/>
* 3. Verify the {@link HelloWorldServiceImpl#helloWorld()} is called <br/>
* 4. Change behavior of {@link HelloWorldServiceImpl#echo(String)} to always
* returns "KPJ Rulez" <br/>
*/
@MockitoSettings(strictness = Strictness.LENIENT)
public class KpjTestingTest {
HelloWorldService helloWorldService = new HelloWorldServiceImpl();
KpjTesting kpjTesting;
void setUp() {
// setup mocks for all tests
// hint you have to use doReturn for Spy
// Change behavior of HelloWorldServiceImpl#echo(String)
// to always returns "KPJ Rulez"
}
void testPrintHelloWorld() {
// no given
// when
kpjTesting.printHelloWorld();
// then
// verify the HelloWorldServiceImpl#helloWorld() is called
}
void testPrintEcho() {
// no given
// when
String result = kpjTesting.printEcho("Print ECHO");
// then
// add assert the result equals "KPJ Rulez"
}
static class HelloWorldServiceImpl implements HelloWorldService {
@Override
public String helloWorld() {
return "Hello world";
}
@Override
public String echo(String echo) {
return echo;
}
}
}