add unit test for resolveRoomId()

Signed-off-by: David Pace <dev@davidpace.de>
This commit is contained in:
David Pace 2025-01-06 21:28:18 +01:00
parent 9aa64a2972
commit 9a5b8f9d7c

View File

@ -12,6 +12,8 @@
*/ */
package org.openhab.binding.boschshc.internal.devices.bridge; package org.openhab.binding.boschshc.internal.devices.bridge;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize; import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
@ -1126,4 +1128,33 @@ class BridgeHandlerTest {
verify(httpClient).createRequest(any(), same(HttpMethod.GET)); verify(httpClient).createRequest(any(), same(HttpMethod.GET));
verify(httpClient).sendRequest(any(), same(PublicInformation.class), any(), isNull()); verify(httpClient).sendRequest(any(), same(PublicInformation.class), any(), isNull());
} }
@Test
void resolveRoomId() throws InterruptedException, TimeoutException, ExecutionException {
Request request = mock(Request.class);
when(httpClient.createRequest(any(), eq(HttpMethod.GET))).thenReturn(request);
ContentResponse contentResponse = mock(ContentResponse.class);
when(request.send()).thenReturn(contentResponse);
when(contentResponse.getStatus()).thenReturn(200);
String roomsJson = """
[
{
"@type": "room",
"id": "hz_1",
"iconId": "icon_room_living_room",
"name": "Living Room"
},
{
"@type": "room",
"id": "hz_2",
"iconId": "icon_room_dining_room",
"name": "Dining Room"
}
]
""";
when(contentResponse.getContentAsString()).thenReturn(roomsJson);
assertThat(fixture.resolveRoomId("hz_1"), is("Living Room"));
assertThat(fixture.resolveRoomId("hz_2"), is("Dining Room"));
assertThat(fixture.resolveRoomId(null), is(nullValue()));
}
} }