Skip to content

Commit

Permalink
Merge pull request #875 from MarkEWaite/add-prune-stale-tags-tests
Browse files Browse the repository at this point in the history
Add more prune stale tags tests
  • Loading branch information
MarkEWaite authored Apr 18, 2020
2 parents 54aa14a + 6eb08b4 commit aa09dfd
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -158,7 +158,7 @@ public int hashCode() {
*/
@Override
public String toString() {
return "PruneStaleTag {}";
return "PruneStaleTag { " + pruneTags + " }";
}

@Symbol("pruneTags")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 }"));
}
}

0 comments on commit aa09dfd

Please sign in to comment.