diff --git a/src/test/java/org/jenkinsci/plugins/badge/JobBadgeActionFactoryTest.java b/src/test/java/org/jenkinsci/plugins/badge/JobBadgeActionFactoryTest.java new file mode 100644 index 000000000..ab0f77098 --- /dev/null +++ b/src/test/java/org/jenkinsci/plugins/badge/JobBadgeActionFactoryTest.java @@ -0,0 +1,38 @@ +package org.jenkinsci.plugins.badge; + +import hudson.model.Action; +import hudson.model.Job; +import org.hamcrest.core.Is; +import org.jenkinsci.plugins.badge.actions.JobBadgeAction; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import java.io.IOException; +import java.util.Collection; + +import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +class JobBadgeActionFactoryTest { + + private JobBadgeActionFactory factory; + + @BeforeEach + void setUp() throws IOException { + factory = new JobBadgeActionFactory(); + } + + @Test + void shouldCreateJobBadgeAction() { + Collection action = factory.createFor(Mockito.mock(Job.class)); + assertThat(action.size(), is(1)); + assertThat(action.stream().findFirst().get(), instanceOf(JobBadgeAction.class)); + } + + @Test + void shouldBeForJobType() { + assertThat(factory.type(), is(Job.class)); + } +} \ No newline at end of file diff --git a/src/test/java/org/jenkinsci/plugins/badge/ParameterResolverTest.java b/src/test/java/org/jenkinsci/plugins/badge/ParameterResolverTest.java new file mode 100644 index 000000000..3a7fa5ec3 --- /dev/null +++ b/src/test/java/org/jenkinsci/plugins/badge/ParameterResolverTest.java @@ -0,0 +1,22 @@ +package org.jenkinsci.plugins.badge; + +import hudson.model.Actionable; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.mockito.Mockito; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +class ParameterResolverTest { + @ParameterizedTest + @CsvSource({ + "Build ${params.BUILD_BRANCH},Build params.BUILD_BRANCH", + "Build ${params.BUILD_BRANCH|master},Build params.BUILD_BRANCH|master", + "Build ${params.BUILD_BRANCH|master} (${displayName}),Build params.BUILD_BRANCH|master (displayName)" + }) + void shouldResolveSubjectWithVariables(String queryParameter, String expectedParameter) { + String resolvedParameter = new ParameterResolver().resolve(Mockito.mock(Actionable.class), queryParameter); + assertThat(resolvedParameter, is(expectedParameter)); + } +} \ No newline at end of file diff --git a/src/test/java/org/jenkinsci/plugins/badge/RunBadgeActionFactoryTest.java b/src/test/java/org/jenkinsci/plugins/badge/RunBadgeActionFactoryTest.java new file mode 100644 index 000000000..325607307 --- /dev/null +++ b/src/test/java/org/jenkinsci/plugins/badge/RunBadgeActionFactoryTest.java @@ -0,0 +1,39 @@ +package org.jenkinsci.plugins.badge; + +import hudson.model.Action; +import hudson.model.Job; +import hudson.model.Run; +import org.jenkinsci.plugins.badge.actions.JobBadgeAction; +import org.jenkinsci.plugins.badge.actions.RunBadgeAction; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import java.io.IOException; +import java.util.Collection; + +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +class RunBadgeActionFactoryTest { + + private RunBadgeActionFactory factory; + + @BeforeEach + void setUp() throws IOException { + factory = new RunBadgeActionFactory(); + } + + @Test + void shouldCreateJobBadgeAction() { + Collection action = factory.createFor(Mockito.mock(Run.class)); + assertThat(action.size(), is(1)); + assertThat(action.stream().findFirst().get(), instanceOf(RunBadgeAction.class)); + } + + @Test + void shouldBeForJobType() { + assertThat(factory.type(), is(Run.class)); + } +} \ No newline at end of file