Search in sources :

Example 1 with InboxAddedEvent

use of org.eclipse.smarthome.config.discovery.inbox.events.InboxAddedEvent in project smarthome by eclipse.

the class PersistentInboxTest method testEmittedAddedResultIsReadFromStorage.

@Test
public void testEmittedAddedResultIsReadFromStorage() {
    DiscoveryResult result = DiscoveryResultBuilder.create(THING_UID).withProperty("foo", 3).build();
    EventPublisher eventPublisher = mock(EventPublisher.class);
    inbox.setEventPublisher(eventPublisher);
    // 
    when(storage.get(THING_UID.toString())).thenReturn(// 
    null).thenReturn(DiscoveryResultBuilder.create(THING_UID).withProperty("foo", "bar").build());
    inbox.add(result);
    // 1st call checks existence of the result in the storage (returns null)
    // 2nd call retrieves the stored instance before the event gets emitted
    // (modified due to storage mock configuration)
    verify(storage, times(2)).get(THING_UID.toString());
    ArgumentCaptor<InboxAddedEvent> eventCaptor = ArgumentCaptor.forClass(InboxAddedEvent.class);
    verify(eventPublisher).post(eventCaptor.capture());
    assertThat(eventCaptor.getValue().getDiscoveryResult().properties, hasEntry("foo", "bar"));
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) EventPublisher(org.eclipse.smarthome.core.events.EventPublisher) InboxAddedEvent(org.eclipse.smarthome.config.discovery.inbox.events.InboxAddedEvent) Test(org.junit.Test)

Aggregations

DiscoveryResult (org.eclipse.smarthome.config.discovery.DiscoveryResult)1 InboxAddedEvent (org.eclipse.smarthome.config.discovery.inbox.events.InboxAddedEvent)1 EventPublisher (org.eclipse.smarthome.core.events.EventPublisher)1 Test (org.junit.Test)1