Kotlinlearncs.online LogoJava
Return to List

Test Writing: Last Value From String

Created By: Geoffrey Challen
/ Version: 2022.7.0

Write a method name lastValueFromString that accepts a String containing one or more lines, each containing an integer value, and returns the last value as an int. The values may have whitespace around them!

For example, given the String:

1
  2
4

You should return 4.

You can assume that the passed String is not null, contains at least one line, and has no blank lines or lines that do not contain an integer value.

Test Design Challenge

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

  • Provide a 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

Related Lessons

Stuck? You may find these lessons helpful: