Here you can find the source of assertThrows(Class extends Exception> exception, Runnable action)
public static void assertThrows(Class<? extends Exception> exception, Runnable action)
//package com.java2s; //License from project: Apache License public class Main { public static void assertThrows(Class<? extends Exception> exception, Runnable action) {/*from w w w.ja v a2s. c om*/ try { action.run(); throw new AssertionError("Expected exception: " + exception.getTypeName() + ", but no exception thrown"); } catch (Exception e) { if (!e.getClass().equals(exception)) { throw new AssertionError("Expected exception: " + exception.getTypeName() + ", but was " + e.getClass().getTypeName()); } } } }