-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from kalarani-tw/issue-114-default-package
Improve automated test coverage #114 - Add test for classes in default package
- Loading branch information
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/test/java/org/jenkinsci/plugins/badge/JobBadgeActionFactoryTest.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,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<? extends Action> 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)); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/test/java/org/jenkinsci/plugins/badge/ParameterResolverTest.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,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)); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/test/java/org/jenkinsci/plugins/badge/RunBadgeActionFactoryTest.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,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<? extends Action> 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)); | ||
} | ||
} |