-
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 and compressed tests for bugs
- Loading branch information
Showing
9 changed files
with
92 additions
and
205 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.quackery.contract; | ||
|
||
import static java.util.Arrays.asList; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Bugs { | ||
public static List<Class<?>> bugs(Class<?> model, Class<?>... contract) { | ||
List<Class<?>> bugs = new ArrayList<>(); | ||
for (Class<?> bug : model.getDeclaredClasses()) { | ||
if (unorderedEquals(bug.getAnnotation(Bug.class).value(), contract)) { | ||
bugs.add(bug); | ||
} | ||
} | ||
return bugs; | ||
} | ||
|
||
private static <T> boolean unorderedEquals(T[] arrayA, T[] arrayB) { | ||
List<T> listA = asList(arrayA); | ||
List<T> listB = asList(arrayB); | ||
return listA.containsAll(listB) && listB.containsAll(listA); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
65 changes: 65 additions & 0 deletions
65
test/java/org/quackery/contract/collection/test_MutableList.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,65 @@ | ||
package org.quackery.contract.collection; | ||
|
||
import static org.quackery.Contracts.quacksLike; | ||
import static org.quackery.contract.Bugs.bugs; | ||
import static org.quackery.testing.Assertions.assertFailure; | ||
import static org.quackery.testing.Assertions.assertSuccess; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
import org.quackery.Contract; | ||
|
||
public class test_MutableList { | ||
private final Class<?> model = MutableList.class; | ||
private Contract<Class<?>> contract; | ||
|
||
public void quacks_like_collection() { | ||
contract = quacksLike(Collection.class); | ||
assertSuccess(contract.test(model)); | ||
for (Class<?> bug : bugs(model, Collection.class)) { | ||
assertFailure(contract.test(bug)); | ||
} | ||
} | ||
|
||
public void quacks_like_mutable_collection() { | ||
contract = quacksLike(Collection.class).mutable(); | ||
assertSuccess(contract.test(model)); | ||
for (Class<?> bug : join( | ||
bugs(model, Collection.class), | ||
bugs(model, Collection.class, Mutable.class))) { | ||
assertFailure(contract.test(bug)); | ||
} | ||
} | ||
|
||
public void quacks_like_list() { | ||
contract = quacksLike(List.class); | ||
assertSuccess(contract.test(model)); | ||
for (Class<?> bug : join( | ||
bugs(model, Collection.class), | ||
bugs(model, List.class))) { | ||
assertFailure(contract.test(bug)); | ||
} | ||
} | ||
|
||
public void quacks_like_mutable_list() { | ||
contract = quacksLike(List.class).mutable(); | ||
assertSuccess(contract.test(model)); | ||
for (Class<?> bug : join( | ||
bugs(model, Collection.class), | ||
bugs(model, Collection.class, Mutable.class), | ||
bugs(model, List.class), | ||
bugs(model, List.class, Mutable.class))) { | ||
assertFailure(contract.test(bug)); | ||
} | ||
} | ||
|
||
private static List<Class<?>> join(List<Class<?>>... parts) { | ||
List<Class<?>> joined = new ArrayList<>(); | ||
for (List<Class<?>> part : parts) { | ||
joined.addAll(part); | ||
} | ||
return joined; | ||
} | ||
} |
27 changes: 0 additions & 27 deletions
27
test/java/org/quackery/contract/collection/test_contract_for_collection.java
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
test/java/org/quackery/contract/collection/test_contract_for_collection_mutable.java
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
test/java/org/quackery/contract/collection/test_contract_for_list.java
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
test/java/org/quackery/contract/collection/test_contract_for_list_mutable.java
This file was deleted.
Oops, something went wrong.
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