-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e46fb95
commit b7d3993
Showing
2 changed files
with
83 additions
and
1 deletion.
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
80 changes: 80 additions & 0 deletions
80
...entation/src/test/java/io/opentelemetry/android/internal/services/ServiceManagerTest.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,80 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.android.internal.services; | ||
|
||
import static org.junit.jupiter.api.Assertions.fail; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ServiceManagerTest { | ||
|
||
private ServiceManager serviceManager; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
serviceManager = new ServiceManager(); | ||
} | ||
|
||
@Test | ||
void addingServices() { | ||
FirstService firstService = mock(); | ||
SecondService secondService = mock(); | ||
|
||
serviceManager.addService(firstService); | ||
serviceManager.addService(secondService); | ||
|
||
Assertions.assertEquals(firstService, serviceManager.getService(FirstService.class)); | ||
Assertions.assertEquals(secondService, serviceManager.getService(SecondService.class)); | ||
} | ||
|
||
@Test | ||
void allowOnlyOneServicePerType() { | ||
FirstService firstService = mock(); | ||
FirstService anotherFirstService = mock(); | ||
|
||
serviceManager.addService(firstService); | ||
|
||
try { | ||
serviceManager.addService(anotherFirstService); | ||
fail(); | ||
} catch (IllegalArgumentException ignored) { | ||
} | ||
} | ||
|
||
@Test | ||
void delegatingStartCall() { | ||
FirstService firstService = mock(); | ||
SecondService secondService = mock(); | ||
serviceManager.addService(firstService); | ||
serviceManager.addService(secondService); | ||
|
||
serviceManager.start(); | ||
|
||
verify(firstService).start(); | ||
verify(secondService).start(); | ||
} | ||
|
||
@Test | ||
void delegatingStopCall() { | ||
FirstService firstService = mock(); | ||
SecondService secondService = mock(); | ||
serviceManager.addService(firstService); | ||
serviceManager.addService(secondService); | ||
|
||
serviceManager.stop(); | ||
|
||
verify(firstService).stop(); | ||
verify(secondService).stop(); | ||
} | ||
|
||
private static class FirstService implements Service {} | ||
|
||
private static class SecondService implements Service {} | ||
} |