-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs: DEV-12343
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
src/test/java/ch/sbb/polarion/extension/pdf_exporter/PdfExporterInternalModuleTest.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,63 @@ | ||
package ch.sbb.polarion.extension.pdf_exporter; | ||
|
||
import com.google.inject.AbstractModule; | ||
import com.google.inject.Guice; | ||
import com.google.inject.Injector; | ||
import com.polarion.alm.tracker.ITestManagementService; | ||
import com.polarion.platform.core.IPlatform; | ||
import com.polarion.platform.core.PlatformContext; | ||
import com.polarion.platform.guice.internal.GuicePlatform; | ||
import com.polarion.platform.security.ISecurityService; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.MockedStatic; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.*; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class PdfExporterInternalModuleTest { | ||
|
||
@Mock | ||
private ITestManagementService testManagementService; | ||
|
||
@BeforeEach | ||
void setUp() throws Exception { | ||
Injector injector = Guice.createInjector(new TestModule(testManagementService)); | ||
Field field = GuicePlatform.class.getDeclaredField("globalInjector"); | ||
field.setAccessible(true); | ||
field.set(null, injector); | ||
} | ||
|
||
@Test | ||
void shouldBindClassImplementations() { | ||
try (MockedStatic<PlatformContext> platformContext = mockStatic(PlatformContext.class)) { | ||
IPlatform platform = mock(IPlatform.class); | ||
platformContext.when(PlatformContext::getPlatform).thenReturn(platform); | ||
ISecurityService securityService = mock(ISecurityService.class); | ||
when(platform.lookupService(ISecurityService.class)).thenReturn(securityService); | ||
|
||
Injector injector = Guice.createInjector(new PdfExporterInternalModule()); | ||
assertThat(injector.getInstance(ISecurityService.class)).isEqualTo(securityService); | ||
assertThat(injector.getInstance(ITestManagementService.class)).isEqualTo(testManagementService); | ||
} | ||
} | ||
|
||
public static class TestModule extends AbstractModule { | ||
private final ITestManagementService testManagementService; | ||
|
||
public TestModule(ITestManagementService testManagementService) { | ||
this.testManagementService = testManagementService; | ||
} | ||
|
||
@Override | ||
protected void configure() { | ||
bind(ITestManagementService.class).toInstance(testManagementService); | ||
} | ||
} | ||
} |