summaryrefslogtreecommitdiff
path: root/src/main/java/au/id/zancanaro/javacheck/statem/CommandValue.java
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@zancanaro.id.au>2015-06-05 14:51:03 +1000
committerCarlo Zancanaro <carlo@zancanaro.id.au>2015-06-05 14:51:03 +1000
commit20b1226b4eb10e85497862bd73fe9e9a2f05191d (patch)
treecfc2cf01032515af4adba2a659f3da9734f5bb48 /src/main/java/au/id/zancanaro/javacheck/statem/CommandValue.java
parent821f5a2c711d748a95d8f5d54266069c5378b556 (diff)
First cut of a stateful testing framework (it's pretty hacky at the moment, but all the pieces are there)
Diffstat (limited to 'src/main/java/au/id/zancanaro/javacheck/statem/CommandValue.java')
-rw-r--r--src/main/java/au/id/zancanaro/javacheck/statem/CommandValue.java60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/main/java/au/id/zancanaro/javacheck/statem/CommandValue.java b/src/main/java/au/id/zancanaro/javacheck/statem/CommandValue.java
new file mode 100644
index 0000000..0a1fb61
--- /dev/null
+++ b/src/main/java/au/id/zancanaro/javacheck/statem/CommandValue.java
@@ -0,0 +1,60 @@
+package au.id.zancanaro.javacheck.statem;
+
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+public abstract class CommandValue<T> {
+ private final int id;
+
+ public CommandValue(int id) {
+ this.id = id;
+ }
+
+ public abstract boolean isAbstract();
+
+ public abstract T get();
+
+ public int getId() {
+ return id;
+ }
+
+ static class AbstractValue<T> extends CommandValue<T> {
+ public AbstractValue(int id) {
+ super(id);
+ }
+
+ @Override
+ public boolean isAbstract() {
+ return true;
+ }
+
+ @Override
+ public T get() {
+ throw new NoSuchElementException("Abstract values cannot be supplied");
+ }
+ }
+
+ static class ConcreteValue<T> extends CommandValue<T> {
+ private final Map<Integer, Object> values;
+
+ public ConcreteValue(int id, Map<Integer, Object> values) {
+ super(id);
+ this.values = values;
+ }
+
+ @Override
+ public boolean isAbstract() {
+ return true;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public T get() {
+ if (values.containsKey(getId())) {
+ return (T) values.get(getId());
+ } else {
+ throw new NoSuchElementException("Concrete values cannot be supplied prior to being calculated");
+ }
+ }
+ }
+}