Skip to content

Commit

Permalink
Fixed itests
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
  • Loading branch information
cweitkamp committed May 19, 2020
1 parent 146edbf commit 0ed1f2a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@
import java.util.Collections;
import java.util.Random;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;

/**
* The {@link DiscoveryServiceMock} is a mock for a {@link
* org.openhab.core.config.discovery.DiscoveryService} which can simulate a working and faulty
* The {@link DiscoveryServiceMock} is a mock for a {@link DiscoveryService} which can simulate a working and faulty
* discovery.<br>
* If this mock is configured to be faulty, an exception is thrown if the discovery is enforced or
* aborted.
* If this mock is configured to be faulty, an exception is thrown if the discovery is enforced or aborted.
*
* @author Michael Grammling - Initial contribution
* @author Thomas Höfer - Added representation
*/
@NonNullByDefault
public class DiscoveryServiceMock extends AbstractDiscoveryService {

public static final int DEFAULT_TTL = 60;

ThingTypeUID thingType;
int timeout;
boolean faulty;
final ThingTypeUID thingType;
final int timeout;
final boolean faulty;

public DiscoveryServiceMock(ThingTypeUID thingType, int timeout) {
this(thingType, timeout, false);
Expand All @@ -43,6 +43,7 @@ public DiscoveryServiceMock(ThingTypeUID thingType, int timeout) {
public DiscoveryServiceMock(ThingTypeUID thingType, int timeout, boolean faulty) {
super(Collections.singleton(thingType), timeout);
this.thingType = thingType;
this.timeout = timeout;
this.faulty = faulty;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

import java.util.Random;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;

/**
* @author Andre Fuechsel - Initial contribution
*/
@NonNullByDefault
public class DiscoveryServiceMockOfBridge extends DiscoveryServiceMock {

final ThingUID bridgeUID;
Expand All @@ -31,7 +33,11 @@ public DiscoveryServiceMockOfBridge(ThingTypeUID thingType, int timeout, ThingUI

@Override
public void startScan() {
thingDiscovered(DiscoveryResultBuilder.create(new ThingUID(thingType, "test" + new Random().nextInt(999999999)))
if (faulty) {
throw new RuntimeException();
}
thingDiscovered(DiscoveryResultBuilder
.create(new ThingUID(thingType, bridgeUID, "test" + new Random().nextInt(999999999)))
.withBridge(bridgeUID).withTTL(DEFAULT_TTL).build());
}

Expand Down

0 comments on commit 0ed1f2a

Please sign in to comment.