1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Testing in Java

Connected

Exercise

Handling Exceptions: Message Processing

Just as using and handling exceptions is an integral part of writing code, testing these exceptions is vital to testing your project.

In this exercise, you will practice the syntax of JUnit's class instance assertion. You are given a method which converts a string to uppercase, but throws a custom RuntimeException if the string is null. The task is to write unit tests for it.

Instructions

100 XP
  • Assert the message has been converted to uppercase in the success scenario test.
  • Use the correct kind of assertion to verify that the exception thrown is an instance of the RuntimeException class.
  • Enter the expected class of the exception.
  • Use the correct assertion to verify the exception message.