Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow for auto-generation of boolean/enum datapoints.

  • Loading branch information...
commit ac48feb8fbdfd1e67d3136d28a28a9331c54ff53 1 parent 1b2ef00
David Hart authored
91 src/test/java/org/junit/tests/experimental/theories/DefaultSupplierTest.java
View
@@ -0,0 +1,91 @@
+package org.junit.tests.experimental.theories;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.experimental.theories.DataPoint;
+import org.junit.experimental.theories.ParameterSignature;
+import org.junit.experimental.theories.PotentialAssignment;
+import org.junit.experimental.theories.internal.AllMembersSupplier;
+import org.junit.experimental.theories.internal.DefaultSupplier;
+import org.junit.runners.model.TestClass;
+
+public class DefaultSupplierTest {
+ public static class HasDataPoints {
+ enum TestEnum {
+ Test1, Test2;
+ }
+ @DataPoint
+ public static Boolean b= Boolean.TRUE;
+ @DataPoint
+ public static TestEnum e= TestEnum.Test1;
+
+ public HasDataPoints(Boolean b, TestEnum testEnum) {
+ }
+ }
+
+ @Test
+ public void noDefaultsNeeded() throws Exception {
+ DefaultSupplier supplier = new DefaultSupplier(
+ new AllMembersSupplier(new TestClass(HasDataPoints.class)));
+
+ List<PotentialAssignment> valueSources= supplier
+ .getValueSources(ParameterSignature.signatures(
+ HasDataPoints.class.getConstructor(Boolean.class, HasDataPoints.TestEnum.class))
+ .get(0));
+ assertThat(valueSources.size(), is(1));
+
+ valueSources= supplier
+ .getValueSources(ParameterSignature.signatures(
+ HasDataPoints.class.getConstructor(Boolean.class, HasDataPoints.TestEnum.class))
+ .get(1));
+ assertThat(valueSources.size(), is(1));
+ }
+
+ public static class NoDataPointBooleanDefaults {
+
+ public NoDataPointBooleanDefaults(Boolean b) {
+ }
+ }
+
+ @Test
+ public void booleanDefaultsNeeded() throws Exception {
+ DefaultSupplier supplier = new DefaultSupplier(
+ new AllMembersSupplier(new TestClass(NoDataPointBooleanDefaults.class)));
+
+ List<PotentialAssignment> valueSources= supplier
+ .getValueSources(ParameterSignature.signatures(
+ NoDataPointBooleanDefaults.class.getConstructor(Boolean.class))
+ .get(0));
+ assertThat(valueSources.size(), is(2));
+ assertThat((Boolean) valueSources.get(0).getValue(), is(Boolean.TRUE));
+ assertThat((Boolean) valueSources.get(1).getValue(), is(Boolean.FALSE));
+ }
+
+ public static class NoDataPointEnumDefaults {
+ enum TestEnum {
+ Test1, Test2;
+ }
+ public NoDataPointEnumDefaults(TestEnum testEnum) {
+ }
+ }
+
+ @Test
+ public void enumDefaultsNeeded() throws Exception {
+ DefaultSupplier supplier = new DefaultSupplier(
+ new AllMembersSupplier(new TestClass(NoDataPointEnumDefaults.class)));
+
+ List<PotentialAssignment> valueSources= supplier
+ .getValueSources(ParameterSignature.signatures(
+ NoDataPointEnumDefaults.class.getConstructor(NoDataPointEnumDefaults.TestEnum.class))
+ .get(0));
+ assertThat(valueSources.size(), is(2));
+ assertThat((NoDataPointEnumDefaults.TestEnum) valueSources.get(0).getValue(),
+ is(NoDataPointEnumDefaults.TestEnum.Test1));
+ assertThat((NoDataPointEnumDefaults.TestEnum) valueSources.get(1).getValue(),
+ is(NoDataPointEnumDefaults.TestEnum.Test2));
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.