22
33import static org .hamcrest .MatcherAssert .assertThat ;
44import static org .hamcrest .Matchers .is ;
5+ import static org .hamcrest .Matchers .nullValue ;
56import static org .mockito .Mockito .mock ;
67import static org .mockito .Mockito .times ;
78import static org .mockito .Mockito .verify ;
@@ -20,7 +21,17 @@ class JiraEnvironmentContributingActionTest {
2021 public void buildEnvVarsEnvIsNull () {
2122 JiraEnvironmentContributingAction action =
2223 new JiraEnvironmentContributingAction (ISSUES_LIST , ISSUES_SIZE , JIRA_URL );
23- AbstractBuild build = mock (AbstractBuild .class );
24+ AbstractBuild <?, ?> build = mock (AbstractBuild .class );
25+
26+ action .buildEnvVars (build , null );
27+ // just expecting no exception
28+ }
29+
30+ @ Test
31+ public void passedVariablesAreNull () {
32+ JiraEnvironmentContributingAction action =
33+ new JiraEnvironmentContributingAction (ISSUES_LIST , ISSUES_SIZE , JIRA_URL );
34+ AbstractBuild <?, ?> build = mock (AbstractBuild .class );
2435
2536 action .buildEnvVars (build , null );
2637 // just expecting no exception
@@ -48,4 +59,26 @@ public void buildEnvVarsAddVariables() {
4859 assertThat (keys .getAllValues ().get (2 ), is (JiraEnvironmentContributingAction .JIRA_URL_VARIABLE_NAME ));
4960 assertThat (values .getAllValues ().get (2 ), is (JIRA_URL ));
5061 }
62+
63+ @ Test
64+ public void noExceptionWhenNullsPassed () {
65+ JiraEnvironmentContributingAction action = new JiraEnvironmentContributingAction (null , null , null );
66+ AbstractBuild <?, ?> build = mock (AbstractBuild .class );
67+ EnvVars envVars = mock (EnvVars .class );
68+
69+ action .buildEnvVars (build , envVars );
70+
71+ ArgumentCaptor <String > keys = ArgumentCaptor .forClass (String .class );
72+ ArgumentCaptor <String > values = ArgumentCaptor .forClass (String .class );
73+ verify (envVars , times (3 )).put (keys .capture (), values .capture ());
74+
75+ assertThat (keys .getAllValues ().get (0 ), is (JiraEnvironmentContributingAction .ISSUES_VARIABLE_NAME ));
76+ assertThat (values .getAllValues ().get (0 ), nullValue ());
77+
78+ assertThat (keys .getAllValues ().get (1 ), is (JiraEnvironmentContributingAction .ISSUES_SIZE_VARIABLE_NAME ));
79+ assertThat (values .getAllValues ().get (1 ), is ("0" ));
80+
81+ assertThat (keys .getAllValues ().get (2 ), is (JiraEnvironmentContributingAction .JIRA_URL_VARIABLE_NAME ));
82+ assertThat (values .getAllValues ().get (2 ), nullValue ());
83+ }
5184}
0 commit comments