Skip to content

Commit

Permalink
Add SET_OF_STRING_GENERIC_TYPE constant to KiwiGenericTypes (#759)
Browse files Browse the repository at this point in the history
Add a new constant to KiwiGenericTypes to support the somewhat common
Set<String> type. At least, it is common for us...
  • Loading branch information
sleberknight authored Aug 2, 2022
1 parent 75447c7 commit 1279624
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/kiwiproject/jaxrs/KiwiGenericTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javax.ws.rs.core.GenericType;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Utilities/constants for containing common, re-usable types of {@link GenericType} objects.
Expand Down Expand Up @@ -43,4 +44,8 @@ public class KiwiGenericTypes {
public static final GenericType<List<Boolean>> LIST_OF_BOOLEAN_GENERIC_TYPE =
new GenericType<>() {
};

public static final GenericType<Set<String>> SET_OF_STRING_GENERIC_TYPE =
new GenericType<>() {
};
}
18 changes: 18 additions & 0 deletions src/test/java/org/kiwiproject/jaxrs/KiwiGenericTypesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import javax.ws.rs.core.Response;
import java.util.List;
import java.util.Map;
import java.util.Set;

@DisplayName("KiwiGenericTypes")
@ExtendWith(DropwizardExtensionsSupport.class)
Expand Down Expand Up @@ -73,6 +74,13 @@ public Response getOnSale() {
var onSale = List.of(true, false, false);
return Response.ok(onSale).build();
}

@GET
@Path("/bodyTypes")
public Response getBodyTypes() {
var types = List.of("sedan", "sedan", "SUV");
return Response.ok(types).build();
}
}

private static final ResourceExtension RESOURCES = ResourceExtension.builder()
Expand Down Expand Up @@ -176,4 +184,14 @@ void shouldSupportListOfBooleans() {

assertThat(onSale).containsExactly(true, false, false);
}

@Test
void shouldSupportSetOfStrings() {
Set<String> models = RESOURCES.client()
.target("/genericTypes/bodyTypes")
.request()
.get(KiwiGenericTypes.SET_OF_STRING_GENERIC_TYPE);

assertThat(models).containsExactlyInAnyOrder("sedan", "SUV");
}
}

0 comments on commit 1279624

Please sign in to comment.