Jamalmo / google-refine

Automatically exported from code.google.com/p/google-refine
Other
0 stars 0 forks source link

./gridworks not compiling server tests (but eclipse does) #21

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Please find attached patch (based on r719) which is a small example of unit 
testing with JUnit and Mockita of Gridworks.

This runs fine in the JUnit runner in Eclipse, but I get a "package 
com.metaweb.gridworks.commands does not exist" compile time error when 
running ./gridworks server_test from the command line.

File and changes description:
--tests/java/lib/mockita-all-1.8.4.jar
adds the mockita library

--.classpath
change appends the mockita library to the java build path

--tests/java/src/com/metaweb/gridworks/tests/commands/util/ 
CancelProcessesCommand.java
Sample test script with two methods.  One testing for behaviour on null 
parameters passed (should fail on running, as it expects 
IllegalArgumentException which isn't currently returned by the method under 
test).
The second test, doPost, uses mock objects to verify the fully working use 
case of the system under test, this should pass.  As Mockita seems unable 
to deal with mocking variables, I had to wrap the field 
Project.projectManager in a method Project.getProjectManager().

--src/main/java/com/metaweb/gridworks/model/Project.java
Additional method getProjectManager() to wrap field projectManager.  I 
think the variable should be made protected, and all calls to it made 
through the method.  (In .Net libraries, it's best practice to avoid 
calling variables directly, and they are private by default - not sure if 
it's the same practice in Java?).

--src/main/java/com/metaweb/gridworks/commands/util/CancelAllProcesses.java
updated to call Project.getProjectManager() so the call can be verified by 
Mockita.

Original issue reported on code.google.com by iainsproat on 12 May 2010 at 8:01

Attachments:

GoogleCodeExporter commented 8 years ago
Committed (I did some changed to the test but it's functionally equivalent)

Original comment by stefano.mazzocchi@gmail.com on 12 May 2010 at 9:03

GoogleCodeExporter commented 8 years ago
Great.  Thanks Stefano - it wasn't quite production ready, so thanks for 
cleaning it 
up and committing.

As an aside, normally I'd have guard clauses on the functions to throw 
IllegalArgumentException if a null value is passed as a parameter (which I was 
testing for).  I notice you changed the test to expect ServletException.

I'd prefer to see IllegalArgumentException (or whatever the Java Equivalent of 
.Net's 
ArgumentNullException is), as it's then obvious that the problem isn't with the 
method but with the parameter passed in to it - which saves time in the 
debugging.

Original comment by iainsproat on 12 May 2010 at 10:28

GoogleCodeExporter commented 8 years ago

Original comment by iainsproat on 17 May 2010 at 12:03

GoogleCodeExporter commented 8 years ago

Original comment by tfmorris on 18 Sep 2012 at 2:21

GoogleCodeExporter commented 8 years ago

Original comment by tfmorris on 18 Sep 2012 at 2:52