Question: Create JUnit tests for the getDensityQualifier(int dpi) method based upon the following requirements: Invoke this method by passing an integer screen density value (referred to
Create JUnit tests for the getDensityQualifier(int dpi) method based upon the following requirements: Invoke this method by passing an integer screen density value (referred to as dpi). The method should return the appropriate screen density qualifier value as shown below. (The screen density qualifier is returned as a String value).
| Density Qualifier | Description |
| ldpi | Up to 120dpi |
| mdpi | Up to 160dpi |
| hdpi | Up to 240dpi |
| xhdpi | Up to 320dpi |
| xxhdpi | Up to 480dpi |
| xxxhdpi | Up to 640dpi |
| tvdpi | For televisions, exactly 213dpi |
| nodpi | Any other unspecified positive value |
package assignment;
import assignment.exceptions.InvalidValueException; import static assignment.SampleClass.ProductType.*; public class SampleClass { // Ctrl-Shift-T public String getDensityQualifier(int dpi) throws InvalidValueException { if (dpi <= 0) throw new InvalidValueException("DPI value must be greater than zero"); if (dpi == 213) { return "tvdpi"; } if (dpi <= 120) { return "ldpi"; } if (dpi <= 160) { return "mdpi"; } if (dpi <= 240) { return "hdpi"; } if (dpi <= 320) { return "xhdpi"; } if (dpi <= 480) { return "xxhdpi"; } if (dpi <= 640) { return "xxxhdpi"; } return "nodpi"; } }
package assignment.exceptions; public class InvalidValueException extends Exception { public InvalidValueException(String s) { super(s); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
