summaryrefslogtreecommitdiff
path: root/src/test/java/au/id/zancanaro/javacheck/object
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/au/id/zancanaro/javacheck/object')
-rw-r--r--src/test/java/au/id/zancanaro/javacheck/object/MyObject.java21
-rw-r--r--src/test/java/au/id/zancanaro/javacheck/object/MyObjectAddTest.java8
2 files changed, 20 insertions, 9 deletions
diff --git a/src/test/java/au/id/zancanaro/javacheck/object/MyObject.java b/src/test/java/au/id/zancanaro/javacheck/object/MyObject.java
index ac0c370..824fd8d 100644
--- a/src/test/java/au/id/zancanaro/javacheck/object/MyObject.java
+++ b/src/test/java/au/id/zancanaro/javacheck/object/MyObject.java
@@ -1,5 +1,13 @@
package au.id.zancanaro.javacheck.object;
+import au.id.zancanaro.javacheck.Generator;
+import au.id.zancanaro.javacheck.ShrinkTree;
+
+import java.util.Random;
+
+import static au.id.zancanaro.javacheck.Generators.asciiCharacter;
+import static au.id.zancanaro.javacheck.Generators.stringOf;
+
public class MyObject {
public final String string;
public final int value;
@@ -12,10 +20,21 @@ public class MyObject {
}
@UseForGeneration
- public MyObject(String string, SubObject<Integer> subObject) {
+ public MyObject(
+ @UseGenerator(StringGenerator.class) String string,
+ SubObject<Integer> subObject) {
this(string, string.length(), subObject);
}
+ public static class StringGenerator implements Generator<String> {
+ public final Generator<String> gen = stringOf(asciiCharacter());
+
+ @Override
+ public ShrinkTree<String> generate(Random random, int size) {
+ return gen.generate(random, size);
+ }
+ }
+
public MyObject add(MyObject other) {
return new MyObject(
this.string + other.string,
diff --git a/src/test/java/au/id/zancanaro/javacheck/object/MyObjectAddTest.java b/src/test/java/au/id/zancanaro/javacheck/object/MyObjectAddTest.java
index 7965449..9321acb 100644
--- a/src/test/java/au/id/zancanaro/javacheck/object/MyObjectAddTest.java
+++ b/src/test/java/au/id/zancanaro/javacheck/object/MyObjectAddTest.java
@@ -1,23 +1,15 @@
package au.id.zancanaro.javacheck.object;
-import au.id.zancanaro.javacheck.Generator;
-import au.id.zancanaro.javacheck.annotations.DataSource;
import au.id.zancanaro.javacheck.annotations.Property;
import au.id.zancanaro.javacheck.junit.Properties;
import org.junit.runner.RunWith;
-import java.util.Collections;
-
-import static au.id.zancanaro.javacheck.Generators.ofType;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@RunWith(Properties.class)
public class MyObjectAddTest {
- @DataSource
- public static Generator<MyObject> source = ofType(MyObject.class);
-
@Property
public void testAdd(MyObject a, MyObject b) {
MyObject added = a.add(b);