diff --git a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/validation/ConfigDescriptionValidatorTest.java b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/validation/ConfigDescriptionValidatorTest.java index 44755518f0f..9579e756e9c 100644 --- a/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/validation/ConfigDescriptionValidatorTest.java +++ b/bundles/org.openhab.core.config.core/src/test/java/org/openhab/core/config/core/internal/validation/ConfigDescriptionValidatorTest.java @@ -14,6 +14,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @@ -268,7 +269,7 @@ public void assertValidationThrowsExceptionContainingMessagesForAllRequiredConfi params.put(DECIMAL_REQUIRED_PARAM_NAME, null); ConfigValidationException exception = Assertions.assertThrows(ConfigValidationException.class, () -> configDescriptionValidator.validate(params, CONFIG_DESCRIPTION_URI)); - assertThat(getConfigValidationMessages(exception), is(expected)); + assertThat(getConfigValidationMessages(exception), containsInAnyOrder(expected.toArray())); } void assertMissingRequired(String parameterName) { @@ -352,7 +353,7 @@ public void assertValidationThrowsExceptionContainingMessagesForAllMinMaxConfigP params.put(DECIMAL_MAX_PARAM_NAME, DECIMAL_MAX_VIOLATED); ConfigValidationException exception = Assertions.assertThrows(ConfigValidationException.class, () -> configDescriptionValidator.validate(params, CONFIG_DESCRIPTION_URI)); - assertThat(getConfigValidationMessages(exception), is(expected)); + assertThat(getConfigValidationMessages(exception), containsInAnyOrder(expected.toArray())); } void assertMinMax(String parameterName, Object value, MessageKey msgKey, String minMax) { @@ -405,7 +406,7 @@ public void assertValidationThrowsExceptionContainingMessagesForMultipleInvalidT params.put(DECIMAL_PARAM_NAME, INVALID); ConfigValidationException exception = Assertions.assertThrows(ConfigValidationException.class, () -> configDescriptionValidator.validate(params, CONFIG_DESCRIPTION_URI)); - assertThat(getConfigValidationMessages(exception), is(expected)); + assertThat(getConfigValidationMessages(exception), containsInAnyOrder(expected.toArray())); } void assertType(String parameterName, Type type) { @@ -513,7 +514,7 @@ public void assertValidationThrowsExceptionContainingMultipleVariousViolations() params.put(DECIMAL_MAX_PARAM_NAME, DECIMAL_MAX_VIOLATED); ConfigValidationException exception = Assertions.assertThrows(ConfigValidationException.class, () -> configDescriptionValidator.validate(params, CONFIG_DESCRIPTION_URI)); - assertThat(getConfigValidationMessages(exception), is(expected)); + assertThat(getConfigValidationMessages(exception), containsInAnyOrder(expected.toArray())); } @Test diff --git a/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/inbox/events/InboxEventFactoryTest.java b/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/inbox/events/InboxEventFactoryTest.java index eb233dbe2eb..4d5d3da9b10 100644 --- a/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/inbox/events/InboxEventFactoryTest.java +++ b/bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/inbox/events/InboxEventFactoryTest.java @@ -25,6 +25,7 @@ import org.openhab.core.thing.ThingUID; import com.google.gson.Gson; +import com.google.gson.JsonParser; /** * {@link InboxEventFactoryTest} tests the {@link InboxEventFactory}. @@ -71,7 +72,7 @@ public void inboxEventFactoryCreatesInboxAddedEventCorrectly() { assertThat(event.getType(), is(INBOX_ADDED_EVENT_TYPE)); assertThat(event.getTopic(), is(INBOX_ADDED_EVENT_TOPIC)); - assertThat(event.getPayload(), is(INBOX_ADDED_EVENT_PAYLOAD)); + assertThat(JsonParser.parseString(event.getPayload()), is(JsonParser.parseString(INBOX_ADDED_EVENT_PAYLOAD))); assertThat(event.getDiscoveryResult(), not(nullValue())); assertThat(event.getDiscoveryResult().thingUID, is(THING_UID.getAsString())); } diff --git a/bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/Stream2JSONInputStreamTest.java b/bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/Stream2JSONInputStreamTest.java index e78632602a2..3e4c129f8dc 100644 --- a/bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/Stream2JSONInputStreamTest.java +++ b/bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/Stream2JSONInputStreamTest.java @@ -27,6 +27,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.JsonParser; /** * Tests {@link Stream2JSONInputStream}. @@ -52,7 +53,8 @@ public void shouldStreamSingleObjectToJSON() throws Exception { List dummyList = List.of(dummyObject); Stream2JSONInputStream collection2InputStream = new Stream2JSONInputStream(Stream.of(dummyObject)); - assertThat(inputStreamToString(collection2InputStream), is(GSON.toJson(dummyList))); + assertThat(JsonParser.parseString(inputStreamToString(collection2InputStream)), + is(JsonParser.parseString(GSON.toJson(dummyList)))); } @Test @@ -62,7 +64,8 @@ public void shouldStreamCollectionStreamToJSON() throws Exception { List dummyCollection = List.of(dummyObject1, dummyObject2); Stream2JSONInputStream collection2InputStream = new Stream2JSONInputStream(dummyCollection.stream()); - assertThat(inputStreamToString(collection2InputStream), is(GSON.toJson(dummyCollection))); + assertThat(JsonParser.parseString(inputStreamToString(collection2InputStream)), + is(JsonParser.parseString(GSON.toJson(dummyCollection)))); } private String inputStreamToString(InputStream in) throws IOException { diff --git a/bundles/org.openhab.core.model.yaml/src/test/java/org/openhab/core/model/yaml/internal/YamlModelRepositoryImplTest.java b/bundles/org.openhab.core.model.yaml/src/test/java/org/openhab/core/model/yaml/internal/YamlModelRepositoryImplTest.java index 9c8285b2f37..13259e1c372 100644 --- a/bundles/org.openhab.core.model.yaml/src/test/java/org/openhab/core/model/yaml/internal/YamlModelRepositoryImplTest.java +++ b/bundles/org.openhab.core.model.yaml/src/test/java/org/openhab/core/model/yaml/internal/YamlModelRepositoryImplTest.java @@ -14,6 +14,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; @@ -41,6 +42,7 @@ import org.openhab.core.model.yaml.test.FirstTypeDTO; import org.openhab.core.model.yaml.test.SecondTypeDTO; import org.openhab.core.service.WatchService; +import org.yaml.snakeyaml.Yaml; /** * The {@link YamlModelRepositoryImplTest} contains tests for the {@link YamlModelRepositoryImpl} class. @@ -204,8 +206,9 @@ public void testAddElementToModel() throws IOException { String actualFileContent = Files.readString(fullModelPath); String expectedFileContent = Files.readString(SOURCE_PATH.resolve("addToModelExpectedContent.yaml")); + Yaml yaml = new Yaml(); - assertThat(actualFileContent, is(expectedFileContent.replaceAll("\r\n", "\n"))); + assertThat(yaml.load(actualFileContent), equalTo(yaml.load(expectedFileContent.replaceAll("\r\n", "\n")))); } @Test @@ -220,8 +223,9 @@ public void testUpdateElementInModel() throws IOException { String actualFileContent = Files.readString(fullModelPath); String expectedFileContent = Files.readString(SOURCE_PATH.resolve("updateInModelExpectedContent.yaml")); + Yaml yaml = new Yaml(); - assertThat(actualFileContent, is(expectedFileContent.replaceAll("\r\n", "\n"))); + assertThat(yaml.load(actualFileContent), equalTo(yaml.load(expectedFileContent.replaceAll("\r\n", "\n")))); } @Test diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/link/events/LinkEventFactoryTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/link/events/LinkEventFactoryTest.java index 0983870c1be..d52428201ae 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/link/events/LinkEventFactoryTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/link/events/LinkEventFactoryTest.java @@ -24,6 +24,7 @@ import org.openhab.core.thing.link.dto.ItemChannelLinkDTO; import com.google.gson.Gson; +import com.google.gson.JsonParser; /** * {@link LinkEventFactoryTest} tests the {@link LinkEventFactory}. @@ -52,7 +53,7 @@ public void testCreateItemChannelLinkAddedEvent() { assertEquals(ItemChannelLinkAddedEvent.TYPE, event.getType()); assertEquals(LINK_ADDED_EVENT_TOPIC, event.getTopic()); - assertEquals(LINK_EVENT_PAYLOAD, event.getPayload()); + assertEquals(JsonParser.parseString(LINK_EVENT_PAYLOAD), JsonParser.parseString(event.getPayload())); } @Test @@ -73,7 +74,7 @@ public void testCreateItemChannelLinkRemovedEvent() { assertEquals(ItemChannelLinkRemovedEvent.TYPE, event.getType()); assertEquals(LINK_REMOVED_EVENT_TOPIC, event.getTopic()); - assertEquals(LINK_EVENT_PAYLOAD, event.getPayload()); + assertEquals(JsonParser.parseString(LINK_EVENT_PAYLOAD), JsonParser.parseString(event.getPayload())); } @Test diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/cache/ExpiringCacheMapTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/cache/ExpiringCacheMapTest.java index 360c896470b..e9768c6e48b 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/cache/ExpiringCacheMapTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/cache/ExpiringCacheMapTest.java @@ -149,7 +149,7 @@ public void testValues() { expectedValues.add(value1); final Collection<@Nullable String> values = subject.values(); - assertEquals(expectedValues, values); + assertEquals(new LinkedHashSet<>(expectedValues), new LinkedHashSet<>(values)); } // use another different key diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/items/events/ItemEventFactoryTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/items/events/ItemEventFactoryTest.java index 7335a2504c0..79fafb8d3cf 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/items/events/ItemEventFactoryTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/items/events/ItemEventFactoryTest.java @@ -31,6 +31,7 @@ import org.openhab.core.types.UnDefType; import com.google.gson.Gson; +import com.google.gson.JsonParser; /** * {@link ItemEventFactoryTest} tests the {@link ItemEventFactory}. @@ -96,7 +97,7 @@ public void testCreateCommandEventOnOffType() throws Exception { assertEquals(ITEM_COMMAND_EVENT_TYPE, event.getType()); assertEquals(ITEM_COMMAND_EVENT_TOPIC, event.getTopic()); - assertEquals(ITEM_COMMAND_EVENT_PAYLOAD, event.getPayload()); + assertEquals(JsonParser.parseString(ITEM_COMMAND_EVENT_PAYLOAD), JsonParser.parseString(event.getPayload())); assertEquals(ITEM_NAME, event.getItemName()); assertEquals(SOURCE, event.getSource()); assertEquals(OnOffType.class, event.getItemCommand().getClass()); @@ -189,7 +190,7 @@ public void testCreateStateEventOnOffType() { assertThat(event.getType(), is(ITEM_STATE_EVENT_TYPE)); assertThat(event.getTopic(), is(ITEM_STATE_EVENT_TOPIC)); - assertThat(event.getPayload(), is(ITEM_STATE_EVENT_PAYLOAD)); + assertThat(JsonParser.parseString(event.getPayload()), is(JsonParser.parseString(ITEM_STATE_EVENT_PAYLOAD))); assertThat(event.getItemName(), is(ITEM_NAME)); assertThat(event.getSource(), is(SOURCE)); assertEquals(OnOffType.class, event.getItemState().getClass());