-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed 2 unnecessary stubbings in HomekitRootTest.java
- Loading branch information
Showing
6 changed files
with
173 additions
and
58 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
55 changes: 55 additions & 0 deletions
55
src/test/java/io/github/hapjava/server/impl/FourthHomekitRootTest.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,55 @@ | ||
package io.github.hapjava.server.impl; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import io.github.hapjava.accessories.HomekitAccessory; | ||
import io.github.hapjava.server.HomekitAccessoryCategories; | ||
import io.github.hapjava.server.HomekitAuthInfo; | ||
import io.github.hapjava.server.HomekitWebHandler; | ||
import io.github.hapjava.server.impl.jmdns.JmdnsHomekitAdvertiser; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class FourthHomekitRootTest { | ||
|
||
private HomekitAccessory accessory; | ||
private HomekitRoot root; | ||
private HomekitWebHandler webHandler; | ||
private JmdnsHomekitAdvertiser advertiser; | ||
private HomekitAuthInfo authInfo; | ||
|
||
private static final int PORT = 12345; | ||
private static final String SETUPID = "Gx12"; | ||
|
||
private static final String LABEL = "Test Label"; | ||
|
||
@Before | ||
public void setup() throws Exception { | ||
accessory = mock(HomekitAccessory.class); | ||
when(accessory.getId()).thenReturn(2); | ||
webHandler = mock(HomekitWebHandler.class); | ||
advertiser = mock(JmdnsHomekitAdvertiser.class); | ||
authInfo = mock(HomekitAuthInfo.class); | ||
root = | ||
new HomekitRoot(LABEL, HomekitAccessoryCategories.OTHER, webHandler, authInfo, advertiser); | ||
} | ||
|
||
@Test | ||
public void verifyRegistryAdded() throws Exception { | ||
root.addAccessory(accessory); | ||
Assert.assertTrue( | ||
"Registry does not contain accessory", | ||
root.getRegistry().getAccessories().contains(accessory)); | ||
} | ||
|
||
@Test | ||
public void verifyRegistryRemoved() throws Exception { | ||
root.addAccessory(accessory); | ||
root.removeAccessory(accessory); | ||
Assert.assertFalse( | ||
"Registry still contains accessory", | ||
root.getRegistry().getAccessories().contains(accessory)); | ||
} | ||
} |
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
72 changes: 72 additions & 0 deletions
72
src/test/java/io/github/hapjava/server/impl/SecondHomekitRootTest.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,72 @@ | ||
package io.github.hapjava.server.impl; | ||
|
||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Matchers.eq; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import io.github.hapjava.accessories.HomekitAccessory; | ||
import io.github.hapjava.server.HomekitAccessoryCategories; | ||
import io.github.hapjava.server.HomekitAuthInfo; | ||
import io.github.hapjava.server.HomekitWebHandler; | ||
import io.github.hapjava.server.impl.http.HomekitClientConnectionFactory; | ||
import io.github.hapjava.server.impl.jmdns.JmdnsHomekitAdvertiser; | ||
import java.util.concurrent.CompletableFuture; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class SecondHomekitRootTest { | ||
|
||
private HomekitAccessory accessory; | ||
private HomekitRoot root; | ||
private HomekitWebHandler webHandler; | ||
private JmdnsHomekitAdvertiser advertiser; | ||
private HomekitAuthInfo authInfo; | ||
|
||
private static final int PORT = 12345; | ||
private static final String SETUPID = "Gx12"; | ||
|
||
private static final String LABEL = "Test Label"; | ||
|
||
@Before | ||
public void setup() throws Exception { | ||
accessory = mock(HomekitAccessory.class); | ||
webHandler = mock(HomekitWebHandler.class); | ||
when(webHandler.start(any())).thenReturn(CompletableFuture.completedFuture(PORT)); | ||
advertiser = mock(JmdnsHomekitAdvertiser.class); | ||
authInfo = mock(HomekitAuthInfo.class); | ||
root = | ||
new HomekitRoot(LABEL, HomekitAccessoryCategories.OTHER, webHandler, authInfo, advertiser); | ||
} | ||
|
||
@Test | ||
public void testWebHandlerStarts() throws Exception { | ||
root.start(); | ||
verify(webHandler).start(any(HomekitClientConnectionFactory.class)); | ||
} | ||
|
||
@Test | ||
public void testWebHandlerStops() throws Exception { | ||
root.start(); | ||
root.stop(); | ||
verify(webHandler).stop(); | ||
} | ||
|
||
@Test | ||
public void testAdvertiserStarts() throws Exception { | ||
final String mac = "00:00:00:00:00:00"; | ||
when(authInfo.getMac()).thenReturn(mac); | ||
when(authInfo.getSetupId()).thenReturn(SETUPID); | ||
|
||
root.start(); | ||
verify(advertiser).advertise(eq(LABEL), eq(1), eq(mac), eq(PORT), eq(1), eq(SETUPID)); | ||
} | ||
|
||
@Test | ||
public void testAdvertiserStops() throws Exception { | ||
root.start(); | ||
root.stop(); | ||
verify(advertiser).stop(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/test/java/io/github/hapjava/server/impl/ThirdHomekitRootTest.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,42 @@ | ||
package io.github.hapjava.server.impl; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import io.github.hapjava.accessories.HomekitAccessory; | ||
import io.github.hapjava.server.HomekitAccessoryCategories; | ||
import io.github.hapjava.server.HomekitAuthInfo; | ||
import io.github.hapjava.server.HomekitWebHandler; | ||
import io.github.hapjava.server.impl.jmdns.JmdnsHomekitAdvertiser; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class ThirdHomekitRootTest { | ||
|
||
private HomekitAccessory accessory; | ||
private HomekitRoot root; | ||
private HomekitWebHandler webHandler; | ||
private JmdnsHomekitAdvertiser advertiser; | ||
private HomekitAuthInfo authInfo; | ||
|
||
private static final int PORT = 12345; | ||
private static final String SETUPID = "Gx12"; | ||
|
||
private static final String LABEL = "Test Label"; | ||
|
||
@Before | ||
public void setup() throws Exception { | ||
accessory = mock(HomekitAccessory.class); | ||
webHandler = mock(HomekitWebHandler.class); | ||
advertiser = mock(JmdnsHomekitAdvertiser.class); | ||
authInfo = mock(HomekitAuthInfo.class); | ||
root = | ||
new HomekitRoot(LABEL, HomekitAccessoryCategories.OTHER, webHandler, authInfo, advertiser); | ||
} | ||
|
||
@Test(expected = IndexOutOfBoundsException.class) | ||
public void testAddIndexOneAccessory() throws Exception { | ||
when(accessory.getId()).thenReturn(1); | ||
root.addAccessory(accessory); | ||
} | ||
} |