|
|
@@ -0,0 +1,56 @@
|
|
|
+package org.leumasjaffe.recipe.view.formatter;
|
|
|
+
|
|
|
+import static org.junit.jupiter.api.Assertions.*;
|
|
|
+
|
|
|
+import java.text.ParseException;
|
|
|
+
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+
|
|
|
+class DurationFormatterTest {
|
|
|
+
|
|
|
+ DurationFormatter formatter = new DurationFormatter();
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testCanParseValidStrings() {
|
|
|
+ assertDoesNotThrow(() -> formatter.stringToValue("10 s"));
|
|
|
+ assertDoesNotThrow(() -> formatter.stringToValue("10 - 20 s"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testThrowsErrorOnUnknownEnum() {
|
|
|
+ assertThrows(ParseException.class,
|
|
|
+ () -> formatter.stringToValue("10 tocks"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testThrowsErrorOnInvalidFloat() {
|
|
|
+ assertThrows(ParseException.class,
|
|
|
+ () -> formatter.stringToValue("0.Q s"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testThrowsErrorEmptyString() {
|
|
|
+ assertThrows(ParseException.class,
|
|
|
+ () -> formatter.stringToValue(""));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testThrowsErrorOneArg() {
|
|
|
+ assertThrows(ParseException.class,
|
|
|
+ () -> formatter.stringToValue("0"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testThrowsErrorThreeArgs() {
|
|
|
+ assertThrows(ParseException.class,
|
|
|
+ () -> formatter.stringToValue("0 - s"));
|
|
|
+ assertThrows(ParseException.class,
|
|
|
+ () -> formatter.stringToValue("0 1 s"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testThrowsErrorMoreThanFourArgs() {
|
|
|
+ assertThrows(ParseException.class,
|
|
|
+ () -> formatter.stringToValue("0 - 1 s s"));
|
|
|
+ }
|
|
|
+}
|