1313import static org .mockito .Mockito .mock ;
1414import static org .mockito .Mockito .when ;
1515import static org .testng .Assert .assertEquals ;
16+ import static org .testng .Assert .assertNotNull ;
1617
1718import java .io .IOException ;
19+ import java .util .Map ;
1820import org .eclipse .che .api .core .notification .EventService ;
1921import org .eclipse .che .plugin .docker .client .DockerApiVersionPathPrefixProvider ;
2022import org .eclipse .che .plugin .docker .client .DockerConnectorConfiguration ;
2123import org .eclipse .che .plugin .docker .client .DockerRegistryAuthResolver ;
2224import org .eclipse .che .plugin .docker .client .connection .DockerConnectionFactory ;
2325import org .eclipse .che .plugin .docker .client .json .ContainerConfig ;
26+ import org .eclipse .che .plugin .docker .client .json .ImageConfig ;
2427import org .eclipse .che .plugin .docker .client .params .CreateContainerParams ;
2528import org .mockito .Mock ;
29+ import org .mockito .Mockito ;
2630import org .mockito .testng .MockitoTestNGListener ;
31+ import org .testng .annotations .BeforeMethod ;
2732import org .testng .annotations .Listeners ;
2833import org .testng .annotations .Test ;
2934
@@ -55,15 +60,8 @@ public class OpenShiftConnectorTest {
5560
5661 private OpenShiftConnector openShiftConnector ;
5762
58- @ Test
59- public void shouldGetWorkspaceIDWhenAValidOneIsProvidedInCreateContainerParams ()
60- throws IOException {
61- //Given
62- String expectedWorkspaceID = "abcd1234" ;
63- ContainerConfig containerConfig = mock (ContainerConfig .class );
64- CreateContainerParams createContainerParams = CreateContainerParams .create (containerConfig );
65-
66- when (containerConfig .getEnv ()).thenReturn (CONTAINER_ENV_VARIABLES );
63+ @ BeforeMethod
64+ private void setup () {
6765
6866 //When
6967 openShiftConnector =
@@ -88,9 +86,35 @@ public void shouldGetWorkspaceIDWhenAValidOneIsProvidedInCreateContainerParams()
8886 null ,
8987 SECURE_ROUTES ,
9088 CREATE_WORKSPACE_DIRS );
89+ }
90+
91+ @ Test
92+ public void shouldGetWorkspaceIDWhenAValidOneIsProvidedInCreateContainerParams ()
93+ throws IOException {
94+ //Given
95+ String expectedWorkspaceID = "abcd1234" ;
96+ ContainerConfig containerConfig = mock (ContainerConfig .class );
97+ CreateContainerParams createContainerParams = CreateContainerParams .create (containerConfig );
98+
99+ when (containerConfig .getEnv ()).thenReturn (CONTAINER_ENV_VARIABLES );
100+
91101 String workspaceID = openShiftConnector .getCheWorkspaceId (createContainerParams );
92102
93103 //Then
94104 assertEquals (workspaceID , expectedWorkspaceID );
95105 }
106+
107+ /** Check that we return empty map if no labels and not a NPE */
108+ @ Test
109+ public void checkWithNoLabels () {
110+ ContainerConfig containerConfig = Mockito .mock (ContainerConfig .class );
111+ when (containerConfig .getLabels ()).thenReturn (null );
112+
113+ ImageConfig imageConfig = Mockito .mock (ImageConfig .class );
114+ when (imageConfig .getLabels ()).thenReturn (null );
115+
116+ Map <String , String > map = openShiftConnector .getLabels (containerConfig , imageConfig );
117+ assertNotNull (map );
118+ assertEquals (map .size (), 0 );
119+ }
96120}
0 commit comments