Skip to content

Commit

Permalink
spotless:apply
Browse files Browse the repository at this point in the history
  • Loading branch information
mwangggg committed Oct 11, 2023
1 parent 17d2460 commit e8beed5
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,7 @@ void shouldThrow404IfNoMatchingRecordingFound() throws Exception {

when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn(subdirectoryName);
when(params.getPathParams())
.thenReturn(
Map.of(
"jvmId",
jvmId,
"recordingName",
recordingName));
.thenReturn(Map.of("jvmId", jvmId, "recordingName", recordingName));

Future<ArchivedRecordingInfo> future =
CompletableFuture.failedFuture(
Expand All @@ -151,12 +146,7 @@ void shouldHandleSuccessfulDELETERequest() throws Exception {

when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn(subdirectoryName);
when(params.getPathParams())
.thenReturn(
Map.of(
"recordingName",
recordingName,
"jvmId",
jvmId));
.thenReturn(Map.of("recordingName", recordingName, "jvmId", jvmId));

CompletableFuture<ArchivedRecordingInfo> future = Mockito.mock(CompletableFuture.class);
when(recordingArchiveHelper.deleteRecordingFromPath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ class RecordingGetFromPathWithJwtHandlerTest {
void setup() {
this.handler =
new RecordingGetFromPathWithJwtHandler(
auth, credentialsManager, jwt, () -> webServer, jvmIdHelper, archive, logger);
auth,
credentialsManager,
jwt,
() -> webServer,
jvmIdHelper,
archive,
logger);
}

@Nested
Expand All @@ -87,8 +93,7 @@ void shouldUseHttpGetVerb() {
void shouldUseExpectedPath() {
MatcherAssert.assertThat(
handler.path(),
Matchers.equalTo(
"/api/beta/fs/recordings/:jvmId/:recordingName/jwt"));
Matchers.equalTo("/api/beta/fs/recordings/:jvmId/:recordingName/jwt"));
}

@Test
Expand Down Expand Up @@ -119,7 +124,8 @@ class Behaviour {
void shouldRespond404IfNotFound() throws Exception {
when(ctx.pathParam("jvmId")).thenReturn("id");
when(ctx.pathParam("recordingName")).thenReturn("myrecording");
when(jvmIdHelper.jvmIdToSubdirectoryName(Mockito.anyString())).thenReturn("mysubdirectory");
when(jvmIdHelper.jvmIdToSubdirectoryName(Mockito.anyString()))
.thenReturn("mysubdirectory");
Future<Path> future =
CompletableFuture.failedFuture(
new RecordingNotFoundException("mysubdirectory", "myrecording"));
Expand All @@ -137,7 +143,8 @@ void shouldSendFileIfFound() throws Exception {
when(ctx.response()).thenReturn(resp);
when(ctx.pathParam("jvmId")).thenReturn("id");
when(ctx.pathParam("recordingName")).thenReturn("myrecording");
when(jvmIdHelper.jvmIdToSubdirectoryName(Mockito.anyString())).thenReturn("mysubdirectory");
when(jvmIdHelper.jvmIdToSubdirectoryName(Mockito.anyString()))
.thenReturn("mysubdirectory");
Path path = Mockito.mock(Path.class);
when(path.toAbsolutePath()).thenReturn(path);
when(path.toString()).thenReturn("foo.jfr");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void shouldUpdateLabels() throws Exception {
String requestLabels = labels.toString();
String subdirectoryName = "someSubdirectory";
Map<String, String> params = Mockito.mock(Map.class);

when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn(subdirectoryName);
when(requestParameters.getPathParams()).thenReturn(params);
when(params.get("recordingName")).thenReturn(recordingName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,14 @@ class RecordingUploadPostFromPathHandlerTest {
void setup() {
this.handler =
new RecordingUploadPostFromPathHandler(
auth, credentialsManager, env, 30, webClient, jvmIdHelper, recordingArchiveHelper, gson);
auth,
credentialsManager,
env,
30,
webClient,
jvmIdHelper,
recordingArchiveHelper,
gson);
}

@Nested
Expand Down Expand Up @@ -117,8 +124,7 @@ void shouldHaveExpectedRequiredPermissions() {
void shouldHandleCorrectPath() {
MatcherAssert.assertThat(
handler.path(),
Matchers.equalTo(
"/api/beta/fs/recordings/:jvmId/:recordingName/upload"));
Matchers.equalTo("/api/beta/fs/recordings/:jvmId/:recordingName/upload"));
}

@Test
Expand Down Expand Up @@ -160,12 +166,7 @@ void shouldThrow501IfDatasourceUrlMalformed(String rawUrl) {
void shouldThrowExceptionIfRecordingNotFound() throws Exception {
when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn(subdirectoryName);
when(params.getPathParams())
.thenReturn(
Map.of(
"jvmId",
jvmId,
"recordingName",
recordingName));
.thenReturn(Map.of("jvmId", jvmId, "recordingName", recordingName));
when(env.getEnv("GRAFANA_DATASOURCE_URL")).thenReturn(DATASOURCE_URL);

CompletableFuture<Path> future = Mockito.mock(CompletableFuture.class);
Expand All @@ -174,8 +175,7 @@ void shouldThrowExceptionIfRecordingNotFound() throws Exception {
.thenReturn(future);
ExecutionException e = Mockito.mock(ExecutionException.class);
when(future.get()).thenThrow(e);
when(e.getCause())
.thenReturn(new RecordingNotFoundException("foo", recordingName));
when(e.getCause()).thenReturn(new RecordingNotFoundException("foo", recordingName));

ApiException ex =
Assertions.assertThrows(ApiException.class, () -> handler.handle(params));
Expand All @@ -186,12 +186,7 @@ void shouldThrowExceptionIfRecordingNotFound() throws Exception {
void shouldDoUpload() throws Exception {
when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn("foo");
when(params.getPathParams())
.thenReturn(
Map.of(
"jvmId",
jvmId,
"recordingName",
recordingName));
.thenReturn(Map.of("jvmId", jvmId, "recordingName", recordingName));
when(env.getEnv("GRAFANA_DATASOURCE_URL")).thenReturn(DATASOURCE_URL);

CompletableFuture<Path> future = Mockito.mock(CompletableFuture.class);
Expand Down Expand Up @@ -241,12 +236,7 @@ public Void answer(InvocationOnMock args) throws Throwable {
void shouldHandleInvalidResponseStatusCode() throws Exception {
when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn("someSubdirectory");
when(params.getPathParams())
.thenReturn(
Map.of(
"jvmId",
jvmId,
"recordingName",
recordingName));
.thenReturn(Map.of("jvmId", jvmId, "recordingName", recordingName));
when(env.getEnv("GRAFANA_DATASOURCE_URL")).thenReturn(DATASOURCE_URL);

CompletableFuture<Path> future = Mockito.mock(CompletableFuture.class);
Expand Down Expand Up @@ -303,12 +293,7 @@ public Void answer(InvocationOnMock args) throws Throwable {
void shouldHandleNullStatusMessage() throws Exception {
when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn("someSubdirectory");
when(params.getPathParams())
.thenReturn(
Map.of(
"jvmId",
jvmId,
"recordingName",
recordingName));
.thenReturn(Map.of("jvmId", jvmId, "recordingName", recordingName));
when(env.getEnv("GRAFANA_DATASOURCE_URL")).thenReturn(DATASOURCE_URL);

CompletableFuture<Path> future = Mockito.mock(CompletableFuture.class);
Expand Down Expand Up @@ -365,12 +350,7 @@ public Void answer(InvocationOnMock args) throws Throwable {
void shouldHandleNullResponseBody() throws Exception {
when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn("someSubdirectory");
when(params.getPathParams())
.thenReturn(
Map.of(
"jvmId",
jvmId,
"recordingName",
recordingName));
.thenReturn(Map.of("jvmId", jvmId, "recordingName", recordingName));
when(env.getEnv("GRAFANA_DATASOURCE_URL")).thenReturn(DATASOURCE_URL);

CompletableFuture<Path> future = Mockito.mock(CompletableFuture.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ void shouldHaveExpectedRequiredPermissions() {
@Test
void shouldHandleCorrectPath() {
MatcherAssert.assertThat(
handler.path(),
Matchers.equalTo("/api/beta/fs/reports/:jvmId/:recordingName"));
handler.path(), Matchers.equalTo("/api/beta/fs/reports/:jvmId/:recordingName"));
}

@Test
Expand All @@ -129,12 +128,7 @@ void shouldThrow404IfNoMatchingRecordingFound() throws Exception {
MultiMap queryParams = MultiMap.caseInsensitiveMultiMap();
when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn(subdirectoryName);
when(params.getPathParams())
.thenReturn(
Map.of(
"jvmId",
jvmId,
"recordingName",
recordingName));
.thenReturn(Map.of("jvmId", jvmId, "recordingName", recordingName));
when(params.getQueryParams()).thenReturn(queryParams);

Future<Path> future =
Expand All @@ -156,12 +150,7 @@ void shouldRespondBySendingFile() throws Exception {
MultiMap queryParams = MultiMap.caseInsensitiveMultiMap();
when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn(subdirectoryName);
when(params.getPathParams())
.thenReturn(
Map.of(
"jvmId",
jvmId,
"recordingName",
recordingName));
.thenReturn(Map.of("jvmId", jvmId, "recordingName", recordingName));
when(params.getQueryParams()).thenReturn(queryParams);

Path fakePath = Mockito.mock(Path.class);
Expand All @@ -185,12 +174,7 @@ void shouldRespondBySendingFileFiltered() throws Exception {

when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn(subdirectoryName);
when(params.getPathParams())
.thenReturn(
Map.of(
"jvmId",
jvmId,
"recordingName",
recordingName));
.thenReturn(Map.of("jvmId", jvmId, "recordingName", recordingName));
when(params.getQueryParams()).thenReturn(queryParams);

Path fakePath = Mockito.mock(Path.class);
Expand All @@ -211,15 +195,10 @@ void shouldRespondBySendingFileFiltered() throws Exception {
void shouldRespondBySendingFileUnformatted() throws Exception {
MultiMap queryParams = MultiMap.caseInsensitiveMultiMap();
queryParams.add("filter", "someFilter");

when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn(subdirectoryName);
when(params.getPathParams())
.thenReturn(
Map.of(
"jvmId",
jvmId,
"recordingName",
recordingName));
.thenReturn(Map.of("jvmId", jvmId, "recordingName", recordingName));
when(params.getQueryParams()).thenReturn(queryParams);

Path fakePath = Mockito.mock(Path.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ class Behaviour {
void shouldRespond404IfNotFound() throws Exception {
when(ctx.pathParam("jvmId")).thenReturn("id");
when(ctx.pathParam("recordingName")).thenReturn("myrecording");
when(jvmIdHelper.jvmIdToSubdirectoryName(Mockito.anyString())).thenReturn("mydirectory");
when(jvmIdHelper.jvmIdToSubdirectoryName(Mockito.anyString()))
.thenReturn("mydirectory");

Future<Path> future =
CompletableFuture.failedFuture(
Expand All @@ -161,7 +162,8 @@ void shouldSendFileIfFound() throws Exception {
when(ctx.response()).thenReturn(resp);
when(ctx.pathParam("jvmId")).thenReturn("id");
when(ctx.pathParam("recordingName")).thenReturn("myrecording");
when(jvmIdHelper.jvmIdToSubdirectoryName(Mockito.anyString())).thenReturn("mydirectory");
when(jvmIdHelper.jvmIdToSubdirectoryName(Mockito.anyString()))
.thenReturn("mydirectory");
Path path = Mockito.mock(Path.class);
when(path.toAbsolutePath()).thenReturn(path);
when(path.toString()).thenReturn("foo.jfr");
Expand All @@ -184,7 +186,8 @@ void shouldSendFileIfFoundFiltered() throws Exception {
when(ctx.response()).thenReturn(resp);
when(ctx.pathParam("jvmId")).thenReturn("id");
when(ctx.pathParam("recordingName")).thenReturn("myrecording");
when(jvmIdHelper.jvmIdToSubdirectoryName(Mockito.anyString())).thenReturn("mydirectory");
when(jvmIdHelper.jvmIdToSubdirectoryName(Mockito.anyString()))
.thenReturn("mydirectory");
Path path = Mockito.mock(Path.class);
when(path.toAbsolutePath()).thenReturn(path);
when(path.toString()).thenReturn("foo.jfr");
Expand All @@ -208,7 +211,8 @@ void shouldSendFileIfFoundUnformatted() throws Exception {
when(ctx.response()).thenReturn(resp);
when(ctx.pathParam("jvmId")).thenReturn("id");
when(ctx.pathParam("recordingName")).thenReturn("myrecording");
when(jvmIdHelper.jvmIdToSubdirectoryName(Mockito.anyString())).thenReturn("mydirectory");
when(jvmIdHelper.jvmIdToSubdirectoryName(Mockito.anyString()))
.thenReturn("mydirectory");
Path path = Mockito.mock(Path.class);
when(path.toAbsolutePath()).thenReturn(path);
when(path.toString()).thenReturn("foo.jfr");
Expand Down

0 comments on commit e8beed5

Please sign in to comment.