use of org.openhab.core.config.discovery.inbox.events.InboxUpdatedEvent in project openhab-core by openhab.
the class PersistentInboxTest method testEmittedUpdatedResultIsReadFromStorage.
@Test
public void testEmittedUpdatedResultIsReadFromStorage() {
DiscoveryResult result = DiscoveryResultBuilder.create(THING_UID).withProperty("foo", 3).build();
EventPublisher eventPublisher = mock(EventPublisher.class);
inbox.setEventPublisher(eventPublisher);
//
when(storageMock.get(THING_UID.toString())).thenReturn(//
result).thenReturn(DiscoveryResultBuilder.create(THING_UID).withProperty("foo", "bar").build());
inbox.activate();
inbox.add(result);
// 1st call checks existence of the result in the storage (returns the original result)
// 2nd call retrieves the stored instance before the event gets emitted
// (modified due to storage mock configuration)
verify(storageMock, times(2)).get(THING_UID.toString());
ArgumentCaptor<InboxUpdatedEvent> eventCaptor = ArgumentCaptor.forClass(InboxUpdatedEvent.class);
verify(eventPublisher).post(eventCaptor.capture());
assertThat(eventCaptor.getValue().getDiscoveryResult().properties, hasEntry("foo", "bar"));
}
Aggregations