@@ -82,13 +82,13 @@ public void testScopeGroovy() throws IOException, InterruptedException {
8282 inputs .put ("age" , 100 );
8383 Task task = service .task (CALC_SQRT_GROOVY , inputs ).waitFor ();
8484 assertComplete (task );
85- Number result = (Number ) task .outputs . get ( " result" );
85+ Number result = (Number ) task .result ( );
8686 assertEquals (10 , result .intValue ());
8787
8888 inputs .put ("age" , 81 );
8989 task = service .task ("task.outputs['result'] = sqrt_age(age)" , inputs ).waitFor ();
9090 assertComplete (task );
91- result = (Number ) task .outputs . get ( " result" );
91+ result = (Number ) task .result ( );
9292 assertEquals (9 , result .intValue ());
9393 }
9494 }
@@ -289,8 +289,45 @@ public void testInit() throws IOException, InterruptedException {
289289 Task task = service .task ("task.outputs['result'] = init_value" ).waitFor ();
290290 assertComplete (task );
291291
292- String result = (String ) task .outputs .get ("result" );
293- assertEquals ("initialized" , result , "Init script should set init_value variable" );
292+ String result = (String ) task .result ();
293+ assertEquals ("initialized" , result ,
294+ "Init script should set init_value variable" );
295+ }
296+ }
297+
298+ /** Tests {@link Task#result()} convenience method. */
299+ @ Test
300+ public void testTaskResult () throws IOException , InterruptedException {
301+ Environment env = Appose .system ();
302+ try (Service service = env .python ()) {
303+ maybeDebug (service );
304+
305+ // Create a task that produces a result.
306+ Task task = service .task ("task.outputs['result'] = 'success'" ).waitFor ();
307+ assertComplete (task );
308+
309+ // Test the result() convenience method.
310+ Object result = task .result ();
311+ assertEquals ("success" , result );
312+
313+ // Verify it's the same as directly accessing outputs.
314+ assertEquals (task .outputs .get ("result" ), result );
315+ }
316+ }
317+
318+ /** Tests {@link Task#result()} returns null when no result is set. */
319+ @ Test
320+ public void testTaskResultNull () throws IOException , InterruptedException {
321+ Environment env = Appose .system ();
322+ try (Service service = env .groovy ()) {
323+ maybeDebug (service );
324+
325+ // Create a task that doesn't set a result
326+ Task task = service .task ("println 'no result'" ).waitFor ();
327+ assertComplete (task );
328+
329+ // result() should return null
330+ assertNull (task .result ());
294331 }
295332 }
296333}
0 commit comments