Skip to content

Commit

Permalink
Fix previously hidden unit test failures (cryostatio#512)
Browse files Browse the repository at this point in the history
* Remove null test cases and change incorrect Matcher functionality

* Fix incorrect class mocking which causes tests to pass for the wrong reason

* Maintain consistency between tests by allowing use of the same recording name
  • Loading branch information
hareetd authored and andrewazores committed Jun 23, 2021
1 parent 00fde22 commit 32a7f3e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void handleAuthenticated(RoutingContext ctx) throws Exception {
MultiMap attrs = ctx.request().formAttributes();
if (attrs.contains("toDisk")) {
Matcher m = bool.matcher(attrs.get("toDisk"));
if (!m.find()) throw new HttpStatusException(400, "Invalid options");
if (!m.matches()) throw new HttpStatusException(400, "Invalid options");
}
Arrays.asList("maxAge", "maxSize")
.forEach(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void handleAuthenticated(RoutingContext ctx) throws Exception {
if (attrs.contains("toDisk")) {
Pattern bool = Pattern.compile("true|false");
Matcher m = bool.matcher(attrs.get("toDisk"));
if (!m.find())
if (!m.matches())
throw new HttpStatusException(400, "Invalid options");
builder = builder.toDisk(Boolean.valueOf(attrs.get("toDisk")));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,10 @@ void shouldThrowInvalidOptionException(Map<String, String> defaultValues) throws

private static Stream<Map<String, String>> getRequestMaps() {
return Stream.of(
Map.of("toDisk", null),
Map.of("toDisk", ""),
Map.of("toDisk", "5"),
Map.of("toDisk", "T"),
Map.of("toDisk", "false1"),
Map.of("maxAge", null),
Map.of("maxAge", ""),
Map.of("maxAge", "true"),
Map.of("maxAge", "1e3"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,15 @@ void shouldThrowInvalidOptionException(Map<String, String> requestValues) throws
arg0.getArgument(1))
.execute(connection));
Mockito.when(connection.getService()).thenReturn(service);
Mockito.when(service.getAvailableRecordings())
.thenReturn(Collections.emptyList())
.thenReturn(Arrays.asList(existingRecording));
RecordingOptionsBuilder recordingOptionsBuilder =
Mockito.mock(RecordingOptionsBuilder.class);
Mockito.when(recordingOptionsBuilderFactory.create(Mockito.any()))
.thenReturn(recordingOptionsBuilder);
Mockito.when(recordingOptionsBuilder.name(Mockito.any()))
.thenReturn(recordingOptionsBuilder);

Mockito.when(ctx.pathParam("targetId")).thenReturn("fooHost:9091");
MultiMap attrs = MultiMap.caseInsensitiveMultiMap();
Expand All @@ -317,16 +326,13 @@ void shouldThrowInvalidOptionException(Map<String, String> requestValues) throws

private static Stream<Map<String, String>> getRequestMaps() {
return Stream.of(
Map.of("duration", null),
Map.of("duration", ""),
Map.of("duration", "t"),
Map.of("duration", "90s"),
Map.of("toDisk", null),
Map.of("toDisk", ""),
Map.of("toDisk", "5"),
Map.of("toDisk", "T"),
Map.of("toDisk", "false1"),
Map.of("maxAge", null),
Map.of("maxAge", ""),
Map.of("maxAge", "true"),
Map.of("maxAge", "1e3"),
Expand Down

0 comments on commit 32a7f3e

Please sign in to comment.