-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGetStateRequestTests.java
More file actions
164 lines (106 loc) · 4.81 KB
/
Copy pathGetStateRequestTests.java
File metadata and controls
164 lines (106 loc) · 4.81 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* Copyright 2016-2023 Berry Cloud Ltd. All rights reserved.
*/
package dev.learning.xapi.client;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import dev.learning.xapi.client.GetStateRequest.Builder;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.web.util.UriComponentsBuilder;
/**
* GetStateRequest Tests.
*
* @author Thomas Turrell-Croft
*/
@DisplayName("GetStateRequest Tests")
class GetStateRequestTests {
@Test
void whenBuildingGetStateRequestWithAllParametersThenNoExceptionIsThrown() {
// When Building GetStateRequest With All Parameters
final Builder<?, ?> builder = GetStateRequest.builder()
.activityId("https://example.com/activity/1")
.agent(a -> a.name("A N Other").mbox("mailto:another@example.com"))
.registration("67828e3a-d116-4e18-8af3-2d2c59e27be6")
.stateId("bookmark");
// Then No Exception Is Thrown
assertDoesNotThrow(builder::build);
}
@Test
void whenBuildingGetStateRequestWithoutRegistrationThenNoExceptionIsThrown() {
// When Building GetStateRequest Without Registration
final Builder<?, ?> builder = GetStateRequest.builder()
.activityId("https://example.com/activity/1")
.agent(a -> a.name("A N Other").mbox("mailto:another@example.com"))
.stateId("bookmark");
// Then No Exception Is Thrown
assertDoesNotThrow(builder::build);
}
@Test
void whenBuildingGetStateRequestWithoutActivityIdThenNullPointerExceptionIsThrown() {
// When Building GetStateRequest Without activityId
final Builder<?, ?> builder = GetStateRequest.builder()
.agent(a -> a.name("A N Other").mbox("mailto:another@example.com"))
.stateId("bookmark");
// Then Null Pointer Exception Is Thrown
assertThrows(NullPointerException.class, builder::build);
}
@Test
void whenBuildingGetStateRequestWithoutAgentThenNullPointerExceptionIsThrown() {
// When Building GetStateRequest Without Agent
final Builder<?, ?> builder = GetStateRequest.builder()
.activityId("https://example.com/activity/1")
.stateId("bookmark");
// Then Null Pointer Exception Is Thrown
assertThrows(NullPointerException.class, builder::build);
}
@Test
void whenBuildingGetStateRequestWithoutStateIdThenNullPointerExceptionIsThrown() {
// When Building GetStateRequest Without StateId
final Builder<?, ?> builder = GetStateRequest.builder()
.activityId("https://example.com/activity/1")
.agent(a -> a.name("A N Other").mbox("mailto:another@example.com"));
// Then Null Pointer Exception Is Thrown
assertThrows(NullPointerException.class, builder::build);
}
@Test
void givenGetStateRequestWithAllParametersWhenGettingURLThenResultIsExpected() {
// Given GetStateRequest With All Parameters
final GetStateRequest request = GetStateRequest.builder()
.activityId("https://example.com/activity/1")
.agent(a -> a.name("A N Other").mbox("mailto:another@example.com"))
.registration("67828e3a-d116-4e18-8af3-2d2c59e27be6")
.stateId("bookmark")
.build();
final Map<String, Object> queryParams = new HashMap<>();
// When Getting URL
final var result =
request.url(UriComponentsBuilder.fromUriString("https://example.com/xapi/"), queryParams)
.build(queryParams);
// Then Result Is Expected
assertThat(result, is(URI.create(
"https://example.com/xapi/activities/state?activityId=https%3A%2F%2Fexample.com%2Factivity%2F1&agent=%7B%22name%22%3A%22A%20N%20Other%22%2C%22mbox%22%3A%22mailto%3Aanother%40example.com%22%7D®istration=67828e3a-d116-4e18-8af3-2d2c59e27be6&stateId=bookmark")));
}
@Test
void givenGetStateRequestWithoutRegistrationWhenGettingURLThenResultIsExpected() {
// Given GetStateRequest Without Registration
final GetStateRequest request = GetStateRequest.builder()
.activityId("https://example.com/activity/1")
.agent(a -> a.name("A N Other").mbox("mailto:another@example.com"))
.stateId("bookmark")
.build();
final Map<String, Object> queryParams = new HashMap<>();
// When Getting URL
final var result =
request.url(UriComponentsBuilder.fromUriString("https://example.com/xapi/"), queryParams)
.build(queryParams);
// Then Result Is Expected
assertThat(result, is(URI.create(
"https://example.com/xapi/activities/state?activityId=https%3A%2F%2Fexample.com%2Factivity%2F1&agent=%7B%22name%22%3A%22A%20N%20Other%22%2C%22mbox%22%3A%22mailto%3Aanother%40example.com%22%7D&stateId=bookmark")));
}
}