Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

assertthat code throws exception

@Test
public void test_exception_approach_1() {
    ...
    assertThatExceptionOfType(IOException.class)
            .isThrownBy(() -> someBadIOOperation())
            .withMessage("boom!"); 
}

@Test
public void test_exception_approach_2() {
    ...
    assertThatThrownBy(() -> someBadIOOperation())
            .isInstanceOf(Exception.class)
            .hasMessageContaining("boom");
}

@Test
public void test_exception_approach_3() {
    ...
    // when
    Throwable thrown = catchThrowable(() -> someBadIOOperation());

    // then
    assertThat(thrown).isInstanceOf(Exception.class)
                      .hasMessageContaining("boom");
}
Comment

PREVIOUS NEXT
Code Example
Java :: sum and array list java 
Java :: android internet permission 
Java :: java get keys from tree map 
Java :: How to efficiently find the first duplicate value in an array of ints between 1 and the n, with n being the size of the array? 
Java :: how to add a keylistener to a jframe 
Java :: date from string java 
Java :: how to make an arraylist java 
Java :: border bottom android xml 
Java :: why java is secure 
Java :: jenna fischer that 70s show 
Java :: edittext color 
Java :: error: package androidx.multidex does not exist 
Java :: IntStream.generate 
Java :: how to set 2 decimal places in java 
Java :: java read string input 
Java :: convert date to calendar java 
Java :: fibonacci sequence in java recursion 
Java :: android studio fab icon color 
Java :: converter int array para string java 
Java :: access activity method from adapter 
Java :: android studio close app 
Java :: java get unique elements from array 
Java :: How to validate a binary search tree, in Java? 
Java :: spring boot logged in user 
Java :: bufferedreader java 
Java :: java how to make a gui 
Java :: java outer class 
Java :: JAVA_HOME not found in your environment. 
Java :: java calculate time difference 
Java :: Fibonacci Series Program. in java 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =