Explorar o código

DMYParseTest (4)

Andrew Grant hai 3 meses
pai
achega
1a9808150c

+ 1 - 1
src/main/java/scot/carricksoftware/grantswriter/data/DMYImpl.java

@@ -49,7 +49,7 @@ public class DMYImpl implements DMY {
     private void checkMonth(String s) {
         try {
             int num = Integer.parseInt(s);
-            if ( num > 12) {
+            if ( num < 1 || num > 12) {
                 setMonth(null);
             } else {
                 setMonth(s);

+ 1 - 1
src/test/java/scot/carricksoftware/grantswriter/data/DMYParseNumericTest.java → src/test/java/scot/carricksoftware/grantswriter/data/DMYParseNumericDayTest.java

@@ -11,7 +11,7 @@ import org.junit.jupiter.api.Test;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
 
-class DMYParseNumericTest {
+class DMYParseNumericDayTest {
 
     private DMY dmy;
 

+ 65 - 0
src/test/java/scot/carricksoftware/grantswriter/data/DMYParseNumericMonthTest.java

@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grantswriter.data;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+class DMYParseNumericMonthTest {
+
+    private DMY dmy;
+
+    @BeforeEach
+    void setUp() {
+        dmy = new DMYImpl();
+    }
+
+    @Test
+    void tooLowMonthTest() {
+        String input = "25/00/1953";
+        dmy.setMonth("99");
+        dmy.parse(input);
+        assertNull(dmy.getMonth());
+    }
+
+    @Test
+    void lowMonthTest() {
+        String input = "25/01/1953";
+        dmy.setMonth("99");
+        dmy.parse(input);
+        assertEquals("01", dmy.getMonth());
+    }
+
+    @Test
+    void highMonthTest() {
+        String input = "25/12/1953";
+        dmy.setMonth("99");
+        dmy.parse(input);
+        assertEquals("12", dmy.getMonth());
+    }
+
+    @Test
+    void tooHighMonthTest() {
+        String input = "25/13/1953";
+        dmy.setMonth("99");
+        dmy.parse(input);
+        assertNull(dmy.getMonth());
+    }
+
+    @Test
+    void invalidMonthTest() {
+        String input = "25/zz/1953";
+        dmy.setMonth("99");
+        dmy.parse(input);
+        assertNull(dmy.getMonth());
+    }
+
+
+
+}