From 66a8e380b06f8dff28e5871ab298598fb916b7f2 Mon Sep 17 00:00:00 2001 From: Maxim Volkov Date: Thu, 17 Feb 2022 06:41:45 +0100 Subject: [PATCH] Added: Better Test Coverage for the Birthday class --- .../de/hs_fulda/ciip/projjpn/Birthdate.java | 6 +++--- .../hs_fulda/ciip/projjpn/BirthdateTest.java | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java index ab9af4c..32ed901 100644 --- a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java +++ b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java @@ -43,13 +43,13 @@ public class Birthdate { } public boolean isValid(int DD, int MM, int YYYY) { - if (DD < 1) { + if (DD < 1 || DD > 31) { return false; } - if (MM < 1) { + if (MM < 1 || MM > 12) { return false; } - if (YYYY < 1) { + if (YYYY < 1990 || YYYY > 2022) { return false; } diff --git a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java index 8b3ea01..b584b58 100644 --- a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java +++ b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java @@ -39,6 +39,25 @@ public class BirthdateTest extends TestCase { boolean expectedResult = false; boolean gotResult = birthdate.isValid(0, 0, 0); assertEquals(expectedResult, gotResult); + + gotResult = birthdate.isValid(32, 13, 1990); + assertEquals(expectedResult, gotResult); + + gotResult = birthdate.isValid(31, 0, 1980); + assertEquals(expectedResult, gotResult); + + gotResult = birthdate.isValid(31, 13, 1980); + assertEquals(expectedResult, gotResult); + + gotResult = birthdate.isValid(1, 1, 3000); + assertEquals(expectedResult, gotResult); + + gotResult = birthdate.isValid(1, 1, 1900); + assertEquals(expectedResult, gotResult); + + expectedResult = true; + gotResult = birthdate.isValid(1, 5, 2020); + assertEquals(expectedResult, gotResult); } }