Skip to content

Commit

Permalink
Fix unstable ItemChannelLinkResourceOSGiTest (openhab#2536)
Browse files Browse the repository at this point in the history
New ItemChannelLinkProviders are added asynchronously to the ItemChannelLinkRegistry, which can cause this test to fail:

TEST org.openhab.core.io.rest.core.internal.link.ItemChannelLinkResourceOSGiTest#shouldReturnLinks() <<< ERROR:
Expected: a collection with size <3>
     but: collection size was <0>
java.lang.AssertionError:
Expected: a collection with size <3>
     but: collection size was <0>
	at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
	at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:6)
	at org.openhab.core.io.rest.core.internal.link.ItemChannelLinkResourceOSGiTest.shouldReturnLinks(ItemChannelLinkResourceOSGiTest.java:109)

Signed-off-by: Wouter Born <github@maindrain.net>
GitOrigin-RevId: 39dad81
  • Loading branch information
wborn authored and splatch committed Jul 12, 2023
1 parent cc89c2f commit 18bf26e
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.link.ItemChannelLink;
import org.openhab.core.thing.link.ItemChannelLinkProvider;
import org.openhab.core.thing.link.ItemChannelLinkRegistry;
import org.openhab.core.thing.link.ManagedItemChannelLinkProvider;

import com.google.gson.JsonElement;
Expand Down Expand Up @@ -73,6 +74,7 @@ public class ItemChannelLinkResourceOSGiTest extends JavaOSGiTest {
private UriInfo uriInfo;
private HttpHeaders httpHeaders;

private ItemChannelLinkRegistry itemChannelLinkRegistry;
private ItemChannelLinkResource itemChannelLinkResource;
private ManagedItemChannelLinkProvider managedItemChannelLinkProvider;

Expand All @@ -83,6 +85,9 @@ public void beforeEach() {
itemChannelLinkResource = getService(RESTResource.class, ItemChannelLinkResource.class);
assertNotNull(itemChannelLinkResource);

itemChannelLinkRegistry = getService(ItemChannelLinkRegistry.class);
assertNotNull(itemChannelLinkRegistry);

managedItemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
assertNotNull(managedItemChannelLinkProvider);

Expand All @@ -93,6 +98,10 @@ public void beforeEach() {
when(itemChannelLinkProvider.getAll()).thenReturn(List.of(link1, link2, link3));
registerService(itemChannelLinkProvider);

waitForAssert(() -> {
assertThat(itemChannelLinkRegistry.getAll(), hasSize(3));
});

UriBuilder uriBuilder = mock(UriBuilder.class);
when(uriBuilder.build(any())).thenReturn(URI.create(""));
uriInfo = mock(UriInfo.class);
Expand Down

0 comments on commit 18bf26e

Please sign in to comment.