Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand All @@ -27,7 +28,7 @@ class DeleteStateRequestTests {
void whenBuildingDeleteStateRequestWithAllParametersThenNoExceptionIsThrown() {

// When Building DeleteStateRequest With All Parameters
Builder<?, ?> builder = DeleteStateRequest.builder()
final Builder<?, ?> builder = DeleteStateRequest.builder()

.activityId("https://example.com/activity/1")

Expand All @@ -46,7 +47,7 @@ void whenBuildingDeleteStateRequestWithAllParametersThenNoExceptionIsThrown() {
void whenBuildingDeleteStateRequestWithoutRegistrationThenNoExceptionIsThrown() {

// When Building DeleteStateRequest Without Registration
Builder<?, ?> builder = DeleteStateRequest.builder()
final Builder<?, ?> builder = DeleteStateRequest.builder()

.activityId("https://example.com/activity/1")

Expand All @@ -63,7 +64,7 @@ void whenBuildingDeleteStateRequestWithoutRegistrationThenNoExceptionIsThrown()
void whenBuildingDeleteStateRequestWithoutActivityIdThenExceptionIsThrown() {

// When Building DeleteStateRequest Without ActivityId
Builder<?, ?> builder = DeleteStateRequest.builder()
final Builder<?, ?> builder = DeleteStateRequest.builder()

.agent(a -> a.name("A N Other").mbox("another@example.com"))

Expand All @@ -80,7 +81,7 @@ void whenBuildingDeleteStateRequestWithoutActivityIdThenExceptionIsThrown() {
void whenBuildingDeleteStateRequestWithoutAgentThenExceptionIsThrown() {

// When Building DeleteStateRequest Without Agent
Builder<?, ?> builder = DeleteStateRequest.builder()
final Builder<?, ?> builder = DeleteStateRequest.builder()

.activityId("https://example.com/activity/1")

Expand All @@ -97,7 +98,7 @@ void whenBuildingDeleteStateRequestWithoutAgentThenExceptionIsThrown() {
void whenBuildingDeleteStateRequestWithoutStateIdThenExceptionIsThrown() {

// When Building DeleteStateRequest Without StateId
Builder<?, ?> builder = DeleteStateRequest.builder()
final Builder<?, ?> builder = DeleteStateRequest.builder()

.activityId("https://example.com/activity/1")

Expand All @@ -114,7 +115,7 @@ void whenBuildingDeleteStateRequestWithoutStateIdThenExceptionIsThrown() {
void givenDeleteStateRequestWithAllParametersWhenGettingURLThenResultIsExpected() {

// Given DeleteStateRequest With All Parameters
DeleteStateRequest request = DeleteStateRequest.builder()
final DeleteStateRequest request = DeleteStateRequest.builder()

.activityId("https://example.com/activity/1")

Expand All @@ -126,24 +127,24 @@ void givenDeleteStateRequestWithAllParametersWhenGettingURLThenResultIsExpected(

.build();

Map<String, Object> queryParams = new HashMap<>();
final Map<String, Object> queryParams = new HashMap<>();

// When Getting URL
URI result =
request.url(UriComponentsBuilder.fromUriString("https://example.com/xapi/"), queryParams)
.build(queryParams);
final URI 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&registration=67828e3a-d116-4e18-8af3-2d2c59e27be6&stateId=bookmark")));
"https://example.com/xapi/activities/state?activityId=https%3A%2F%2Fexample.com%2Factivity%2F1&agent=%7B%22objectType%22%3A%22Agent%22%2C%22name%22%3A%22A%20N%20Other%22%2C%22mbox%22%3A%22another%40example.com%22%7D&registration=67828e3a-d116-4e18-8af3-2d2c59e27be6&stateId=bookmark")));

}

@Test
void givenDeleteStateRequestWithoutRegistrationWhenGettingURLThenResultIsExpected() {

// Given DeleteStateRequest Without Registration
DeleteStateRequest request = DeleteStateRequest.builder()
final DeleteStateRequest request = DeleteStateRequest.builder()

.activityId("https://example.com/activity/1")

Expand All @@ -153,16 +154,16 @@ void givenDeleteStateRequestWithoutRegistrationWhenGettingURLThenResultIsExpecte

.build();

Map<String, Object> queryParams = new HashMap<>();
final Map<String, Object> queryParams = new HashMap<>();

// When Getting URL
URI result =
request.url(UriComponentsBuilder.fromUriString("https://example.com/xapi/"), queryParams)
.build(queryParams);
final URI 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")));
"https://example.com/xapi/activities/state?activityId=https%3A%2F%2Fexample.com%2Factivity%2F1&agent=%7B%22objectType%22%3A%22Agent%22%2C%22name%22%3A%22A%20N%20Other%22%2C%22mbox%22%3A%22another%40example.com%22%7D&stateId=bookmark")));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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.DeleteStatesRequest.Builder;
import java.net.URI;
import java.util.HashMap;
Expand All @@ -28,7 +29,7 @@ class DeleteStatesRequestTests {
void whenBuildingDeleteStatesRequestWithAllParametersThenNoExceptionIsThrown() {

// When Building DeleteStatesRequest With All Parameters
Builder<?, ?> builder = DeleteStatesRequest.builder()
final Builder<?, ?> builder = DeleteStatesRequest.builder()

.activityId("https://example.com/activity/1")

Expand All @@ -45,7 +46,7 @@ void whenBuildingDeleteStatesRequestWithAllParametersThenNoExceptionIsThrown() {
void whenBuildingDeleteStatesRequestWithRegistrationAsUUIDTypeThenNoExceptionIsThrown() {

// When Building Delete States Request With Registration As UUID Type
Builder<?, ?> builder = DeleteStatesRequest.builder()
final Builder<?, ?> builder = DeleteStatesRequest.builder()

.activityId("https://example.com/activity/1")

Expand All @@ -62,13 +63,13 @@ void whenBuildingDeleteStatesRequestWithRegistrationAsUUIDTypeThenNoExceptionIsT
void whenBuildingDeleteStatesRequestWithActivityIdAsURITypeThenNoExceptionIsThrown() {

// When Building Delete States Request With ActivityId As URI Type
Builder<?, ?> builder = DeleteStatesRequest.builder()
final Builder<?, ?> builder = DeleteStatesRequest.builder()

.activityId(URI.create("https://example.com/activity/1"))

.agent(a -> a.name("A N Other").mbox("mailto:another@example.com"))

.registration(("67828e3a-d116-4e18-8af3-2d2c59e27be6"));
.registration("67828e3a-d116-4e18-8af3-2d2c59e27be6");

// Then No Exception Is Thrown
assertDoesNotThrow(() -> builder.build());
Expand All @@ -79,7 +80,7 @@ void whenBuildingDeleteStatesRequestWithActivityIdAsURITypeThenNoExceptionIsThro
void whenBuildingDeleteStatesRequestWithoutRegistrationThenNoExceptionIsThrown() {

// When Building DeleteStatesRequest Without Registration
Builder<?, ?> builder = DeleteStatesRequest.builder()
final Builder<?, ?> builder = DeleteStatesRequest.builder()

.activityId("https://example.com/activity/1")

Expand All @@ -94,7 +95,7 @@ void whenBuildingDeleteStatesRequestWithoutRegistrationThenNoExceptionIsThrown()
void whenBuildingDeleteStatesRequestWithoutActivityIdThenExceptionIsThrown() {

// When Building DeleteStatesRequest Without ActivityId
Builder<?, ?> builder = DeleteStatesRequest.builder()
final Builder<?, ?> builder = DeleteStatesRequest.builder()

.agent(a -> a.name("A N Other").mbox("mailto:another@example.com"))

Expand All @@ -109,7 +110,7 @@ void whenBuildingDeleteStatesRequestWithoutActivityIdThenExceptionIsThrown() {
void whenBuildingDeleteStatesRequestWithoutAgentThenExceptionIsThrown() {

// When Building DeleteStatesRequest Without Agent
Builder<?, ?> builder = DeleteStatesRequest.builder()
final Builder<?, ?> builder = DeleteStatesRequest.builder()

.activityId("https://example.com/activity/1")

Expand All @@ -124,7 +125,7 @@ void whenBuildingDeleteStatesRequestWithoutAgentThenExceptionIsThrown() {
void givenDeleteStatesRequestWithAllParametersWhenGettingURLThenResultIsExpected() {

// Given DeleteStatesRequest With All Parameters
DeleteStatesRequest request = DeleteStatesRequest.builder()
final DeleteStatesRequest request = DeleteStatesRequest.builder()

.activityId("https://example.com/activity/1")

Expand All @@ -134,42 +135,41 @@ void givenDeleteStatesRequestWithAllParametersWhenGettingURLThenResultIsExpected

.build();

Map<String, Object> queryParams = new HashMap<>();
final Map<String, Object> queryParams = new HashMap<>();

// When Getting URL
URI url =
request.url(UriComponentsBuilder.fromUriString("https://example.com/xapi/"), queryParams)
.build(queryParams);
final URI url = request
.url(UriComponentsBuilder.fromUriString("https://example.com/xapi/"), queryParams)
.build(queryParams);

// Then Result Is Expected
assertThat(url, 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&registration=67828e3a-d116-4e18-8af3-2d2c59e27be6")));
"https://example.com/xapi/activities/state?activityId=https%3A%2F%2Fexample.com%2Factivity%2F1&agent=%7B%22objectType%22%3A%22Agent%22%2C%22name%22%3A%22A%20N%20Other%22%2C%22mbox%22%3A%22mailto%3Aanother%40example.com%22%7D&registration=67828e3a-d116-4e18-8af3-2d2c59e27be6")));

}


@Test
void givenDeleteStatesRequestWithoutRegistrationWhenGettingURLThenResultIsExpected() {

// Given DeleteStatesRequest Without Registration
DeleteStatesRequest request = DeleteStatesRequest.builder()
final DeleteStatesRequest request = DeleteStatesRequest.builder()

.activityId("https://example.com/activity/1")

.agent(a -> a.name("A N Other").mbox("mailto:another@example.com"))

.build();

Map<String, Object> queryParams = new HashMap<>();
final Map<String, Object> queryParams = new HashMap<>();

// When Getting URL
URI url =
request.url(UriComponentsBuilder.fromUriString("https://example.com/xapi/"), queryParams)
.build(queryParams);
final URI url = request
.url(UriComponentsBuilder.fromUriString("https://example.com/xapi/"), queryParams)
.build(queryParams);

// Then Result Is Expected
assertThat(url, 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")));
"https://example.com/xapi/activities/state?activityId=https%3A%2F%2Fexample.com%2Factivity%2F1&agent=%7B%22objectType%22%3A%22Agent%22%2C%22name%22%3A%22A%20N%20Other%22%2C%22mbox%22%3A%22mailto%3Aanother%40example.com%22%7D")));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand All @@ -27,7 +28,7 @@ class GetStateRequestTests {
void whenBuildingGetStateRequestWithAllParametersThenNoExceptionIsThrown() {

// When Building GetStateRequest With All Parameters
Builder<?, ?> builder = GetStateRequest.builder()
final Builder<?, ?> builder = GetStateRequest.builder()

.activityId("https://example.com/activity/1")

Expand All @@ -46,7 +47,7 @@ void whenBuildingGetStateRequestWithAllParametersThenNoExceptionIsThrown() {
void whenBuildingGetStateRequestWithoutRegistrationThenNoExceptionIsThrown() {

// When Building GetStateRequest Without Registration
Builder<?, ?> builder = GetStateRequest.builder()
final Builder<?, ?> builder = GetStateRequest.builder()

.activityId("https://example.com/activity/1")

Expand All @@ -63,7 +64,7 @@ void whenBuildingGetStateRequestWithoutRegistrationThenNoExceptionIsThrown() {
void whenBuildingGetStateRequestWithoutActivityIdThenNullPointerExceptionIsThrown() {

// When Building GetStateRequest Without activityId
Builder<?, ?> builder = GetStateRequest.builder()
final Builder<?, ?> builder = GetStateRequest.builder()

.agent(a -> a.name("A N Other").mbox("mailto:another@example.com"))

Expand All @@ -78,7 +79,7 @@ void whenBuildingGetStateRequestWithoutActivityIdThenNullPointerExceptionIsThrow
void whenBuildingGetStateRequestWithoutAgentThenNullPointerExceptionIsThrown() {

// When Building GetStateRequest Without Agent
Builder<?, ?> builder = GetStateRequest.builder()
final Builder<?, ?> builder = GetStateRequest.builder()

.activityId("https://example.com/activity/1")

Expand All @@ -93,7 +94,7 @@ void whenBuildingGetStateRequestWithoutAgentThenNullPointerExceptionIsThrown() {
void whenBuildingGetStateRequestWithoutStateIdThenNullPointerExceptionIsThrown() {

// When Building GetStateRequest Without StateId
Builder<?, ?> builder = GetStateRequest.builder()
final Builder<?, ?> builder = GetStateRequest.builder()

.activityId("https://example.com/activity/1")

Expand All @@ -108,7 +109,7 @@ void whenBuildingGetStateRequestWithoutStateIdThenNullPointerExceptionIsThrown()
void givenGetStateRequestWithAllParametersWhenGettingURLThenResultIsExpected() {

// Given GetStateRequest With All Parameters
GetStateRequest request = GetStateRequest.builder()
final GetStateRequest request = GetStateRequest.builder()

.activityId("https://example.com/activity/1")

Expand All @@ -120,24 +121,24 @@ void givenGetStateRequestWithAllParametersWhenGettingURLThenResultIsExpected() {

.build();

Map<String, Object> queryParams = new HashMap<>();
final Map<String, Object> queryParams = new HashMap<>();

// When Getting URL
URI result =
request.url(UriComponentsBuilder.fromUriString("https://example.com/xapi/"), queryParams)
.build(queryParams);
final URI 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&registration=67828e3a-d116-4e18-8af3-2d2c59e27be6&stateId=bookmark")));
"https://example.com/xapi/activities/state?activityId=https%3A%2F%2Fexample.com%2Factivity%2F1&agent=%7B%22objectType%22%3A%22Agent%22%2C%22name%22%3A%22A%20N%20Other%22%2C%22mbox%22%3A%22mailto%3Aanother%40example.com%22%7D&registration=67828e3a-d116-4e18-8af3-2d2c59e27be6&stateId=bookmark")));

}

@Test
void givenGetStateRequestWithoutRegistrationWhenGettingURLThenResultIsExpected() {

// Given GetStateRequest Without Registration
GetStateRequest request = GetStateRequest.builder()
final GetStateRequest request = GetStateRequest.builder()

.activityId("https://example.com/activity/1")

Expand All @@ -147,16 +148,16 @@ void givenGetStateRequestWithoutRegistrationWhenGettingURLThenResultIsExpected()

.build();

Map<String, Object> queryParams = new HashMap<>();
final Map<String, Object> queryParams = new HashMap<>();

// When Getting URL
URI result =
request.url(UriComponentsBuilder.fromUriString("https://example.com/xapi/"), queryParams)
.build(queryParams);
final URI 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")));
"https://example.com/xapi/activities/state?activityId=https%3A%2F%2Fexample.com%2Factivity%2F1&agent=%7B%22objectType%22%3A%22Agent%22%2C%22name%22%3A%22A%20N%20Other%22%2C%22mbox%22%3A%22mailto%3Aanother%40example.com%22%7D&stateId=bookmark")));

}

Expand Down
Loading