Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests to SpecialValueParameterResolverExtensionTest #349

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.nullValue;
import static org.mockito.Mockito.when;

import hudson.model.Job;
Expand Down Expand Up @@ -73,4 +74,31 @@ void testMultipleParameters() {
extension.resolve(mockRun, "buildId buildNumber duration startTime displayName description");
assertThat(actualParameter, is("1234 1234 23:35 23:35 display name run description"));
}

@Test
void resolveEmptyStringParameter() {
String actualParameter = extension.resolve(mockRun, "");
assertThat(actualParameter, is(""));
}

@Test
void resolveWithNullParameter() {
String actualParameter = extension.resolve(mockRun, null);
assertThat(actualParameter, is(nullValue()));
}

@Test
void unknownParameterShouldNotBeResolved() {
String actualParameter = extension.resolve(mockRun, "unknown");
assertThat(actualParameter, is("unknown"));
}

@Test
void testResolveWhenJobHasNoLastBuild() {
Job<?, ?> job = Mockito.mock(Job.class);
when(job.getLastBuild()).thenReturn(null);

String parameter = "${buildId}${buildNumber}";
assertThat(extension.resolve(job, parameter), is(parameter));
}
}