Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to assert that an exception is thrown java

@Test
public void whenExceptionThrown_thenAssertionSucceeds() {
    Exception exception = assertThrows(NumberFormatException.class, () -> {
        Integer.parseInt("1a");
    });

    String expectedMessage = "For input string";
    String actualMessage = exception.getMessage();

    assertTrue(actualMessage.contains(expectedMessage));
}
Comment

PREVIOUS NEXT
Code Example
Java :: How to connect from Android emulator to application on localhost? 
Java :: java comments 
Java :: Failed to collect dependencies at net.sf.jasperreports:jasperreports:jar:6.2.0 
Java :: java eclipse console clear 
Java :: pivot in array 
Java :: byte array to file java 
Java :: java string regexp replace 
Java :: sort descending java stream 
Java :: Processing Java examples 
Java :: how to find numbers of digits in java 
Java :: how to add element to end of array java 
Java :: okhttp post 
Java :: fill two dimensional array 
Java :: java enums 
Java :: how to find the length of a string in java without using length function 
Java :: springboot mongodb test 
Java :: datatypes in java 
Java :: how to find max in min in an array 
Java :: javafx textarea size 
Java :: java scan a file 
Java :: java write in a file without overwriting 
Java :: brew use java 11 
Java :: java formatted output 
Java :: how to take float input in java 
Java :: Access items from the ArrayList using get() function 
Java :: java standard exception 
Java :: indext of minimum element in an array in java 
Java :: add character to a string java 
Java :: error: package android.support.v7.app does not exist 
Java :: char to ascii java 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =