-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests for condition based on build description
Request #128
- Loading branch information
1 parent
3c860bd
commit dbc3985
Showing
3 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...ik/jenkins/buildhistorymanager/descriptors/conditions/BuildDescriptionDescriptorTest.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,52 @@ | ||
package pl.damianszczepanik.jenkins.buildhistorymanager.descriptors.conditions; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import hudson.model.AbstractDescribableImpl; | ||
import hudson.model.Descriptor; | ||
import hudson.util.ListBoxModel; | ||
import org.jenkinsci.plugins.structs.SymbolLookup; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import pl.damianszczepanik.jenkins.buildhistorymanager.model.conditions.BuildDescriptionCondition.MatchingMethodType; | ||
|
||
/** | ||
* @author Damian Szczepanik (damianszczepanik@github) | ||
*/ | ||
public class BuildDescriptionDescriptorTest { | ||
|
||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
@Test | ||
public void doFillMatchingMethodItems_ReturnsMethodItems() { | ||
|
||
// given | ||
BuildDescriptionDescriptor descriptor = (BuildDescriptionDescriptor) | ||
SymbolLookup.get().findDescriptor(AbstractDescribableImpl.class, "BuildDescription"); | ||
|
||
// when | ||
ListBoxModel listBoxModel = descriptor.doFillMatchingMethodItems(); | ||
|
||
// then | ||
assertThat(listBoxModel.stream().map(option -> option.value)) | ||
.containsExactly( | ||
MatchingMethodType.EQUALS.name(), | ||
MatchingMethodType.CONTAINS.name(), | ||
MatchingMethodType.MATCHES.name()); | ||
} | ||
|
||
@Test | ||
public void getDisplayName_ReturnsDescriptorName() { | ||
|
||
// given | ||
Descriptor descriptor = SymbolLookup.get().findDescriptor(AbstractDescribableImpl.class, "BuildDescription"); | ||
|
||
// when | ||
String displayName = descriptor.getDisplayName(); | ||
|
||
// then | ||
assertThat(displayName).isEqualTo("Build description"); | ||
} | ||
} |
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
124 changes: 124 additions & 0 deletions
124
...zczepanik/jenkins/buildhistorymanager/model/conditions/BuildDescriptionConditionTest.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,124 @@ | ||
package pl.damianszczepanik.jenkins.buildhistorymanager.model.conditions; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.IOException; | ||
|
||
import hudson.model.Run; | ||
import org.junit.Test; | ||
import pl.damianszczepanik.jenkins.buildhistorymanager.model.conditions.BuildDescriptionCondition.MatchingMethodType; | ||
import pl.damianszczepanik.jenkins.buildhistorymanager.utils.RunStub; | ||
|
||
/** | ||
* @author Damian Szczepanik (damianszczepanik@github) | ||
*/ | ||
public class BuildDescriptionConditionTest { | ||
|
||
@Test | ||
public void setPattern_SetsPattern() { | ||
|
||
// given | ||
BuildDescriptionCondition condition = new BuildDescriptionCondition(); | ||
String pattern = "[release] 22.0r5"; | ||
condition.setPattern(pattern); | ||
|
||
// when | ||
String returnedPattern = condition.getPattern(); | ||
|
||
// then | ||
assertThat(returnedPattern).isEqualTo(pattern); | ||
} | ||
|
||
@Test | ||
public void setMatchingMethod_SetsMatchingMethod() { | ||
|
||
// given | ||
BuildDescriptionCondition condition = new BuildDescriptionCondition(); | ||
MatchingMethodType matchingMethodType = MatchingMethodType.CONTAINS; | ||
|
||
// make sure that default matching method is not same | ||
// as the one used by this test | ||
assertThat(condition.getMatchingMethod()).isNotEqualTo(matchingMethodType.name()); | ||
condition.setMatchingMethod(matchingMethodType.name()); | ||
|
||
// when | ||
String returnedMethodType = condition.getMatchingMethod(); | ||
|
||
// then | ||
assertThat(returnedMethodType).isEqualTo(matchingMethodType.name()); | ||
} | ||
|
||
@Test | ||
public void matches_OnEqualDescription_ReturnsTrue() throws IOException { | ||
|
||
// given | ||
BuildDescriptionCondition condition = new BuildDescriptionCondition(); | ||
condition.setMatchingMethod(MatchingMethodType.EQUALS.name()); | ||
final String description = "[release] 11.3.4.1"; | ||
condition.setPattern(description); | ||
|
||
Run<?, ?> run = new RunStub(); | ||
run.setDescription(description); | ||
|
||
// when | ||
boolean matches = condition.matches(run, null); | ||
|
||
// then | ||
assertThat(matches).isTrue(); | ||
} | ||
|
||
@Test | ||
public void matches_OnLongerDescription_ReturnsTrue() throws IOException { | ||
|
||
// given | ||
BuildDescriptionCondition condition = new BuildDescriptionCondition(); | ||
condition.setMatchingMethod(MatchingMethodType.CONTAINS.name()); | ||
final String description = "[release] 1987.3.14"; | ||
condition.setPattern(description); | ||
|
||
Run<?, ?> run = new RunStub(); | ||
run.setDescription(description + "some extra description"); | ||
|
||
// when | ||
boolean matches = condition.matches(run, null); | ||
|
||
// then | ||
assertThat(matches).isTrue(); | ||
} | ||
|
||
@Test | ||
public void matches_OnMatchedDescription_ReturnsTrue() throws IOException { | ||
|
||
// given | ||
BuildDescriptionCondition condition = new BuildDescriptionCondition(); | ||
condition.setMatchingMethod(MatchingMethodType.MATCHES.name()); | ||
final String description = "[release] 11.3.4"; | ||
condition.setPattern(".*release.*"); | ||
|
||
Run<?, ?> run = new RunStub(); | ||
run.setDescription(description + "some extra description"); | ||
|
||
// when | ||
boolean matches = condition.matches(run, null); | ||
|
||
// then | ||
assertThat(matches).isTrue(); | ||
} | ||
|
||
@Test | ||
public void matches_OnNullDescription_ReturnsFalse() throws IOException { | ||
|
||
// given | ||
BuildDescriptionCondition condition = new BuildDescriptionCondition(); | ||
|
||
Run<?, ?> run = new RunStub(); | ||
run.setDescription(null); | ||
|
||
// when | ||
boolean matches = condition.matches(run, null); | ||
|
||
// then | ||
assertThat(matches).isFalse(); | ||
} | ||
|
||
} |