Skip to content

Commit 889c64c

Browse files
author
Yug Vajani
committed
Fixed a few non deterministic tests in the repository
Signed-off-by: Yug Vajani <[email protected]>
1 parent 297d54e commit 889c64c

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

bundles/org.openhab.core.config.discovery/src/test/java/org/openhab/core/config/discovery/inbox/events/InboxEventFactoryTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.openhab.core.thing.ThingUID;
2626

2727
import com.google.gson.Gson;
28+
import com.google.gson.JsonParser;
2829

2930
/**
3031
* {@link InboxEventFactoryTest} tests the {@link InboxEventFactory}.
@@ -71,7 +72,7 @@ public void inboxEventFactoryCreatesInboxAddedEventCorrectly() {
7172

7273
assertThat(event.getType(), is(INBOX_ADDED_EVENT_TYPE));
7374
assertThat(event.getTopic(), is(INBOX_ADDED_EVENT_TOPIC));
74-
assertThat(event.getPayload(), is(INBOX_ADDED_EVENT_PAYLOAD));
75+
assertThat(JsonParser.parseString(event.getPayload()), is(JsonParser.parseString(INBOX_ADDED_EVENT_PAYLOAD)));
7576
assertThat(event.getDiscoveryResult(), not(nullValue()));
7677
assertThat(event.getDiscoveryResult().thingUID, is(THING_UID.getAsString()));
7778
}

bundles/org.openhab.core.io.rest/src/test/java/org/openhab/core/io/rest/Stream2JSONInputStreamTest.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import com.google.gson.Gson;
2929
import com.google.gson.GsonBuilder;
30+
import com.google.gson.JsonParser;
3031

3132
/**
3233
* Tests {@link Stream2JSONInputStream}.
@@ -52,7 +53,8 @@ public void shouldStreamSingleObjectToJSON() throws Exception {
5253
List<DummyObject> dummyList = List.of(dummyObject);
5354
Stream2JSONInputStream collection2InputStream = new Stream2JSONInputStream(Stream.of(dummyObject));
5455

55-
assertThat(inputStreamToString(collection2InputStream), is(GSON.toJson(dummyList)));
56+
assertThat(JsonParser.parseString(inputStreamToString(collection2InputStream)),
57+
is(JsonParser.parseString(GSON.toJson(dummyList))));
5658
}
5759

5860
@Test
@@ -62,7 +64,8 @@ public void shouldStreamCollectionStreamToJSON() throws Exception {
6264
List<DummyObject> dummyCollection = List.of(dummyObject1, dummyObject2);
6365
Stream2JSONInputStream collection2InputStream = new Stream2JSONInputStream(dummyCollection.stream());
6466

65-
assertThat(inputStreamToString(collection2InputStream), is(GSON.toJson(dummyCollection)));
67+
assertThat(JsonParser.parseString(inputStreamToString(collection2InputStream)),
68+
is(JsonParser.parseString(GSON.toJson(dummyCollection))));
6669
}
6770

6871
private String inputStreamToString(InputStream in) throws IOException {

bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/link/events/LinkEventFactoryTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.openhab.core.thing.link.dto.ItemChannelLinkDTO;
2525

2626
import com.google.gson.Gson;
27+
import com.google.gson.JsonParser;
2728

2829
/**
2930
* {@link LinkEventFactoryTest} tests the {@link LinkEventFactory}.
@@ -52,7 +53,7 @@ public void testCreateItemChannelLinkAddedEvent() {
5253

5354
assertEquals(ItemChannelLinkAddedEvent.TYPE, event.getType());
5455
assertEquals(LINK_ADDED_EVENT_TOPIC, event.getTopic());
55-
assertEquals(LINK_EVENT_PAYLOAD, event.getPayload());
56+
assertEquals(JsonParser.parseString(LINK_EVENT_PAYLOAD), JsonParser.parseString(event.getPayload()));
5657
}
5758

5859
@Test
@@ -73,7 +74,7 @@ public void testCreateItemChannelLinkRemovedEvent() {
7374

7475
assertEquals(ItemChannelLinkRemovedEvent.TYPE, event.getType());
7576
assertEquals(LINK_REMOVED_EVENT_TOPIC, event.getTopic());
76-
assertEquals(LINK_EVENT_PAYLOAD, event.getPayload());
77+
assertEquals(JsonParser.parseString(LINK_EVENT_PAYLOAD), JsonParser.parseString(event.getPayload()));
7778
}
7879

7980
@Test

bundles/org.openhab.core/src/test/java/org/openhab/core/items/events/ItemEventFactoryTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.openhab.core.types.UnDefType;
3232

3333
import com.google.gson.Gson;
34+
import com.google.gson.JsonParser;
3435

3536
/**
3637
* {@link ItemEventFactoryTest} tests the {@link ItemEventFactory}.
@@ -96,7 +97,7 @@ public void testCreateCommandEventOnOffType() throws Exception {
9697

9798
assertEquals(ITEM_COMMAND_EVENT_TYPE, event.getType());
9899
assertEquals(ITEM_COMMAND_EVENT_TOPIC, event.getTopic());
99-
assertEquals(ITEM_COMMAND_EVENT_PAYLOAD, event.getPayload());
100+
assertEquals(JsonParser.parseString(ITEM_COMMAND_EVENT_PAYLOAD), JsonParser.parseString(event.getPayload()));
100101
assertEquals(ITEM_NAME, event.getItemName());
101102
assertEquals(SOURCE, event.getSource());
102103
assertEquals(OnOffType.class, event.getItemCommand().getClass());
@@ -189,7 +190,7 @@ public void testCreateStateEventOnOffType() {
189190

190191
assertThat(event.getType(), is(ITEM_STATE_EVENT_TYPE));
191192
assertThat(event.getTopic(), is(ITEM_STATE_EVENT_TOPIC));
192-
assertThat(event.getPayload(), is(ITEM_STATE_EVENT_PAYLOAD));
193+
assertThat(JsonParser.parseString(event.getPayload()), is(JsonParser.parseString(ITEM_STATE_EVENT_PAYLOAD)));
193194
assertThat(event.getItemName(), is(ITEM_NAME));
194195
assertThat(event.getSource(), is(SOURCE));
195196
assertEquals(OnOffType.class, event.getItemState().getClass());

0 commit comments

Comments
 (0)