Skip to content

Commit

Permalink
Fix warnings in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtSilvio committed Sep 9, 2024
1 parent 3628b76 commit e29d8f9
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public class SchemaCreateCommandTest {
private final @NotNull HiveMQRestService hiveMQRestService = mock();
private @NotNull OutputFormatter outputFormatter;
private final @NotNull ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
private final @NotNull JSON openapiSerialization = new JSON();
private final @NotNull DataHubSchemasApi schemasApi = mock();

private @NotNull CommandLine commandLine;
Expand Down Expand Up @@ -180,8 +179,7 @@ void execute_printVersionSet_versionPrinted() throws ApiException {
"\"schemaDefinition\":\"J3t9Jw==\"," +
"\"arguments\":{}" +
"}";
final HivemqOpenapiSchema createdSchema =
openapiSerialization.deserialize(apiSchemaResponseJson, HivemqOpenapiSchema.class);
final HivemqOpenapiSchema createdSchema = JSON.deserialize(apiSchemaResponseJson, HivemqOpenapiSchema.class);
when(schemasApi.createSchema(any())).thenReturn(createdSchema);

assertEquals(0, commandLine.execute("--id=s1", "--type=json", "--definition='{}'", "--print-version"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public class ScriptCreateCommandTest {
private final @NotNull HiveMQRestService hiveMQRestService = mock();
private @NotNull OutputFormatter outputFormatter;
private final @NotNull ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
private final @NotNull JSON openapiSerialization = new JSON();
private final @NotNull DataHubScriptsApi scriptsApi = mock(DataHubScriptsApi.class);

private @NotNull CommandLine commandLine;
Expand Down Expand Up @@ -134,8 +133,7 @@ void execute_printVersionSet_versionPrinted() throws ApiException {
"\"functionType\":\"TRANSFORMATION\"," +
"\"source\":\"J2NvbnNvbGUubG9nKCdIZWxsbywgV29ybGQhJyk7\"" +
"}";
final HivemqOpenapiScript createdScript =
openapiSerialization.deserialize(apiScriptResponseJson, HivemqOpenapiScript.class);
final HivemqOpenapiScript createdScript = JSON.deserialize(apiScriptResponseJson, HivemqOpenapiScript.class);
when(scriptsApi.createScript(any())).thenReturn(createdScript);

assertEquals(0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
import com.hivemq.cli.commands.swarm.error.SwarmApiErrorTransformer;
import com.hivemq.cli.openapi.ApiClient;
import com.hivemq.cli.openapi.ApiException;
import com.hivemq.cli.openapi.swarm.*;
import com.hivemq.cli.openapi.swarm.RunResponse;
import com.hivemq.cli.openapi.swarm.RunsApi;
import com.hivemq.cli.openapi.swarm.ScenariosApi;
import com.hivemq.cli.openapi.swarm.StartRunRequest;
import com.hivemq.cli.openapi.swarm.StartRunResponse;
import com.hivemq.cli.openapi.swarm.UploadScenarioRequest;
import com.hivemq.cli.openapi.swarm.UploadScenarioResponse;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -29,13 +35,18 @@

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

class SwarmRunStartCommandTest {

Expand Down Expand Up @@ -120,7 +131,7 @@ void scenarioNotExist_error() {
@Test
void uploadScenario_xml_error(final @TempDir @NotNull Path tempDir) throws IOException, ApiException {
final Path scenario = tempDir.resolve("scenario.xml");
Files.write(scenario, "scenario-content".getBytes(StandardCharsets.UTF_8));
Files.writeString(scenario, "scenario-content");

final SwarmRunStartCommand command = new SwarmRunStartCommand("http://localhost:8080",
scenario.toFile(),
Expand Down Expand Up @@ -152,7 +163,7 @@ void uploadScenario_xml_error(final @TempDir @NotNull Path tempDir) throws IOExc
@Test
void uploadScenario_vm_error(final @TempDir @NotNull Path tempDir) throws IOException, ApiException {
final Path scenario = tempDir.resolve("scenario.vm");
Files.write(scenario, "scenario-content".getBytes(StandardCharsets.UTF_8));
Files.writeString(scenario, "scenario-content");

final SwarmRunStartCommand command = new SwarmRunStartCommand("http://localhost:8080",
scenario.toFile(),
Expand Down Expand Up @@ -185,7 +196,7 @@ void uploadScenario_vm_error(final @TempDir @NotNull Path tempDir) throws IOExce
void uploadScenarioSuccessButCantStart_error(final @TempDir @NotNull Path tempDir)
throws IOException, ApiException {
final Path scenario = tempDir.resolve("scenario.vm");
Files.write(scenario, "scenario-content".getBytes(StandardCharsets.UTF_8));
Files.writeString(scenario, "scenario-content");

final SwarmRunStartCommand command = new SwarmRunStartCommand("http://localhost:8080",
scenario.toFile(),
Expand Down Expand Up @@ -214,7 +225,7 @@ void uploadScenarioSuccessButCantStart_error(final @TempDir @NotNull Path tempDi
@Test
void runScenarioAttached(final @TempDir @NotNull Path tempDir) throws IOException, ApiException {
final Path scenario = tempDir.resolve("scenario.vm");
Files.write(scenario, "scenario-content".getBytes(StandardCharsets.UTF_8));
Files.writeString(scenario, "scenario-content");

final SwarmRunStartCommand command = new SwarmRunStartCommand("http://localhost:8080",
scenario.toFile(),
Expand Down Expand Up @@ -251,7 +262,7 @@ void runScenarioAttached(final @TempDir @NotNull Path tempDir) throws IOExceptio
@Test
void runScenarioDetached(final @TempDir @NotNull Path tempDir) throws IOException, ApiException {
final Path scenario = tempDir.resolve("scenario.vm");
Files.write(scenario, "scenario-content".getBytes(StandardCharsets.UTF_8));
Files.writeString(scenario, "scenario-content");

final SwarmRunStartCommand command = new SwarmRunStartCommand("http://localhost:8080",
scenario.toFile(),
Expand Down Expand Up @@ -284,4 +295,4 @@ void runScenarioDetached(final @TempDir @NotNull Path tempDir) throws IOExceptio

assertEquals("42", captor.getValue().getScenarioId());
}
}
}
12 changes: 0 additions & 12 deletions src/test/java/com/hivemq/cli/rest/hivemq/TestResponseBodies.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,4 @@ public class TestResponseBodies {
" }\n" +
"}";
//@formatter:on

public static final @NotNull String CLIENT_DETAILS_NOT_FOUND =
//@formatter:off
"{\n" +
" \"errors\": [\n" +
" {\n" +
" \"title\": \"Requested resource not found\",\n" +
" \"detail\": \"Client with id 'client-1' not found\"\n" +
" }\n" +
" ]\n" +
"}";
//@formatter:on
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class DataPolicySerializerTest {
.registerTypeAdapter(OffsetDateTime.class, new OffsetDateTimeSerializer())
.registerTypeAdapter(HivemqOpenapiDataPolicy.class, new DataPolicySerializer())
.create();
private final @NotNull JSON openapiSerialization = new JSON();

@Test
void serialize_allFields_jsonIdentical() {
Expand All @@ -43,8 +42,7 @@ void serialize_allFields_jsonIdentical() {
"\"onSuccess\":{\"pipeline\":[{\"id\":\"success\",\"functionId\":\"successFunction\",\"arguments\":{\"argB\":\"valB\",\"argA\":\"valA\"}}]}," +
"\"onFailure\":{\"pipeline\":[{\"id\":\"failure\",\"functionId\":\"failureFunction\",\"arguments\":{\"argA\":\"valA\",\"argB\":\"valB\"}}]}}";

final HivemqOpenapiDataPolicy policy =
openapiSerialization.deserialize(dataPolicyJson, HivemqOpenapiDataPolicy.class);
final HivemqOpenapiDataPolicy policy = JSON.deserialize(dataPolicyJson, HivemqOpenapiDataPolicy.class);
final String serialized = gson.toJson(policy);
assertEquals(dataPolicyJson, serialized);
}
Expand All @@ -55,8 +53,7 @@ void serialize_minimalFields_jsonIdentical() {
"\"createdAt\":\"2023-01-01T01:02:03.004Z\"," +
"\"matching\":{\"topicFilter\":\"filter\"}}";

final HivemqOpenapiDataPolicy policy =
openapiSerialization.deserialize(policyJson, HivemqOpenapiDataPolicy.class);
final HivemqOpenapiDataPolicy policy = JSON.deserialize(policyJson, HivemqOpenapiDataPolicy.class);
final String serialized = gson.toJson(policy);
assertEquals(policyJson, serialized);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@

import static com.hivemq.client.mqtt.mqtt5.message.publish.Mqtt5PayloadFormatIndicator.UNSPECIFIED;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -140,7 +140,7 @@ void mqtt5_base64Payload_allFieldPresent_converted() {
assertEquals("myResponseTopic", map.get("responseTopic"));

final Object userPropertiesArrayList = map.get("userProperties");
assertTrue(userPropertiesArrayList instanceof ArrayList);
assertInstanceOf(ArrayList.class, userPropertiesArrayList);
@SuppressWarnings("unchecked") //
final ArrayList<LinkedTreeMap<String, String>> userPropertiesMapCasted =
(ArrayList<LinkedTreeMap<String, String>>) userPropertiesArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ public class SchemaSerializerTest {
.registerTypeAdapter(OffsetDateTime.class, new OffsetDateTimeSerializer())
.registerTypeAdapter(HivemqOpenapiSchema.class, new SchemaSerializer())
.create();
private final @NotNull JSON openapiSerialization = new JSON();

@Test
void serialize_allFields_jsonIdentical() {
final String schemaJson = "{\"id\":\"protobuf-1-schema\",\"version\":1,\"createdAt\":\"2023-01-01T01:02:03.004Z\"," +
"\"type\":\"schemaType\",\"schemaDefinition\":\"abc\",\"arguments\":{\"argB\":\"valB\",\"argA\":\"valA\"}}";

final HivemqOpenapiSchema schema = openapiSerialization.deserialize(schemaJson, HivemqOpenapiSchema.class);
final HivemqOpenapiSchema schema = JSON.deserialize(schemaJson, HivemqOpenapiSchema.class);
final String serialized = gson.toJson(schema);
assertEquals(schemaJson, serialized);
}
Expand Down

0 comments on commit e29d8f9

Please sign in to comment.