3232public class JavadocParameterTest extends AbstractTestEnvironment {
3333
3434 /**
35+ * Tests javadoc scraping with param (P) and return (R)
36+ *
3537 * @param foo the first input
3638 * @param bar the second input
3739 * @return foo + bar
3840 */
39- @ OpMethod (names = "test.javadoc.method" , type = BiFunction .class )
40- public static List <Long > OpMethodFoo (List <String > foo , List <String > bar ) {
41+ @ OpMethod (names = "test.javadoc.methodPR" , type = BiFunction .class )
42+ public static List <Long > OpMethodPR (List <String > foo , List <String > bar ) {
43+ BiFunction <String , String , Long > func = (s1 , s2 ) -> Long .parseLong (s1 ) +
44+ Long .parseLong (s2 );
45+ return Streams .zip (foo .stream (), bar .stream (), func ).collect (Collectors
46+ .toList ());
47+ }
48+
49+ /**
50+ * Tests javadoc scraping with input (I) and output (O)
51+ *
52+ * @input foo the first input
53+ * @input bar the second input
54+ * @output foo + bar
55+ */
56+ @ OpMethod (names = "test.javadoc.methodIO" , type = BiFunction .class )
57+ public static List <Long > OpMethodIO (List <String > foo , List <String > bar ) {
58+ BiFunction <String , String , Long > func = (s1 , s2 ) -> Long .parseLong (s1 ) +
59+ Long .parseLong (s2 );
60+ return Streams .zip (foo .stream (), bar .stream (), func ).collect (Collectors
61+ .toList ());
62+ }
63+
64+ /**
65+ * Tests javadoc scraping with input (I) and return (R)
66+ *
67+ * @input foo the first input
68+ * @input bar the second input
69+ * @return foo + bar
70+ */
71+ @ OpMethod (names = "test.javadoc.methodIR" , type = BiFunction .class )
72+ public static List <Long > OpMethodIR (List <String > foo , List <String > bar ) {
4173 BiFunction <String , String , Long > func = (s1 , s2 ) -> Long .parseLong (s1 ) +
4274 Long .parseLong (s2 );
4375 return Streams .zip (foo .stream (), bar .stream (), func ).collect (Collectors
4476 .toList ());
4577 }
4678
4779 @ Test
48- public void testJavadocMethod () {
49- Iterator <OpInfo > infos = ops .env ().infos ("test.javadoc.method " ).iterator ();
80+ public void testJavadocMethodPR () {
81+ Iterator <OpInfo > infos = ops .env ().infos ("test.javadoc.methodPR " ).iterator ();
5082
5183 OpInfo info = infos .next ();
5284 if (infos .hasNext ()) {
5385 Assert .fail ("Multiple OpInfos with name \" test.javadoc.method\" " );
5486 }
87+ isSuitableScrapedOpMethodInfo (info );
88+ }
89+
90+ @ Test
91+ public void testJavadocMethodIO () {
92+ Iterator <OpInfo > infos = ops .env ().infos ("test.javadoc.methodIO" ).iterator ();
5593
94+ OpInfo info = infos .next ();
95+ if (infos .hasNext ()) {
96+ Assert .fail ("Multiple OpInfos with name \" test.javadoc.method\" " );
97+ }
98+ isSuitableScrapedOpMethodInfo (info );
99+ }
100+
101+ @ Test
102+ public void testJavadocMethodIR () {
103+ Iterator <OpInfo > infos = ops .env ().infos ("test.javadoc.methodIR" ).iterator ();
104+
105+ OpInfo info = infos .next ();
106+ if (infos .hasNext ()) {
107+ Assert .fail ("Multiple OpInfos with name \" test.javadoc.method\" " );
108+ }
109+ isSuitableGenericOpMethodInfo (info );
110+ }
111+
112+ /**
113+ * Asserts that the {@link OpInfo} has as inputs:
114+ * <ul>
115+ * <li> foo - the first input
116+ * <li> bar - the second input
117+ * </ul>
118+ * and as output:
119+ * <ul>
120+ * <li> output - foo + bar
121+ * </ul>
122+ */
123+ private void isSuitableScrapedOpMethodInfo (OpInfo info ) {
56124 // assert input names
57125 String [] inputNames = info .inputs ().stream ().map (m -> m .getKey ()).toArray (
58126 String []::new );
@@ -72,23 +140,66 @@ public void testJavadocMethod() {
72140 Assert .assertEquals ("foo + bar" , outputDescription );
73141 }
74142
143+ /**
144+ * Asserts that the {@link OpInfo} has as inputs:
145+ * <ul>
146+ * <li> input1
147+ * <li> input2
148+ * </ul>
149+ * and as output:
150+ * <ul>
151+ * <li> output1
152+ * </ul>
153+ */
154+ private void isSuitableGenericOpMethodInfo (OpInfo info ) {
155+ // assert input names
156+ String [] inputNames = info .inputs ().stream ().map (m -> m .getKey ()).toArray (
157+ String []::new );
158+ Assert .assertArrayEquals (inputNames , new String [] { "input1" , "input2" });
159+
160+ // assert input descriptions
161+ String [] inputDescriptions = info .inputs ().stream ().map (m -> m .getDescription ()).toArray (
162+ String []::new );
163+ Assert .assertArrayEquals (inputDescriptions , new String [] { "" , "" });
164+
165+ // assert output name
166+ String outputName = info .output ().getKey ();
167+ Assert .assertEquals ("output1" , outputName );
168+
169+ // assert output description
170+ String outputDescription = info .output ().getDescription ();
171+ Assert .assertEquals ("" , outputDescription );
172+ }
173+
75174 /**
76175 * @input in the input
77176 * @output the output
78177 */
79- @ OpField (names = "test.javadoc.field " )
178+ @ OpField (names = "test.javadoc.fieldF " )
80179 public final Function <Double , Double > javadocFieldOp = (in ) -> in + 1 ;
81180
181+ /**
182+ * @input inList the input
183+ * @container outList the preallocated output
184+ */
185+ @ OpField (names = "test.javadoc.fieldC" )
186+ public final Computers .Arity1 <List <Double >, List <Double >> javadocFieldOpComputer = (in , out ) -> {
187+ out .clear ();
188+ for (Double d :in ) {
189+ out .add (d + 1 );
190+ }
191+ };
192+
82193 @ Test
83- public void testJavadocField () {
84- Iterator <OpInfo > infos = ops .env ().infos ("test.javadoc.field " ).iterator ();
194+ public void testJavadocFieldF () {
195+ Iterator <OpInfo > infos = ops .env ().infos ("test.javadoc.fieldF " ).iterator ();
85196
86197 if (!infos .hasNext ()) {
87- Assert .fail ("No OpInfos with name \" test.javadoc.field \" " );
198+ Assert .fail ("No OpInfos with name \" test.javadoc.fieldF \" " );
88199 }
89200 OpInfo info = infos .next ();
90201 if (infos .hasNext ()) {
91- Assert .fail ("Multiple OpInfos with name \" test.javadoc.field \" " );
202+ Assert .fail ("Multiple OpInfos with name \" test.javadoc.fieldF \" " );
92203 }
93204
94205 // assert input names
@@ -109,6 +220,37 @@ public void testJavadocField() {
109220 String outputDescription = info .output ().getDescription ();
110221 assertEquals ("the output" , outputDescription );
111222 }
223+
224+ @ Test
225+ public void testJavadocFieldC () {
226+ Iterator <OpInfo > infos = ops .env ().infos ("test.javadoc.fieldC" ).iterator ();
227+
228+ if (!infos .hasNext ()) {
229+ Assert .fail ("No OpInfos with name \" test.javadoc.fieldC\" " );
230+ }
231+ OpInfo info = infos .next ();
232+ if (infos .hasNext ()) {
233+ Assert .fail ("Multiple OpInfos with name \" test.javadoc.fieldC\" " );
234+ }
235+
236+ // assert input names
237+ String [] inputNames = info .inputs ().stream ().map (m -> m .getKey ()).toArray (
238+ String []::new );
239+ Assert .assertArrayEquals (new String [] { "inList" , "outList" }, inputNames );
240+
241+ // assert input descriptions
242+ String [] inputDescriptions = info .inputs ().stream ().map (m -> m .getDescription ()).toArray (
243+ String []::new );
244+ Assert .assertArrayEquals (new String [] { "the input" , "the preallocated output" }, inputDescriptions );
245+
246+ // assert output name
247+ String outputName = info .output ().getKey ();
248+ Assert .assertEquals ("outList" , outputName );
249+
250+ // assert output description
251+ String outputDescription = info .output ().getDescription ();
252+ assertEquals ("the preallocated output" , outputDescription );
253+ }
112254
113255 @ Test
114256 public void testJavadocClass () {
@@ -143,7 +285,7 @@ public void testJavadocClass() {
143285
144286 @ Test
145287 public void opStringRegressionTest () {
146- Iterator <OpInfo > infos = ops .env ().infos ("test.javadoc.method " ).iterator ();
288+ Iterator <OpInfo > infos = ops .env ().infos ("test.javadoc.methodPR " ).iterator ();
147289
148290 OpInfo info = infos .next ();
149291 if (infos .hasNext ()) {
@@ -153,7 +295,7 @@ public void opStringRegressionTest() {
153295 // test standard op string
154296 String expected =
155297 "public static java.util.List<java.lang.Long> org.scijava.param.JavadocParameterTest." +
156- "OpMethodFoo (java.util.List<java.lang.String>,java.util.List<java.lang.String>)(\n " +
298+ "OpMethodPR (java.util.List<java.lang.String>,java.util.List<java.lang.String>)(\n " +
157299 " Inputs:\n " +
158300 " java.util.List<java.lang.String> foo -> the first input\n " +
159301 " java.util.List<java.lang.String> bar -> the second input\n " +
@@ -165,7 +307,7 @@ public void opStringRegressionTest() {
165307 // test special op string
166308 expected =
167309 "public static java.util.List<java.lang.Long> org.scijava.param.JavadocParameterTest." +
168- "OpMethodFoo (java.util.List<java.lang.String>,java.util.List<java.lang.String>)(\n " +
310+ "OpMethodPR (java.util.List<java.lang.String>,java.util.List<java.lang.String>)(\n " +
169311 " Inputs:\n " +
170312 " java.util.List<java.lang.String> foo -> the first input\n " +
171313 "==> java.util.List<java.lang.String> bar -> the second input\n " +
0 commit comments