-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Theories: only get all data points from enum and boolean types if the… #1651
Open
awturner
wants to merge
3
commits into
junit-team:main
Choose a base branch
from
awturner:master
base: main
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
3 commits
Select commit
Hold shift + click to select a range
0828f45
Theories: only get all data points from enum and boolean types if the…
awturner 180142f
Update src/main/java/org/junit/experimental/theories/internal/Assignm…
awturner cfcb3f1
Update src/main/java/org/junit/experimental/theories/internal/Assignm…
awturner 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
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
83 changes: 83 additions & 0 deletions
83
...va/org/junit/tests/experimental/theories/runner/WhenNoParametersMatchEnumeratedTypes.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,83 @@ | ||
package org.junit.tests.experimental.theories.runner; | ||
|
||
import static org.junit.Assert.assertThat; | ||
import static org.junit.experimental.results.PrintableResult.testResult; | ||
import static org.junit.experimental.results.ResultMatchers.failureCountIs; | ||
import static org.junit.experimental.results.ResultMatchers.hasFailureContaining; | ||
import static org.junit.experimental.results.ResultMatchers.hasSingleFailureContaining; | ||
|
||
import org.junit.Test; | ||
import org.junit.experimental.results.PrintableResult; | ||
import org.junit.experimental.theories.DataPoints; | ||
import org.junit.experimental.theories.FromDataPoints; | ||
import org.junit.experimental.theories.Theories; | ||
import org.junit.experimental.theories.Theory; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
@RunWith(JUnit4.class) | ||
public class WhenNoParametersMatchEnumeratedTypes { | ||
public enum SomeEnum { | ||
FIRST, SECOND | ||
} | ||
|
||
@RunWith(Theories.class) | ||
public static class AssumptionsFailBoolean { | ||
@Theory | ||
public void shouldFailBecauseExplicitFromDataPointsNotKnown( | ||
@FromDataPoints("unknown") boolean b) {} | ||
|
||
@Theory | ||
public void shouldSucceedBecauseNoExplicitFromDataPoints(boolean b) {} | ||
} | ||
|
||
@Test | ||
public void showFailedAssumptionsWhenNoParametersFoundBoolean() { | ||
assertThat( | ||
testResult(AssumptionsFailBoolean.class), | ||
hasSingleFailureContaining( | ||
"Never found parameters that satisfied method assumptions")); | ||
} | ||
|
||
@RunWith(Theories.class) | ||
public static class AssumptionsFailEnum { | ||
@Theory | ||
public void shouldFailBecauseExplicitFromDataPointsNotKnown( | ||
@FromDataPoints("unknown") SomeEnum e) {} | ||
|
||
@Theory | ||
public void shouldSucceedBecauseNoExplicitFromDataPoints(SomeEnum e) {} | ||
} | ||
|
||
@Test | ||
public void showFailedAssumptionsWhenNoParametersFoundEnum() { | ||
assertThat( | ||
testResult(AssumptionsFailEnum.class), | ||
hasSingleFailureContaining( | ||
"Never found parameters that satisfied method assumptions")); | ||
} | ||
|
||
@RunWith(Theories.class) | ||
public static class AssumptionsFailWrongType { | ||
@DataPoints("known") public static final String[] known = {"known"}; | ||
|
||
@Theory | ||
public void shouldSucceedBecauseRightType(@FromDataPoints("known") String s) {} | ||
|
||
@Theory | ||
public void shouldFailBecauseWrongTypeBoolean(@FromDataPoints("known") boolean b) {} | ||
|
||
@Theory | ||
public void shouldFailBecauseWrongTypeEnum(@FromDataPoints("known") SomeEnum e) {} | ||
} | ||
|
||
@Test | ||
public void showFailedAssumptionsWhenWrongType() { | ||
PrintableResult result = testResult(AssumptionsFailWrongType.class); | ||
assertThat(result, failureCountIs(2)); | ||
assertThat( | ||
result, | ||
hasFailureContaining( | ||
"Never found parameters that satisfied method assumptions")); | ||
} | ||
} |
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.
❓ Shouldn't this check for
ParametersSuppliedBy
or, alternatively, shouldn'tSpecificDataPointsSupplier
throw an exception if it couldn't find a matching field?