Skip to content

Commit

Permalink
tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
pholser committed Nov 21, 2020
1 parent 440a2c8 commit 5a95e9f
Show file tree
Hide file tree
Showing 35 changed files with 583 additions and 215 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public class CallablePropertyParameterTest {
public static class CallableOfInt {
static int iterations;

@Property public void shouldHold(Callable<Integer> c) throws Exception {
@Property public void shouldHold(Callable<Integer> c)
throws Exception {

++iterations;

Integer value = functionValue(new IntegerGenerator(), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,18 @@ public static class RangedClock {
assertThat(
c.instant(),
allOf(
greaterThanOrEqualTo(Instant.parse("2012-01-01T00:00:00.0Z")),
lessThanOrEqualTo(Instant.parse("2012-12-31T23:59:59.999999999Z"))));
greaterThanOrEqualTo(
Instant.parse("2012-01-01T00:00:00.0Z")),
lessThanOrEqualTo(
Instant.parse("2012-12-31T23:59:59.999999999Z"))));
}
}

@Test public void malformedMin() {
assertThat(
testResult(MalformedMinClock.class),
hasSingleFailureContaining(DateTimeParseException.class.getName()));
hasSingleFailureContaining(
DateTimeParseException.class.getName()));
}

@RunWith(JUnitQuickcheck.class)
Expand All @@ -91,7 +94,8 @@ public static class MalformedMinClock {
@Test public void malformedMax() {
assertThat(
testResult(MalformedMaxClock.class),
hasSingleFailureContaining(DateTimeParseException.class.getName()));
hasSingleFailureContaining(
DateTimeParseException.class.getName()));
}

@RunWith(JUnitQuickcheck.class)
Expand All @@ -115,7 +119,8 @@ public static class MissingMin {

assertThat(
c.instant(),
lessThanOrEqualTo(Instant.parse("2012-12-31T23:59:59.999999999Z")));
lessThanOrEqualTo(
Instant.parse("2012-12-31T23:59:59.999999999Z")));
}
}

Expand All @@ -130,14 +135,16 @@ public static class MissingMax {

assertThat(
c.instant(),
greaterThanOrEqualTo(Instant.parse("2012-12-31T23:59:59.999999999Z")));
greaterThanOrEqualTo(
Instant.parse("2012-12-31T23:59:59.999999999Z")));
}
}

@Test public void backwardsRange() {
assertThat(
testResult(BackwardsRange.class),
hasSingleFailureContaining(DateTimeParseException.class.getName()));
hasSingleFailureContaining(
DateTimeParseException.class.getName()));
}

@RunWith(JUnitQuickcheck.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ a copy of this software and associated documentation files (the
import static org.junit.Assert.*;
import static org.junit.Assume.*;

public interface ComparableWithConsistentEqualsContract<T extends Comparable<T>> {
public interface
ComparableWithConsistentEqualsContract<T extends Comparable<T>> {
@Property default void equalsConsistency(T thing) {
T other = thingComparableTo(thing);
assumeThat(thing.compareTo(other), equalTo(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ a copy of this software and associated documentation files (the

public class ContractTestWithTypeVariableForPropertyParameterTest {
public static class TestObject {
private final String str;
private final String s;

public TestObject( String str ) {
this.str = str;
public TestObject(String s) {
this.s = s;
}

@Override public String toString() {
return str;
return s;
}
}

Expand All @@ -56,7 +56,10 @@ public G() {
super(TestObject.class);
}

@Override public TestObject generate(SourceOfRandomness r, GenerationStatus s) {
@Override public TestObject generate(
SourceOfRandomness r,
GenerationStatus s) {

return new TestObject("yermom");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ public static class DateProperty {
@RunWith(JUnitQuickcheck.class)
public static class RangedDate {
@Property public void shouldHold(
@InRange(min = "01/01/2012", max = "12/31/2012", format = "MM/dd/yyyy") Date d) throws Exception {
@InRange(
min = "01/01/2012",
max = "12/31/2012",
format = "MM/dd/yyyy")
Date d)
throws Exception {

SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
assertThat(
Expand All @@ -70,39 +75,54 @@ public static class RangedDate {
@Test public void malformedMin() {
assertThat(
testResult(MalformedMinDate.class),
hasSingleFailureContaining(IllegalArgumentException.class.getName()));
hasSingleFailureContaining(
IllegalArgumentException.class.getName()));
}

@RunWith(JUnitQuickcheck.class)
public static class MalformedMinDate {
@Property public void shouldHold(
@InRange(min = "@#!@#@", max = "12/31/2012", format = "MM/dd/yyyy") Date d) {
@InRange(
min = "@#!@#@",
max = "12/31/2012",
format = "MM/dd/yyyy")
Date d) {
}
}

@Test public void malformedMax() {
assertThat(
testResult(MalformedMaxDate.class),
hasSingleFailureContaining(IllegalArgumentException.class.getName()));
hasSingleFailureContaining(
IllegalArgumentException.class.getName()));
}

@RunWith(JUnitQuickcheck.class)
public static class MalformedMaxDate {
@Property public void shouldHold(
@InRange(min = "06/01/2011", max = "*&@^#%$", format = "MM/dd/yyyy") Date d) {
@InRange(
min = "06/01/2011",
max = "*&@^#%$",
format = "MM/dd/yyyy")
Date d) {
}
}

@Test public void malformedFormat() {
assertThat(
testResult(MalformedFormatDate.class),
hasSingleFailureContaining(IllegalArgumentException.class.getName()));
hasSingleFailureContaining(
IllegalArgumentException.class.getName()));
}

@RunWith(JUnitQuickcheck.class)
public static class MalformedFormatDate {
@Property public void shouldHold(
@InRange(min = "06/01/2011", max = "06/30/2011", format = "*@&^#$") Date d) {
@InRange(
min = "06/01/2011",
max = "06/30/2011",
format = "*@&^#$")
Date d) {
}
}

Expand All @@ -112,7 +132,8 @@ public static class MalformedFormatDate {

@RunWith(JUnitQuickcheck.class)
public static class MissingMin {
@Property public void shouldHold(@InRange(max = "12/31/2012", format = "MM/dd/yyyy") Date d)
@Property public void shouldHold(
@InRange(max = "12/31/2012", format = "MM/dd/yyyy") Date d)
throws Exception {

SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
Expand All @@ -126,24 +147,32 @@ public static class MissingMin {

@RunWith(JUnitQuickcheck.class)
public static class MissingMax {
@Property public void shouldHold(@InRange(min = "12/31/2012", format = "MM/dd/yyyy") Date d)
@Property public void shouldHold(
@InRange(min = "12/31/2012", format = "MM/dd/yyyy") Date d)
throws Exception {

SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
assertThat(d, greaterThanOrEqualTo(formatter.parse("12/31/2012")));
assertThat(
d,
greaterThanOrEqualTo(formatter.parse("12/31/2012")));
}
}

@Test public void backwardsRange() {
assertThat(
testResult(BackwardsRange.class),
hasSingleFailureContaining(IllegalArgumentException.class.getName()));
hasSingleFailureContaining(
IllegalArgumentException.class.getName()));
}

@RunWith(JUnitQuickcheck.class)
public static class BackwardsRange {
@Property public void shouldHold(
@InRange(min = "12/31/2012", max = "12/01/2012", format = "MM/dd/yyyy") Date d) {
@InRange(
min = "12/31/2012",
max = "12/01/2012",
format = "MM/dd/yyyy")
Date d) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public class DistinctArrayPropertyParameterTypesTest {
@RunWith(JUnitQuickcheck.class)
public static class DistinctArrays {
@Property public void shouldHold(
@InRange(minInt = 1, maxInt = 5) int @Size(min = 2, max = 5) @Distinct [] i) {
@InRange(minInt = 1, maxInt = 5)
int @Size(min = 2, max = 5) @Distinct [] i) {

assertThat(
i.length,
Expand All @@ -68,15 +69,18 @@ public static class DistinctArrays {
allOf(
greaterThanOrEqualTo(4),
lessThanOrEqualTo(5)));
assertTrue(Lists.isDistinct(Ints.asList(ShrinkingDistinctArrays.failed)));
assertTrue(
Lists.isDistinct(Ints.asList(ShrinkingDistinctArrays.failed)));
}

@RunWith(JUnitQuickcheck.class)
public static class ShrinkingDistinctArrays {
static int[] failed;

@Property public void shouldHold(
@InRange(minInt = 1, maxInt = 5) int @Size(min = 4, max = 5) @Distinct [] i) {
@InRange(minInt = 1, maxInt = 5)
int @Size(min = 4, max = 5) @Distinct [] i) {

failed = i;

fail();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ public class DistinctSetPropertyParameterTypesTest {
@RunWith(JUnitQuickcheck.class)
public static class DistinctSets {
@Property public void shouldHold(
@Size(min = 4, max = 5) @Distinct Set<@InRange(minInt = 1, maxInt = 5) Integer> items) {
assertThat(items.size(), allOf(greaterThanOrEqualTo(4), lessThanOrEqualTo(5)));
@Size(min = 4, max = 5)
@Distinct
Set<@InRange(minInt = 1, maxInt = 5) Integer> items) {

assertThat(
items.size(),
allOf(greaterThanOrEqualTo(4), lessThanOrEqualTo(5)));
}
}

Expand All @@ -40,7 +45,10 @@ public static class ShrinkingDistinctSets {
static Set<Integer> failed;

@Property public void shouldHold(
@Size(min = 4, max = 5) @Distinct Set<@InRange(minInt = 1, maxInt = 5) Integer> items) {
@Size(min = 4, max = 5)
@Distinct
Set<@InRange(minInt = 1, maxInt = 5) Integer> items) {

failed = items;

fail();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,18 @@ public static class RangedDuration {
assertThat(
d,
allOf(
greaterThanOrEqualTo(Duration.parse("PT-2562047788015215H-30M-8S")),
lessThanOrEqualTo(Duration.parse("PT2562047788015215H30M7.999999999S"))));
greaterThanOrEqualTo(
Duration.parse("PT-2562047788015215H-30M-8S")),
lessThanOrEqualTo(
Duration.parse("PT2562047788015215H30M7.999999999S"))));
}
}

@Test public void malformedMin() {
assertThat(
testResult(MalformedMinDuration.class),
hasSingleFailureContaining(DateTimeParseException.class.getName()));
hasSingleFailureContaining(
DateTimeParseException.class.getName()));
}

@RunWith(JUnitQuickcheck.class)
Expand All @@ -90,7 +93,8 @@ public static class MalformedMinDuration {
@Test public void malformedMax() {
assertThat(
testResult(MalformedMaxDuration.class),
hasSingleFailureContaining(DateTimeParseException.class.getName()));
hasSingleFailureContaining(
DateTimeParseException.class.getName()));
}

@RunWith(JUnitQuickcheck.class)
Expand Down Expand Up @@ -138,7 +142,8 @@ public static class MissingMaxDuration {
@Test public void backwardsRange() {
assertThat(
testResult(BackwardsRange.class),
hasSingleFailureContaining(IllegalArgumentException.class.getName()));
hasSingleFailureContaining(
IllegalArgumentException.class.getName()));
}

@RunWith(JUnitQuickcheck.class)
Expand Down

0 comments on commit 5a95e9f

Please sign in to comment.