Kotlinlearncs.online LogoJava
Return to List

Test Writing: Return an Exception

Created By: Geoffrey Challen
/ Version: 2020.11.0

Create a public class called Exceptioner that provides one static method exceptionable. exceptionable accepts a single int as a parameter. You should assert that the int is between 0 and 3, inclusive.

If the int is 0, you should return an IllegalStateException. If it's 1, you should return a NullPointerException. If it's 2, you should return a ArithmeticException. And if it's 3, you should return a IllegalArgumentException.

Test Design Challenge

You're challenge is to write tests for this problem described above.

  • Provide a public class named TestExceptioner with a single non-private class method named test that accepts no arguments and does not return a value.
  • If the implementation of the class described above is incorrect, your test method should throw an exception.
  • If it is correct, do not throw an exception.
  • You may want to use Java's assert method