Kotlinlearncs.online LogoJava
Return to List

Test Writing: Multi Catcher

Created By: Geoffrey Challen
/ Version: 2021.9.0

Write a method named retrieveValue. retrieveValue takes an instance of Faulter and returns the result of retrieving its value property, which has type Int.

Seems simple! Except there is just one small problem. Faulter was implemented by a friend that didn't take CS 124, and so it's getter is pretty buggy. A lot of the time it will throw an exception rather than return the value. But you did take CS 124, and so you know how to catch the exception and retry the call to getValue. Note that getValue may fault multiple times before succeeding, and you should retry until it successfully returns a value.

Test Design Challenge

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

  • Provide a public class named TestCatcher 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 Kotlin's assert or check methods