-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reorganized test hierarchy in collection contract
- Loading branch information
Showing
6 changed files
with
168 additions
and
107 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.quackery.contract.collection; | ||
|
||
import static org.quackery.Suite.suite; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.quackery.Case; | ||
import org.quackery.Suite; | ||
import org.quackery.Test; | ||
|
||
public class Flags { | ||
public static Test onlyIf(boolean condition, Test test) { | ||
return condition | ||
? test | ||
: suite(""); | ||
} | ||
|
||
public static Test clean(Test test) { | ||
return test instanceof Case | ||
? test | ||
: clean((Suite) test); | ||
} | ||
|
||
private static Test clean(Suite suite) { | ||
List<Test> cleanedChildren = new ArrayList<>(); | ||
for (Test child : suite.tests) { | ||
Test cleanChild = clean(child); | ||
if (!isEmptySuite(cleanChild)) { | ||
cleanedChildren.add(cleanChild); | ||
} | ||
} | ||
return suite(suite.name).testAll(cleanedChildren); | ||
} | ||
|
||
private static boolean isEmptySuite(Test test) { | ||
return test instanceof Suite && ((Suite) test).tests.isEmpty(); | ||
} | ||
} |
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
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
Oops, something went wrong.