Skip to content

Commit

Permalink
Fixed a few non deterministic tests in the repository
Browse files Browse the repository at this point in the history
Signed-off-by: Yug Vajani <[email protected]>
  • Loading branch information
Yug Vajani committed Dec 5, 2024
1 parent 297d54e commit 889c64c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down Expand Up @@ -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()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParser;

/**
* Tests {@link Stream2JSONInputStream}.
Expand All @@ -52,7 +53,8 @@ public void shouldStreamSingleObjectToJSON() throws Exception {
List<DummyObject> 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
Expand All @@ -62,7 +64,8 @@ public void shouldStreamCollectionStreamToJSON() throws Exception {
List<DummyObject> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 889c64c

Please sign in to comment.