-
Notifications
You must be signed in to change notification settings - Fork 402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parameterise "StatusCounter" tests (#973) #979
Open
ghostcity
wants to merge
2
commits into
damianszczepanik:master
Choose a base branch
from
informaticum:973_parameterise_statuscounter_tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
197 changes: 126 additions & 71 deletions
197
src/test/java/net/masterthought/cucumber/json/support/comparators/StatusCounterTest.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 |
---|---|---|
@@ -1,151 +1,206 @@ | ||
package net.masterthought.cucumber.json.support.comparators; | ||
|
||
import static java.util.Arrays.asList; | ||
import static java.util.Arrays.stream; | ||
import static java.util.Collections.emptySet; | ||
import static java.util.Collections.singleton; | ||
import static java.util.stream.Collectors.toSet; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Collections; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
import org.junit.Test; | ||
|
||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.junit.runners.Parameterized.Parameter; | ||
import org.junit.runners.Parameterized.Parameters; | ||
import net.masterthought.cucumber.json.support.Resultsable; | ||
import net.masterthought.cucumber.json.support.ResultsableBuilder; | ||
import net.masterthought.cucumber.json.support.Status; | ||
import net.masterthought.cucumber.json.support.StatusCounter; | ||
|
||
/** | ||
* @author Damian Szczepanik (damianszczepanik@github) | ||
* @author <a href="https://github.com/ghostcity">Stefan Gasterstädt</a> | ||
*/ | ||
@RunWith(Parameterized.class) | ||
public class StatusCounterTest { | ||
|
||
@Test | ||
public void StatusCounter_OnFailingStatuses_IncrementsPassing() { | ||
@Parameters(name = "{5} by {6}") | ||
public static Iterable<Object[]> data() { | ||
return asList(new Object[][] { | ||
{ 0, 0, 0, 0, 0, Status.PASSED, asList() }, | ||
{ 1, 0, 0, 0, 0, Status.PASSED, asList(Status.PASSED) }, | ||
{ 0, 1, 0, 0, 0, Status.FAILED, asList(Status.FAILED) }, | ||
{ 0, 0, 1, 0, 0, Status.FAILED, asList(Status.SKIPPED) }, | ||
{ 0, 0, 0, 1, 0, Status.FAILED, asList(Status.PENDING) }, | ||
{ 0, 0, 0, 0, 1, Status.FAILED, asList(Status.UNDEFINED) }, | ||
{ 2, 0, 0, 0, 0, Status.PASSED, asList(Status.PASSED, Status.PASSED) }, | ||
{ 1, 1, 0, 0, 0, Status.FAILED, asList(Status.PASSED, Status.FAILED) }, | ||
{ 1, 0, 1, 0, 0, Status.FAILED, asList(Status.PASSED, Status.SKIPPED) }, | ||
{ 1, 0, 0, 1, 0, Status.FAILED, asList(Status.PASSED, Status.PENDING) }, | ||
{ 1, 0, 0, 0, 1, Status.FAILED, asList(Status.PASSED, Status.UNDEFINED) }, | ||
{ 3, 0, 0, 0, 0, Status.PASSED, asList(Status.PASSED, Status.PASSED, Status.PASSED) }, | ||
{ 2, 1, 0, 0, 0, Status.FAILED, asList(Status.PASSED, Status.FAILED, Status.PASSED) }, | ||
{ 2, 0, 1, 0, 0, Status.FAILED, asList(Status.PASSED, Status.SKIPPED, Status.PASSED) }, | ||
{ 2, 0, 0, 1, 0, Status.FAILED, asList(Status.PASSED, Status.PENDING, Status.PASSED) }, | ||
{ 2, 0, 0, 0, 1, Status.FAILED, asList(Status.PASSED, Status.UNDEFINED, Status.PASSED) }, | ||
{ 1, 2, 0, 0, 0, Status.FAILED, asList(Status.PASSED, Status.FAILED, Status.FAILED) }, | ||
{ 1, 1, 1, 0, 0, Status.FAILED, asList(Status.PASSED, Status.FAILED, Status.SKIPPED) }, | ||
{ 1, 1, 0, 1, 0, Status.FAILED, asList(Status.PASSED, Status.FAILED, Status.PENDING) }, | ||
{ 1, 1, 0, 0, 1, Status.FAILED, asList(Status.PASSED, Status.FAILED, Status.UNDEFINED) }, | ||
}); | ||
} | ||
|
||
// given | ||
Resultsable[] resultsables = ResultsableBuilder.Resultsable(Status.PASSED, Status.FAILED, Status.SKIPPED); | ||
@Parameter(0) | ||
public int passedCounter; | ||
|
||
// when | ||
StatusCounter statusCounter = new StatusCounter(resultsables, Collections.singleton(Status.SKIPPED)); | ||
@Parameter(1) | ||
public int failedCounter; | ||
|
||
// then | ||
assertThat(statusCounter.getValueFor(Status.PASSED)).isEqualTo(2); | ||
assertThat(statusCounter.getValueFor(Status.FAILED)).isOne(); | ||
assertThat(statusCounter.getValueFor(Status.SKIPPED)).isZero(); | ||
} | ||
@Parameter(2) | ||
public int skippedCounter; | ||
|
||
@Test | ||
public void StatusCounter_OnNullFailingStatuses_IncrementsPassing() { | ||
@Parameter(3) | ||
public int pendingCounter; | ||
|
||
// given | ||
Resultsable[] resultsables = ResultsableBuilder.Resultsable(Status.PASSED, Status.FAILED, Status.SKIPPED); | ||
@Parameter(4) | ||
public int undefinedCounter; | ||
|
||
// when | ||
StatusCounter statusCounter = new StatusCounter(resultsables, null); | ||
@Parameter(5) | ||
public Status finalStatus; | ||
|
||
// then | ||
assertThat(statusCounter.getValueFor(Status.PASSED)).isOne(); | ||
assertThat(statusCounter.getValueFor(Status.FAILED)).isOne(); | ||
assertThat(statusCounter.getValueFor(Status.SKIPPED)).isOne(); | ||
} | ||
@Parameter(6) | ||
public List<Status> statuses; | ||
|
||
@Test | ||
public void StatusCounter_OnEmptyFailingStatuses_IncrementsPassing() { | ||
|
||
public void StatusCounter_OnNoneNotFailingStatuses() { | ||
// given | ||
Resultsable[] resultsables = ResultsableBuilder.Resultsable(Status.PASSED, Status.FAILED, Status.SKIPPED); | ||
Resultsable[] resultsables = ResultsableBuilder.Resultsable(this.statuses.toArray(new Status[0])); | ||
|
||
// when | ||
StatusCounter statusCounter = new StatusCounter(resultsables); | ||
|
||
// then | ||
assertThat(statusCounter.getValueFor(Status.PASSED)).isOne(); | ||
assertThat(statusCounter.getValueFor(Status.FAILED)).isOne(); | ||
assertThat(statusCounter.getValueFor(Status.SKIPPED)).isOne(); | ||
assertThat(statusCounter.size()).isEqualTo(this.passedCounter + this.failedCounter + this.skippedCounter + this.pendingCounter + this.undefinedCounter); | ||
assertThat(statusCounter.getValueFor(Status.PASSED)).isEqualTo(this.passedCounter); | ||
assertThat(statusCounter.getValueFor(Status.FAILED)).isEqualTo(this.failedCounter); | ||
assertThat(statusCounter.getValueFor(Status.SKIPPED)).isEqualTo(this.skippedCounter); | ||
assertThat(statusCounter.getValueFor(Status.PENDING)).isEqualTo(this.pendingCounter); | ||
assertThat(statusCounter.getValueFor(Status.UNDEFINED)).isEqualTo(this.undefinedCounter); | ||
assertThat(statusCounter.getFinalStatus()).isEqualTo(this.finalStatus); | ||
} | ||
|
||
@Test | ||
public void getValueFor_ReturnsStatusCounter() { | ||
|
||
public void StatusCounter_OnNullNotFailingStatuses() { | ||
// given | ||
StatusCounter statusCounter = new StatusCounter(); | ||
Resultsable[] resultsables = ResultsableBuilder.Resultsable(this.statuses.toArray(new Status[0])); | ||
|
||
// when | ||
statusCounter.incrementFor(Status.PASSED); | ||
statusCounter.incrementFor(Status.PASSED); | ||
statusCounter.incrementFor(Status.PASSED); | ||
StatusCounter statusCounter = new StatusCounter(resultsables, null); | ||
|
||
// then | ||
assertThat(statusCounter.getValueFor(Status.PASSED)).isEqualTo(3); | ||
assertThat(statusCounter.getValueFor(Status.FAILED)).isZero(); | ||
assertThat(statusCounter.getValueFor(Status.UNDEFINED)).isZero(); | ||
assertThat(statusCounter.getValueFor(Status.PENDING)).isZero(); | ||
assertThat(statusCounter.getValueFor(Status.SKIPPED)).isZero(); | ||
assertThat(statusCounter.size()).isEqualTo(this.passedCounter + this.failedCounter + this.skippedCounter + this.pendingCounter + this.undefinedCounter); | ||
assertThat(statusCounter.getValueFor(Status.PASSED)).isEqualTo(this.passedCounter); | ||
assertThat(statusCounter.getValueFor(Status.FAILED)).isEqualTo(this.failedCounter); | ||
assertThat(statusCounter.getValueFor(Status.SKIPPED)).isEqualTo(this.skippedCounter); | ||
assertThat(statusCounter.getValueFor(Status.PENDING)).isEqualTo(this.pendingCounter); | ||
assertThat(statusCounter.getValueFor(Status.UNDEFINED)).isEqualTo(this.undefinedCounter); | ||
assertThat(statusCounter.getFinalStatus()).isEqualTo(this.finalStatus); | ||
} | ||
|
||
@Test | ||
public void size_ReturnsAllStatusCounter() { | ||
|
||
public void StatusCounter_OnEmptyNotFailingStatuses() { | ||
// given | ||
StatusCounter statusCounter = new StatusCounter(); | ||
Resultsable[] resultsables = ResultsableBuilder.Resultsable(this.statuses.toArray(new Status[0])); | ||
|
||
// when | ||
statusCounter.incrementFor(Status.PASSED); | ||
statusCounter.incrementFor(Status.FAILED); | ||
StatusCounter statusCounter = new StatusCounter(resultsables, emptySet()); | ||
|
||
// then | ||
assertThat(statusCounter.size()).isEqualTo(2); | ||
assertThat(statusCounter.size()).isEqualTo(this.passedCounter + this.failedCounter + this.skippedCounter + this.pendingCounter + this.undefinedCounter); | ||
assertThat(statusCounter.getValueFor(Status.PASSED)).isEqualTo(this.passedCounter); | ||
assertThat(statusCounter.getValueFor(Status.FAILED)).isEqualTo(this.failedCounter); | ||
assertThat(statusCounter.getValueFor(Status.SKIPPED)).isEqualTo(this.skippedCounter); | ||
assertThat(statusCounter.getValueFor(Status.PENDING)).isEqualTo(this.pendingCounter); | ||
assertThat(statusCounter.getValueFor(Status.UNDEFINED)).isEqualTo(this.undefinedCounter); | ||
assertThat(statusCounter.getFinalStatus()).isEqualTo(this.finalStatus); | ||
} | ||
|
||
@Test | ||
public void getFinalStatus_WithNoStatuses_ReturnsPass() { | ||
|
||
public void StatusCounter_OnSkippedNotFailingStatuses() { | ||
// given | ||
StatusCounter statusCounter = new StatusCounter(); | ||
Resultsable[] resultsables = ResultsableBuilder.Resultsable(this.statuses.toArray(new Status[0])); | ||
Set<Status> notFailingStatuses = singleton(Status.SKIPPED); | ||
|
||
// when | ||
Status status = statusCounter.getFinalStatus(); | ||
StatusCounter statusCounter = new StatusCounter(resultsables, notFailingStatuses); | ||
|
||
// then | ||
assertThat(status).isEqualTo(Status.PASSED); | ||
assertThat(statusCounter.size()).isEqualTo(this.passedCounter + this.failedCounter + this.skippedCounter + this.pendingCounter + this.undefinedCounter); | ||
assertThat(statusCounter.getValueFor(Status.PASSED)).isEqualTo(this.passedCounter + this.skippedCounter); | ||
assertThat(statusCounter.getValueFor(Status.FAILED)).isEqualTo(this.failedCounter); | ||
assertThat(statusCounter.getValueFor(Status.SKIPPED)).isZero(); | ||
assertThat(statusCounter.getValueFor(Status.PENDING)).isEqualTo(this.pendingCounter); | ||
assertThat(statusCounter.getValueFor(Status.UNDEFINED)).isEqualTo(this.undefinedCounter); | ||
} | ||
|
||
@Test | ||
public void getFinalStatus_OnSameStatuses_ReturnsThatStatus() { | ||
|
||
public void StatusCounter_OnNonPassedNotFailingStatuses() { | ||
// given | ||
StatusCounter statusCounter = new StatusCounter(); | ||
Resultsable[] resultsables = ResultsableBuilder.Resultsable(this.statuses.toArray(new Status[0])); | ||
Set<Status> notFailingStatuses = Stream.of(Status.FAILED, Status.SKIPPED, Status.PENDING, Status.UNDEFINED).collect(toSet()); | ||
|
||
// when | ||
statusCounter.incrementFor(Status.PASSED); | ||
statusCounter.incrementFor(Status.PASSED); | ||
StatusCounter statusCounter = new StatusCounter(resultsables, notFailingStatuses); | ||
|
||
// then | ||
assertThat(statusCounter.size()).isEqualTo(this.passedCounter + this.failedCounter + this.skippedCounter + this.pendingCounter + this.undefinedCounter); | ||
assertThat(statusCounter.getValueFor(Status.PASSED)).isEqualTo(this.passedCounter + this.failedCounter + this.skippedCounter + this.pendingCounter + this.undefinedCounter); | ||
assertThat(statusCounter.getValueFor(Status.FAILED)).isZero(); | ||
assertThat(statusCounter.getValueFor(Status.SKIPPED)).isZero(); | ||
assertThat(statusCounter.getValueFor(Status.PENDING)).isZero(); | ||
assertThat(statusCounter.getValueFor(Status.UNDEFINED)).isZero(); | ||
assertThat(statusCounter.getFinalStatus()).isEqualTo(Status.PASSED); | ||
} | ||
|
||
@Test | ||
public void getFinalStatus_OnDifferentStatuses_ReturnsFailedStatus() { | ||
|
||
public void StatusCounter_OnAllNotFailingStatuses() { | ||
// given | ||
StatusCounter statusCounter = new StatusCounter(); | ||
Resultsable[] resultsables = ResultsableBuilder.Resultsable(this.statuses.toArray(new Status[0])); | ||
Set<Status> notFailingStatuses = stream(Status.values()).collect(toSet()); | ||
|
||
// when | ||
statusCounter.incrementFor(Status.PASSED); | ||
statusCounter.incrementFor(Status.UNDEFINED); | ||
StatusCounter statusCounter = new StatusCounter(resultsables, notFailingStatuses); | ||
|
||
// then | ||
assertThat(statusCounter.getFinalStatus()).isEqualTo(Status.FAILED); | ||
assertThat(statusCounter.size()).isEqualTo(this.passedCounter + this.failedCounter + this.skippedCounter + this.pendingCounter + this.undefinedCounter); | ||
assertThat(statusCounter.getValueFor(Status.PASSED)).isEqualTo(this.passedCounter + this.failedCounter + this.skippedCounter + this.pendingCounter + this.undefinedCounter); | ||
assertThat(statusCounter.getValueFor(Status.FAILED)).isZero(); | ||
assertThat(statusCounter.getValueFor(Status.SKIPPED)).isZero(); | ||
assertThat(statusCounter.getValueFor(Status.PENDING)).isZero(); | ||
assertThat(statusCounter.getValueFor(Status.UNDEFINED)).isZero(); | ||
assertThat(statusCounter.getFinalStatus()).isEqualTo(Status.PASSED); | ||
} | ||
|
||
@Test | ||
public void getFinalStatus_OnFailedStatus_ReturnsFailedStatus() { | ||
|
||
public void StatusCounter_OnIncrementFor() { | ||
// given | ||
StatusCounter statusCounter = new StatusCounter(); | ||
|
||
// when | ||
statusCounter.incrementFor(Status.PASSED); | ||
statusCounter.incrementFor(Status.FAILED); | ||
for (Status status : this.statuses) { | ||
statusCounter.incrementFor(status); | ||
} | ||
|
||
// then | ||
assertThat(statusCounter.getFinalStatus()).isEqualTo(Status.FAILED); | ||
} | ||
assertThat(statusCounter.size()).isEqualTo(this.passedCounter + this.failedCounter + this.skippedCounter + this.pendingCounter + this.undefinedCounter); | ||
assertThat(statusCounter.getValueFor(Status.PASSED)).isEqualTo(this.passedCounter); | ||
assertThat(statusCounter.getValueFor(Status.FAILED)).isEqualTo(this.failedCounter); | ||
assertThat(statusCounter.getValueFor(Status.SKIPPED)).isEqualTo(this.skippedCounter); | ||
assertThat(statusCounter.getValueFor(Status.PENDING)).isEqualTo(this.pendingCounter); | ||
assertThat(statusCounter.getValueFor(Status.UNDEFINED)).isEqualTo(this.undefinedCounter); | ||
assertThat(statusCounter.getFinalStatus()).isEqualTo(this.finalStatus); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice but rather not very efficient if size() is invoked often and report is big