Kotlinlearncs.online LogoJava
Return to List

Test Writing: Map Sum Longer Than

Created By: Geoffrey Challen
/ Version: 2020.11.0

Create a public class called Summer that provides a single class method named sumLongerThan. sumLongerThan accepts a java.util.Map from String to Integer as its first parameter and an int as its second. It returns the sum as an int of the values of all of the keys that are longer than the second parameter.

For example:

If the passed Map is null or the length is negative, you should throw an IllegalArgumentException.

As a reminder, you can iterate over the keys in a map like this:

Test Design Challenge

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

  • Provide a public class named TestSummer 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