Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
student:junit:v5 [2018/08/14 10:55] bernstdhstudent:junit:v5 [2020/02/23 10:50] – Fixed the description of assertThrows() bernstdh
Line 155: Line 155:
    */    */
   @Test   @Test
-  public void constructor_IllegalArguments()  +  public void constructor_IllegalArguments()
-          throws IllegalArgumentException+
   {   {
     assertThrows(IllegalArgumentException.class, () -> {new Atom("O", -8, -16);});     assertThrows(IllegalArgumentException.class, () -> {new Atom("O", -8, -16);});
Line 163: Line 162:
  
 This approach uses a //Lambda expression//, a representation of a class with a single-method.  This approach uses a //Lambda expression//, a representation of a class with a single-method. 
-(Note that ''%%IllegalArgumentException%%'' is an unchecked   exception. Hence, this code will compile even if the test method does   not specify that it re-throws the exception. If you are testing for   a checked exception then the test method must specify that it re-throws   the exception.) 
  
  
Line 180: Line 178:
  
       // Shouldn’t get here       // Shouldn’t get here
-      fail("Constrcutor should have thrown an IllegalArgumentException");+      fail("Constructor should have thrown an IllegalArgumentException");
     }     }
     catch (IllegalArgumentException iae)     catch (IllegalArgumentException iae)
Line 387: Line 385:
  
  
-==== Integrating JUnit into IDE ====+==== Integrating JUnit into an IDE ====