@@ -44,7 +44,7 @@ public void init() {
4444 public void testGradeDistributionCommand () {
4545 GradeDistributionCommand cmd = new GradeDistributionCommand ();
4646 JSONObject gradeDistribution = cmd .run (null );
47-
47+
4848 assertNotNull ("JSONObject is null" , gradeDistribution );
4949 ApiAssert .assertApiDataFetched (gradeDistribution );
5050 }
@@ -70,24 +70,21 @@ public void testScannerStatesCommand() {
7070 @ Test
7171 public void testInvokeAssessmentCommand () {
7272 InvokeAssessmentCommand cmd = new InvokeAssessmentCommand ();
73-
73+
7474 JSONObject assessment = new JSONObject ();
7575 try {
7676 // Argument host is mandatory. Should fail
7777 assessment = cmd .run (null );
78- fail ("InvokeAssessmentCommand called without an host argument. This should not be possible." );
79- } catch (IllegalArgumentException e ) {
80- //ignore
78+ fail ("Should have raised an IllegalArgumentException." );
79+ } catch (IllegalArgumentException e ) {
80+ List <String > arguments = new ArrayList <String >();
81+ arguments .add ("host=google.com" );
82+ arguments .add ("hidden" );
83+ assessment = cmd .run (arguments );
84+
85+ assertNotNull ("JSONObject is null" , assessment );
86+ ApiAssert .assertApiDataFetched (assessment );
8187 }
82-
83-
84- List <String > arguments = new ArrayList <String >();
85- arguments .add ("host=google.com" );
86- arguments .add ("hidden" );
87- assessment = cmd .run (arguments );
88-
89- assertNotNull ("JSONObject is null" , assessment );
90- ApiAssert .assertApiDataFetched (assessment );
9188 }
9289
9390 /**
@@ -110,12 +107,12 @@ public void testRetrieveTestResultsCommand() {
110107 try {
111108 // Argument id is mandatory. Should fail
112109 cmd .run (null );
113- } catch (IllegalArgumentException e ) {
114- assertTrue (true );
110+ fail ("Should have raised an IllegalArgumentException." );
111+ } catch (IllegalArgumentException e ) {
112+ return ;
115113 }
116114 }
117115
118-
119116 /**
120117 * A recent scan call should not be null.
121118 */
@@ -126,36 +123,38 @@ public void testRecentScansCommand() {
126123 JSONObject json = cmd .run (null );
127124 assertNotNull ("JSONObject is null" , json );
128125 ApiAssert .assertApiDataFetched (json );
129-
126+
130127 // Test the min argument
131128 List <String > arguments = new ArrayList <String >();
132129 arguments .add ("min=100" );
133130 json = cmd .run (arguments );
134131 String key ;
135- for (Iterator <String > it = json .keys (); it .hasNext ();) {
132+ for (Iterator <String > it = json .keys (); it .hasNext ();) {
136133 key = it .next ();
137134 try {
138- assertTrue ("Calling recent scan with a minimum score of 100 should only retrieve A+ score" , json .get (key ).equals ("A+" ));
135+ assertTrue ("Calling recent scan with a minimum score of 100 should only retrieve A+ score" ,
136+ json .get (key ).equals ("A+" ));
139137 } catch (JSONException e ) {
140- e . printStackTrace ();
138+ fail ();
141139 }
142140 }
143-
141+
144142 arguments .clear ();
145143 arguments .add ("max=80" );
146144 json = cmd .run (arguments );
147- key = new String ();
148- for (Iterator <String > it = json .keys (); it .hasNext ();) {
145+ for (Iterator <String > it = json .keys (); it .hasNext ();) {
149146 try {
150147 key = it .next ();
151- assertFalse ("Calling recent scan with a maximum score of 80 should only retrieve A scores" , json .get (key ).equals ("A-" ));
152- assertFalse ("Calling recent scan with a maximum score of 80 should only retrieve A scores" , json .get (key ).equals ("A" ));
153- assertFalse ("Calling recent scan with a maximum score of 80 should only retrieve A scores" , json .get (key ).equals ("A+" ));
148+ assertFalse ("Calling recent scan with a maximum score of 80 should only retrieve A scores" ,
149+ json .get (key ).equals ("A-" ));
150+ assertFalse ("Calling recent scan with a maximum score of 80 should only retrieve A scores" ,
151+ json .get (key ).equals ("A" ));
152+ assertFalse ("Calling recent scan with a maximum score of 80 should only retrieve A scores" ,
153+ json .get (key ).equals ("A+" ));
154154 } catch (JSONException e ) {
155155 e .printStackTrace ();
156156 }
157157 }
158-
159158
160159 }
161160}
0 commit comments