34
34
* @since 0.1
35
35
*/
36
36
final class GenericIoStubTest {
37
- /**
38
- * The client id for the test.
39
- */
40
- public static final ClientId SPEC_CLIENT = Mocks .testRequestFromVipClient ().clientId ();
37
+ public static final ClientId ANY_CLIENT = new ClientId ("any client" );
38
+
39
+ public static final ClientId VIP_CLIENT = new ClientId ("12345" );
40
+
41
+ public static final ClientId NEW_CLIENT = new ClientId ("new client" );
42
+
43
+ public static final QueryId TEST_REQUEST = new QueryId ("test_request" );
41
44
42
45
@ Test
43
46
void createDefaultStub () {
44
47
final GenericIoStub target = new GenericIoStub ();
45
48
target .addCommonStub (Mocks .defaultStub ());
46
- Assertions .assertThat (target .nextResponseFor (Mocks . testRequestFromAnyClient () ))
49
+ Assertions .assertThat (target .nextResponseFor (ANY_CLIENT , TEST_REQUEST ))
47
50
.isEqualTo (Mocks .defaultResponse ());
48
- Assertions .assertThat (target .nextResponseFor (Mocks . testRequestFromVipClient () ))
51
+ Assertions .assertThat (target .nextResponseFor (VIP_CLIENT , TEST_REQUEST ))
49
52
.isEqualTo (Mocks .defaultResponse ());
50
53
}
51
54
52
55
@ Test
53
56
void createInfiniteStubForSpecificClient () {
54
57
final GenericIoStub target = new GenericIoStub ();
55
58
target .addCommonStub (Mocks .defaultStub ());
56
- target .addClientStub (Mocks .emptyStub (), GenericIoStubTest .SPEC_CLIENT );
57
- Assertions .assertThat (target .nextResponseFor (Mocks . testRequestFromAnyClient () ))
59
+ target .addClientStub (Mocks .emptyStub (), GenericIoStubTest .VIP_CLIENT );
60
+ Assertions .assertThat (target .nextResponseFor (ANY_CLIENT , TEST_REQUEST ))
58
61
.isEqualTo (Mocks .defaultResponse ());
59
- Assertions .assertThat (target .nextResponseFor (Mocks . testRequestFromVipClient () ))
62
+ Assertions .assertThat (target .nextResponseFor (VIP_CLIENT , TEST_REQUEST ))
60
63
.isEqualTo (Mocks .emptyResponse ());
61
64
}
62
65
63
66
@ Test
64
67
void shouldAddResponseToStoredResponses () {
65
68
final GenericIoStub target = new GenericIoStub ();
66
69
target .addCommonStub (Mocks .defaultStub ());
67
- target .addClientStub (Mocks .emptyStub (), GenericIoStubTest .SPEC_CLIENT );
70
+ target .addClientStub (Mocks .emptyStub (), GenericIoStubTest .VIP_CLIENT );
68
71
final Set <Stub > stubs = target .getResponsesFor ("test_request" );
69
72
Assertions .assertThat (stubs .stream ().map (Stub ::name ).toList ())
70
73
.isNotEmpty ()
@@ -77,9 +80,9 @@ void shouldAddResponseToStoredResponses() {
77
80
@ Test
78
81
void shouldAddTheExceptionAsTheResponse () {
79
82
final GenericIoStub target = new GenericIoStub ();
80
- target .addClientStub (Mocks .errorStub (), GenericIoStubTest .SPEC_CLIENT );
83
+ target .addClientStub (Mocks .errorStub (), GenericIoStubTest .VIP_CLIENT );
81
84
Assertions
82
- .assertThatThrownBy (() -> target .nextResponseFor (Mocks . testRequestFromVipClient () ))
85
+ .assertThatThrownBy (() -> target .nextResponseFor (VIP_CLIENT , TEST_REQUEST ))
83
86
.isInstanceOf (RuntimeException .class )
84
87
.hasMessage ("test error" );
85
88
}
@@ -88,31 +91,31 @@ void shouldAddTheExceptionAsTheResponse() {
88
91
void shouldActivateOneOfStoredResponses () {
89
92
final GenericIoStub target = new GenericIoStub ();
90
93
target .addCommonStub (Mocks .defaultStub ());
91
- target .addClientStub (Mocks .emptyStub (), GenericIoStubTest .SPEC_CLIENT );
92
- Assertions .assertThat (target .nextResponseFor (Mocks . testRequestFromVipClient () ))
94
+ target .addClientStub (Mocks .emptyStub (), GenericIoStubTest .VIP_CLIENT );
95
+ Assertions .assertThat (target .nextResponseFor (VIP_CLIENT , TEST_REQUEST ))
93
96
.isEqualTo (Mocks .emptyResponse ());
94
97
target .setActiveResponse (
95
- GenericIoStubTest .SPEC_CLIENT ,
98
+ GenericIoStubTest .VIP_CLIENT ,
96
99
Mocks .defaultStub ().query (),
97
100
Mocks .defaultStub ().name ()
98
101
);
99
- Assertions .assertThat (target .nextResponseFor (Mocks . testRequestFromVipClient () ))
102
+ Assertions .assertThat (target .nextResponseFor (VIP_CLIENT , TEST_REQUEST ))
100
103
.isEqualTo (Mocks .defaultResponse ());
101
104
}
102
105
103
106
@ Test
104
107
void shouldActivateStoredResponseForNewClient () {
105
108
final GenericIoStub target = new GenericIoStub ();
106
109
target .addCommonStub (Mocks .defaultStub ());
107
- target .addClientStub (Mocks .emptyStub (), GenericIoStubTest .SPEC_CLIENT );
108
- Assertions .assertThat (target .nextResponseFor (Mocks . testRequestFromNewClient () ))
110
+ target .addClientStub (Mocks .emptyStub (), GenericIoStubTest .VIP_CLIENT );
111
+ Assertions .assertThat (target .nextResponseFor (NEW_CLIENT , TEST_REQUEST ))
109
112
.isEqualTo (Mocks .defaultResponse ());
110
113
target .setActiveResponse (
111
- Mocks . testRequestFromNewClient (). clientId () ,
114
+ NEW_CLIENT ,
112
115
Mocks .emptyStub ().query (),
113
116
Mocks .emptyStub ().name ()
114
117
);
115
- Assertions .assertThat (target .nextResponseFor (Mocks . testRequestFromNewClient () ))
118
+ Assertions .assertThat (target .nextResponseFor (NEW_CLIENT , TEST_REQUEST ))
116
119
.isEqualTo (Mocks .emptyResponse ());
117
120
}
118
121
}
0 commit comments