This repository has been archived by the owner on May 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 779
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Maintaining ReadyMarkers in a dedicated service
...instead of using the SCR for it. Signed-off-by: Simon Kaufmann <[email protected]>
- Loading branch information
Simon Kaufmann
committed
Sep 8, 2017
1 parent
74880d0
commit e6233e7
Showing
19 changed files
with
643 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
....test/src/test/java/org/eclipse/smarthome/core/internal/service/ReadyServiceImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* Copyright (c) 2014-2017 by the respective copyright holders. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.eclipse.smarthome.core.internal.service; | ||
|
||
import static org.junit.Assert.*; | ||
import static org.mockito.Matchers.isA; | ||
import static org.mockito.Mockito.*; | ||
|
||
import org.eclipse.smarthome.core.service.ReadyMarker; | ||
import org.eclipse.smarthome.core.service.ReadyMarkerFilter; | ||
import org.eclipse.smarthome.core.service.ReadyService.ReadyTracker; | ||
import org.junit.Test; | ||
|
||
/** | ||
* | ||
* @author Simon Kaufmann - initial contribution and API. | ||
* | ||
*/ | ||
public class ReadyServiceImplTest { | ||
|
||
@Test | ||
public void testDifferentReadyMarkerInstances() { | ||
ReadyServiceImpl rs = new ReadyServiceImpl(); | ||
assertFalse(rs.isReady(new ReadyMarker("test", "id"))); | ||
rs.markReady(new ReadyMarker("test", "id")); | ||
assertTrue(rs.isReady(new ReadyMarker("test", "id"))); | ||
rs.unmarkReady(new ReadyMarker("test", "id")); | ||
assertFalse(rs.isReady(new ReadyMarker("test", "id"))); | ||
} | ||
|
||
@Test | ||
public void testTrackersAreInformedInitially() { | ||
ReadyTracker tracker = mock(ReadyTracker.class); | ||
ReadyServiceImpl rs = new ReadyServiceImpl(); | ||
rs.markReady(new ReadyMarker("test", "id")); | ||
rs.registerTracker(tracker); | ||
verify(tracker).onReadyMarkerAdded(isA(ReadyMarker.class)); | ||
verifyNoMoreInteractions(tracker); | ||
} | ||
|
||
@Test | ||
public void testTrackersAreInformedOnChange() { | ||
ReadyTracker tracker = mock(ReadyTracker.class); | ||
ReadyServiceImpl rs = new ReadyServiceImpl(); | ||
rs.registerTracker(tracker); | ||
rs.markReady(new ReadyMarker("test", "id")); | ||
verify(tracker).onReadyMarkerAdded(isA(ReadyMarker.class)); | ||
rs.unmarkReady(new ReadyMarker("test", "id")); | ||
verify(tracker).onReadyMarkerRemoved(isA(ReadyMarker.class)); | ||
verifyNoMoreInteractions(tracker); | ||
} | ||
|
||
@Test | ||
public void testTrackersAreInformedOnlyOnMatch() { | ||
ReadyTracker tracker = mock(ReadyTracker.class); | ||
ReadyServiceImpl rs = new ReadyServiceImpl(); | ||
rs.registerTracker(tracker, new ReadyMarkerFilter().withType("test")); | ||
rs.markReady(new ReadyMarker("foo", "id")); | ||
verifyNoMoreInteractions(tracker); | ||
rs.markReady(new ReadyMarker("test", "id")); | ||
verify(tracker).onReadyMarkerAdded(isA(ReadyMarker.class)); | ||
verifyNoMoreInteractions(tracker); | ||
} | ||
|
||
@Test | ||
public void testUnregisterTracker() { | ||
ReadyTracker tracker = mock(ReadyTracker.class); | ||
ReadyServiceImpl rs = new ReadyServiceImpl(); | ||
rs.markReady(new ReadyMarker("foo", "id")); | ||
rs.registerTracker(tracker, new ReadyMarkerFilter()); | ||
verify(tracker).onReadyMarkerAdded(isA(ReadyMarker.class)); | ||
rs.unregisterTracker(tracker); | ||
verify(tracker).onReadyMarkerRemoved(isA(ReadyMarker.class)); | ||
verifyNoMoreInteractions(tracker); | ||
} | ||
|
||
} |
Oops, something went wrong.