-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDeleteStateRequestTests.java
More file actions
170 lines (109 loc) · 5 KB
/
Copy pathDeleteStateRequestTests.java
File metadata and controls
170 lines (109 loc) · 5 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
165
166
167
168
169
170
/*
* 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.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
import dev.learning.xapi.client.DeleteStateRequest.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;
/**
* DeleteStateRequest Tests.
*
* @author Thomas Turrell-Croft
*/
@DisplayName("DeleteStateRequest Tests")
class DeleteStateRequestTests {
@Test
void whenBuildingDeleteStateRequestWithAllParametersThenNoExceptionIsThrown() {
// When Building DeleteStateRequest With All Parameters
final Builder<?, ?> builder = DeleteStateRequest.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 whenBuildingDeleteStateRequestWithoutRegistrationThenNoExceptionIsThrown() {
// When Building DeleteStateRequest Without Registration
final Builder<?, ?> builder = DeleteStateRequest.builder()
.activityId("https://example.com/activity/1")
.agent(a -> a.name("A N Other").mbox("another@example.com"))
.stateId("bookmark");
// Then No Exception Is Thrown
assertDoesNotThrow(builder::build);
}
@Test
void whenBuildingDeleteStateRequestWithoutActivityIdThenExceptionIsThrown() {
// When Building DeleteStateRequest Without ActivityId
final Builder<?, ?> builder = DeleteStateRequest.builder()
.agent(a -> a.name("A N Other").mbox("another@example.com"))
.registration("67828e3a-d116-4e18-8af3-2d2c59e27be6")
.stateId("bookmark");
// Then NullPointerException Is Thrown
assertThrows(NullPointerException.class, builder::build);
}
@Test
void whenBuildingDeleteStateRequestWithoutAgentThenExceptionIsThrown() {
// When Building DeleteStateRequest Without Agent
final Builder<?, ?> builder = DeleteStateRequest.builder()
.activityId("https://example.com/activity/1")
.registration("67828e3a-d116-4e18-8af3-2d2c59e27be6")
.stateId("bookmark");
// Then NullPointerException Is Thrown
assertThrows(NullPointerException.class, builder::build);
}
@Test
void whenBuildingDeleteStateRequestWithoutStateIdThenExceptionIsThrown() {
// When Building DeleteStateRequest Without StateId
final Builder<?, ?> builder = DeleteStateRequest.builder()
.activityId("https://example.com/activity/1")
.agent(a -> a.name("A N Other").mbox("another@example.com"))
.registration("67828e3a-d116-4e18-8af3-2d2c59e27be6");
// Then NullPointerException Is Thrown
assertThrows(NullPointerException.class, builder::build);
}
@Test
void givenDeleteStateRequestWithAllParametersWhenGettingURLThenResultIsExpected() {
// Given DeleteStateRequest With All Parameters
final DeleteStateRequest request = DeleteStateRequest.builder()
.activityId("https://example.com/activity/1")
.agent(a -> a.name("A N Other").mbox("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%22another%40example.com%22%7D®istration=67828e3a-d116-4e18-8af3-2d2c59e27be6&stateId=bookmark")));
}
@Test
void givenDeleteStateRequestWithoutRegistrationWhenGettingURLThenResultIsExpected() {
// Given DeleteStateRequest Without Registration
final DeleteStateRequest request = DeleteStateRequest.builder()
.activityId("https://example.com/activity/1")
.agent(a -> a.name("A N Other").mbox("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%22another%40example.com%22%7D&stateId=bookmark")));
}
}