diff --git a/src/main/java/hudson/plugins/git/extensions/impl/PruneStaleTag.java b/src/main/java/hudson/plugins/git/extensions/impl/PruneStaleTag.java index 74537d808b..70815d5dbe 100644 --- a/src/main/java/hudson/plugins/git/extensions/impl/PruneStaleTag.java +++ b/src/main/java/hudson/plugins/git/extensions/impl/PruneStaleTag.java @@ -58,7 +58,7 @@ public class PruneStaleTag extends GitSCMExtension { private static final String TAG_REF = "refs/tags/"; - private boolean pruneTags; + private final boolean pruneTags; /** * Control pruning of tags that exist in the local repository but @@ -158,7 +158,7 @@ public int hashCode() { */ @Override public String toString() { - return "PruneStaleTag {}"; + return "PruneStaleTag { " + pruneTags + " }"; } @Symbol("pruneTags") diff --git a/src/test/java/hudson/plugins/git/extensions/impl/PruneStaleTagTest.java b/src/test/java/hudson/plugins/git/extensions/impl/PruneStaleTagTest.java index 90db6f48f2..a6e071917d 100644 --- a/src/test/java/hudson/plugins/git/extensions/impl/PruneStaleTagTest.java +++ b/src/test/java/hudson/plugins/git/extensions/impl/PruneStaleTagTest.java @@ -31,6 +31,7 @@ import java.util.logging.Level; import java.util.logging.Logger; +import nl.jqno.equalsverifier.EqualsVerifier; import org.apache.commons.io.FileUtils; import org.jenkinsci.plugins.gitclient.GitClient; import org.jenkinsci.plugins.gitclient.TestCliGitAPIImpl; @@ -40,6 +41,10 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; + import hudson.EnvVars; import hudson.Functions; import hudson.model.Run; @@ -230,4 +235,50 @@ private GitClient initRepository(File workspace) throws Exception { return remoteClient; } + @Test + public void testGetPruneTags() { + PruneStaleTag pruneEnabled = new PruneStaleTag(true); + assertThat(pruneEnabled.getPruneTags(), is(true)); + } + + @Test + public void testGetPruneTagsDisabled() { + PruneStaleTag pruneEnabled = new PruneStaleTag(false); + assertThat(pruneEnabled.getPruneTags(), is(false)); + } + + @Test + public void testEquals() { + EqualsVerifier.forClass(PruneStaleTag.class).usingGetClass().verify(); + } + + @Test + public void testHashCode() { + PruneStaleTag enabledOne = new PruneStaleTag(true); + PruneStaleTag enabledTwo = new PruneStaleTag(true); + assertThat(enabledOne.equals(enabledTwo), is(true)); + assertThat(enabledTwo.equals(enabledOne), is(true)); + assertThat(enabledOne.hashCode(), is(enabledTwo.hashCode())); + + PruneStaleTag disabledOne = new PruneStaleTag(false); + PruneStaleTag disabledTwo = new PruneStaleTag(false); + assertThat(disabledOne.equals(disabledTwo), is(true)); + assertThat(disabledTwo.equals(disabledOne), is(true)); + assertThat(disabledOne.hashCode(), is(disabledTwo.hashCode())); + + // Not required by hashCode contract, expected in this case + assertThat(enabledOne.hashCode(), not(is(disabledOne.hashCode()))); + } + + @Test + public void testToString() { + PruneStaleTag enabled = new PruneStaleTag(true); + assertThat(enabled.toString(), is("PruneStaleTag { true }")); + } + + @Test + public void testToStringDisabled() { + PruneStaleTag disabled = new PruneStaleTag(false); + assertThat(disabled.toString(), is("PruneStaleTag { false }")); + } }