Skip to content

Commit 91eed21

Browse files
gselzerctrueden
authored andcommitted
Add javadoc scraping tests
1 parent 22e6208 commit 91eed21

1 file changed

Lines changed: 111 additions & 0 deletions

File tree

scijava/scijava-ops/src/test/java/org/scijava/param/JavadocParameterTest.java

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
import org.junit.Assert;
1515
import org.junit.Test;
1616
import org.scijava.function.Computers;
17+
import org.scijava.function.Inplaces;
1718
import org.scijava.ops.AbstractTestEnvironment;
19+
import org.scijava.ops.OpDependency;
1820
import org.scijava.ops.OpField;
1921
import org.scijava.ops.OpInfo;
2022
import org.scijava.ops.OpMethod;
@@ -77,6 +79,20 @@ public static List<Long> OpMethodIR(List<String> foo, List<String> bar) {
7779
.toList());
7880
}
7981

82+
/**
83+
* Tests javadoc scraping with input (I) ONLY
84+
*
85+
* @input foo the first input
86+
* @input bar the second input
87+
*/
88+
@OpMethod(names = "test.javadoc.methodI", type = BiFunction.class)
89+
public static List<Long> OpMethodI(List<String> foo, List<String> bar) {
90+
BiFunction<String, String, Long> func = (s1, s2) -> Long.parseLong(s1) +
91+
Long.parseLong(s2);
92+
return Streams.zip(foo.stream(), bar.stream(), func).collect(Collectors
93+
.toList());
94+
}
95+
8096
@Test
8197
public void testJavadocMethodPR() {
8298
Iterator<OpInfo> infos = ops.env().infos("test.javadoc.methodPR").iterator();
@@ -110,6 +126,101 @@ public void testJavadocMethodIR() {
110126
isSuitableGenericOpMethodInfo(info);
111127
}
112128

129+
@Test
130+
public void testJavadocMethodI() {
131+
Iterator<OpInfo> infos = ops.env().infos("test.javadoc.methodI").iterator();
132+
133+
OpInfo info = infos.next();
134+
if (infos.hasNext()) {
135+
Assert.fail("Multiple OpInfos with name \"test.javadoc.method\"");
136+
}
137+
isSuitableGenericOpMethodInfo(info);
138+
}
139+
140+
/**
141+
* Tests javadoc scraping of mutable taglet
142+
*
143+
* @mutable foo the i/o argument
144+
*/
145+
@OpMethod(names = "test.javadoc.methodInplaceI", type = Inplaces.Arity1.class)
146+
public static void OpMethodInplaceI(List<String> foo) {
147+
for (int i = 0; i < foo.size(); i++) {
148+
foo.set(i, foo.get(i) + " foo");
149+
}
150+
}
151+
152+
/**
153+
* Tests javadoc scraping of mutable taglet
154+
*
155+
* @dependency inplace the Op being wrapped
156+
* @mutable foo the i/o argument
157+
*/
158+
@OpMethod(names = "test.javadoc.methodDependency", type = Inplaces.Arity1.class)
159+
public static void OpMethodInplaceI(@OpDependency(
160+
name = "test.javadoc.methodInplaceI") Inplaces.Arity1<List<String>> inplace,
161+
List<String> foo)
162+
{
163+
inplace.mutate(foo);
164+
}
165+
166+
@Test
167+
public void testJavadocMethodInplaceI() {
168+
Iterator<OpInfo> infos = ops.env().infos("test.javadoc.methodInplaceI").iterator();
169+
170+
OpInfo info = infos.next();
171+
if (infos.hasNext()) {
172+
Assert.fail("Multiple OpInfos with name \"test.javadoc.method\"");
173+
}
174+
175+
// assert input names
176+
String[] inputNames = info.inputs().stream().map(m -> m.getKey()).toArray(
177+
String[]::new);
178+
Assert.assertArrayEquals(inputNames, new String[] { "foo" });
179+
180+
// assert input descriptions
181+
String[] inputDescriptions = info.inputs().stream().map(m -> m
182+
.getDescription()).toArray(String[]::new);
183+
Assert.assertArrayEquals(inputDescriptions, new String[] {
184+
"the i/o argument"});
185+
186+
// assert output name
187+
String outputName = info.output().getKey();
188+
Assert.assertEquals("foo", outputName);
189+
190+
// assert output description
191+
String outputDescription = info.output().getDescription();
192+
Assert.assertEquals("the i/o argument", outputDescription);
193+
}
194+
195+
@Test
196+
public void testJavadocMethodInplaceWithDepedency() {
197+
Iterator<OpInfo> infos = ops.env().infos("test.javadoc.methodDependency").iterator();
198+
199+
OpInfo info = infos.next();
200+
if (infos.hasNext()) {
201+
Assert.fail("Multiple OpInfos with name \"test.javadoc.methodDependency\"");
202+
}
203+
204+
// assert input names
205+
String[] inputNames = info.inputs().stream().map(m -> m.getKey()).toArray(
206+
String[]::new);
207+
Assert.assertArrayEquals(inputNames, new String[] { "foo" });
208+
209+
// assert input descriptions
210+
String[] inputDescriptions = info.inputs().stream().map(m -> m
211+
.getDescription()).toArray(String[]::new);
212+
Assert.assertArrayEquals(inputDescriptions, new String[] {
213+
"the i/o argument"});
214+
215+
// assert output name
216+
String outputName = info.output().getKey();
217+
Assert.assertEquals("foo", outputName);
218+
219+
// assert output description
220+
String outputDescription = info.output().getDescription();
221+
Assert.assertEquals("the i/o argument", outputDescription);
222+
}
223+
113224
/**
114225
* Asserts that the {@link OpInfo} has as inputs:
115226
* <ul>

0 commit comments

Comments
 (0)