25
25
package ewc .utilities .testableio .external ;
26
26
27
27
import ewc .utilities .testableio .core .*;
28
+ import java .util .Map ;
28
29
import java .util .stream .Stream ;
29
30
import org .assertj .core .api .Assertions ;
30
31
import org .junit .jupiter .api .BeforeEach ;
@@ -43,10 +44,11 @@ final class EndToEndTest {
43
44
public static final ClientId ANY_CLIENT = new ClientId ("any client" );
44
45
public static final ClientId VIP_CLIENT = new ClientId ("VIP client" );
45
46
public static final ClientId NEW_CLIENT = new ClientId ("new client" );
47
+ public static final IllegalStateException NO_SUCH_PAGE_EXCEPTION = new IllegalStateException ("no such page" );
46
48
public static final GenericResponse DEFAULT_HOME_PAGE = new GenericResponse ("html for the home page" );
47
49
public static final GenericResponse DEFAULT_NUMBER_PAGE = new GenericResponse (1000L );
48
- public static final IllegalStateException NO_SUCH_PAGE = new IllegalStateException ("no such page" );
49
50
public static final GenericResponse VIP_HOME_PAGE = new GenericResponse ("VIP home page" );
51
+ public static final GenericResponse NO_SUCH_PAGE = new GenericResponse (NO_SUCH_PAGE_EXCEPTION );
50
52
private GenericIoStub target ;
51
53
52
54
@ BeforeEach
@@ -57,7 +59,7 @@ void setUp() {
57
59
.withContents (DEFAULT_HOME_PAGE )
58
60
.withResponseId ("home" ),
59
61
Stub .forQueryId ("non-existing" )
60
- .withContents (new GenericResponse ( NO_SUCH_PAGE ) )
62
+ .withContents (NO_SUCH_PAGE )
61
63
.withResponseId ("non-existing" ),
62
64
Stub .forQueryId ("number" )
63
65
.withContents (DEFAULT_NUMBER_PAGE )
@@ -73,9 +75,9 @@ void shouldHaveAPredefinedSetOfDefaultResponses() {
73
75
when (ANY_CLIENT ).requests (NUMBER_PAGE ).then (DEFAULT_NUMBER_PAGE );
74
76
when (NEW_CLIENT ).requests (NUMBER_PAGE ).then (DEFAULT_NUMBER_PAGE );
75
77
when (VIP_CLIENT ).requests (NUMBER_PAGE ).then (DEFAULT_NUMBER_PAGE );
76
- when (ANY_CLIENT ).requests (MISSING_PAGE ).thenThrows (NO_SUCH_PAGE );
77
- when (NEW_CLIENT ).requests (MISSING_PAGE ).thenThrows (NO_SUCH_PAGE );
78
- when (VIP_CLIENT ).requests (MISSING_PAGE ).thenThrows (NO_SUCH_PAGE );
78
+ when (ANY_CLIENT ).requests (MISSING_PAGE ).thenThrows (NO_SUCH_PAGE_EXCEPTION );
79
+ when (NEW_CLIENT ).requests (MISSING_PAGE ).thenThrows (NO_SUCH_PAGE_EXCEPTION );
80
+ when (VIP_CLIENT ).requests (MISSING_PAGE ).thenThrows (NO_SUCH_PAGE_EXCEPTION );
79
81
}
80
82
81
83
@ Test
@@ -106,6 +108,25 @@ void shouldChooseActiveStubFromStoredStubs() {
106
108
when (ANY_CLIENT ).requests (HOME_PAGE ).then (DEFAULT_HOME_PAGE );
107
109
}
108
110
111
+ @ Test
112
+ void shouldReturnCorrectCommonState () {
113
+ final Map <QueryId , GenericResponse > actual = this .target .getCurrentCommonStubs ();
114
+ Assertions .assertThat (actual )
115
+ .containsEntry (HOME_PAGE , DEFAULT_HOME_PAGE )
116
+ .containsEntry (NUMBER_PAGE , DEFAULT_NUMBER_PAGE )
117
+ .containsEntry (MISSING_PAGE , NO_SUCH_PAGE );
118
+ }
119
+
120
+ @ Test
121
+ void shouldCombineCommonAndClientCurrentState () {
122
+ final Stub newHome = Stub .forQueryId ("home" ).withContents (VIP_HOME_PAGE ).withResponseId ("home" );
123
+ this .target .addClientStub (newHome , VIP_CLIENT );
124
+ final Map <QueryId , GenericResponse > actual = this .target .getCurrentClientStubs (VIP_CLIENT );
125
+ Assertions .assertThat (actual )
126
+ .containsEntry (HOME_PAGE , VIP_HOME_PAGE )
127
+ .containsEntry (NUMBER_PAGE , DEFAULT_NUMBER_PAGE )
128
+ .containsEntry (MISSING_PAGE , NO_SUCH_PAGE );
129
+ }
109
130
110
131
private When when (ClientId client ) {
111
132
return new When (client );
0 commit comments