My functioning Java code:
@RunWith(Theories.class)
public class TestDoubling {
@DataPoints
public static int[] values() {
return new int[] { -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
}
@Theory
public void testDoubling(Integer a) {
assertThat(doubling(a), is(a * 2));
}
public int doubling(int value) { return value * 2; }
}
my (hopefully) equivalent kotlin code which fails:
RunWith(javaClass<Theories>())
class Testing {
class object {
DataPoints
fun values(): Array<Int> {
return array(-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
}
}
Theory
fun testDoubling(value: Integer) {
assertThat(doubling(value.intValue()), is
(value.intValue() * 2))
}
fun doubling(a: Int): Int = a * 2
}
Please note that the java.lang.Integer is required- a simple int will cause the following error:
java.lang.AssertionError: Never found parameters that satisfied method assumptions. Violated assumptions: []
at org.junit.Assert.fail(Assert.java:88)
at org.junit.experimental.theories.Theories$TheoryAnchor.evaluate(Theories.java:100)
That is also the exact same error message I get for the Kotlin version, even though they are- at least to my noobish eye- identical. Changing the Array<Int> to an IntArray didn't work nor removing the class object.