Skip to content

Commit 4e111b4

Browse files
committed
Test OpBuilder specifically without input
This test should be differentiated from the no output tests within OpBuilderTest in that tests within this class are more complex. The no-output tests within OpBuilderTest merely ensure that a) the methods continue to exist and b) that basic functionality is available. This class tests more complicated functionality contingent on no output (which is currently limited to ensuring ParameterizedType outputs do not cause error when no output is specified)
1 parent 3adb2f1 commit 4e111b4

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
package org.scijava.ops.core.builder;
3+
4+
import java.lang.reflect.Type;
5+
import java.util.ArrayList;
6+
import java.util.function.Function;
7+
8+
import org.junit.Assert;
9+
import org.junit.Test;
10+
import org.scijava.ops.AbstractTestEnvironment;
11+
import org.scijava.ops.OpField;
12+
import org.scijava.ops.core.OpCollection;
13+
import org.scijava.param.Parameter;
14+
import org.scijava.plugin.Plugin;
15+
import org.scijava.struct.ItemIO;
16+
import org.scijava.types.Nil;
17+
import org.scijava.types.TypeService;
18+
19+
/**
20+
* Ensures correct behavior in {@link OpBuilder} calls <b>where no output type
21+
* or <code>Object</code> is given</b>.
22+
*
23+
* @author Gabriel Selzer
24+
* @see OpBuilderTest
25+
*/
26+
@Plugin(type = OpCollection.class)
27+
public class OpBuilderNoOutputTest<T extends Number> extends
28+
AbstractTestEnvironment
29+
{
30+
31+
public final String opName = "test.noOutput";
32+
33+
// private wrapper class
34+
private static class WrappedList<E> extends ArrayList<E> {}
35+
36+
@OpField(names = opName)
37+
@Parameter(key = "in", itemIO = ItemIO.INPUT)
38+
@Parameter(key = "out", itemIO = ItemIO.OUTPUT)
39+
public final Function<T, WrappedList<T>> func = in -> {
40+
41+
WrappedList<T> out = new WrappedList<>();
42+
out.add(in);
43+
return out;
44+
};
45+
46+
@Test
47+
public void testNoParameterizedTypeOutputGiven() {
48+
Object output = ops.op(opName).input(5.).apply();
49+
TypeService types = context.getService(TypeService.class);
50+
Type expectedOutputType = new Nil<WrappedList<Double>>() {}.getType();
51+
Assert.assertEquals(types.reify(output), expectedOutputType);
52+
}
53+
}

0 commit comments

Comments
 (0)