From 357adfcb9485caf40c34e602c545156a2c3ebc68 Mon Sep 17 00:00:00 2001 From: "Anton Isaev (opzaes ctai win10)" Date: Mon, 18 Jan 2021 16:15:03 +0200 Subject: [PATCH] create testing-class !!! --- .classpath | 4 +- .gitignore | 4 +- pom.xml | 7 + some_new_file.txt | 1 - .../java/com/gmail/develop/jcant/JDate.java | 7 +- .../com/gmail/develop/jcant/JDateTest.java | 205 ++++++++++++++++++ .../com/gmail/develop/jcant/JDate.class | Bin 6126 -> 0 bytes target/maven-archiver/pom.properties | 5 - .../compile/default-compile/createdFiles.lst | 1 - .../compile/default-compile/inputFiles.lst | 1 - 10 files changed, 221 insertions(+), 14 deletions(-) delete mode 100644 some_new_file.txt create mode 100644 src/test/java/com/gmail/develop/jcant/JDateTest.java delete mode 100644 target/classes/com/gmail/develop/jcant/JDate.class delete mode 100644 target/maven-archiver/pom.properties delete mode 100644 target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst delete mode 100644 target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst diff --git a/.classpath b/.classpath index e23a0f6..1ce4e9c 100644 --- a/.classpath +++ b/.classpath @@ -6,7 +6,7 @@ - + @@ -18,9 +18,9 @@ + - diff --git a/.gitignore b/.gitignore index e58e14f..3ed6619 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,5 @@ /.recommenders/ /RemoteSystemsTempFiles/ .settings/ -target/ -/target/ \ No newline at end of file +target/*.* +/target/ diff --git a/pom.xml b/pom.xml index 3981d99..0959cd6 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,13 @@ 1.6 + + + org.junit.jupiter + junit-jupiter-api + 5.7.0 + test + diff --git a/some_new_file.txt b/some_new_file.txt deleted file mode 100644 index 0fd933f..0000000 --- a/some_new_file.txt +++ /dev/null @@ -1 +0,0 @@ -asdf asdf asdf adsf adsf adsf afds adsf diff --git a/src/main/java/com/gmail/develop/jcant/JDate.java b/src/main/java/com/gmail/develop/jcant/JDate.java index 0e9e671..d581589 100644 --- a/src/main/java/com/gmail/develop/jcant/JDate.java +++ b/src/main/java/com/gmail/develop/jcant/JDate.java @@ -121,7 +121,7 @@ public class JDate { our.set(Calendar.HOUR_OF_DAY, setter.get(Calendar.HOUR_OF_DAY)); our.set(Calendar.MINUTE, setter.get(Calendar.MINUTE)); - our.set(Calendar.SECOND, 0); + our.set(Calendar.SECOND, setter.get(Calendar.SECOND)); return our.getTime(); } @@ -223,7 +223,10 @@ public class JDate { public static int getWeekDay(Date date) { Calendar day = Calendar.getInstance(); day.setTime(date); - return day.get(Calendar.DAY_OF_WEEK); + int num = day.get(Calendar.DAY_OF_WEEK); + num--; + if (num < 1) num = 7; + return num; } public static int getDay(Date date) { diff --git a/src/test/java/com/gmail/develop/jcant/JDateTest.java b/src/test/java/com/gmail/develop/jcant/JDateTest.java new file mode 100644 index 0000000..41f8df5 --- /dev/null +++ b/src/test/java/com/gmail/develop/jcant/JDateTest.java @@ -0,0 +1,205 @@ +package com.gmail.develop.jcant; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.Date; + +import org.junit.jupiter.api.Test; + +public class JDateTest { + + + + @Test + public void testSetDefaultDateFormat() { + JDate.setDefaultDateFormat("DD/MM/YYYY"); + assertEquals(JDate.getDefaultDateFormat(), "DD/MM/YYYY"); + JDate.setDefaultDateFormat("dd-MM-yyyy"); + } + + @Test + public void testGetDefaultDateFormat() { + JDate.setDefaultDateFormat("DD/MM/YYYY"); + assertEquals(JDate.getDefaultDateFormat(), "DD/MM/YYYY"); + JDate.setDefaultDateFormat("dd-MM-yyyy"); + } + + @Test + public void testSetDefaultTimeFormat() { + JDate.setDefaultTimeFormat("HH-MM-SS"); + assertEquals(JDate.getDefaultTimeFormat(), "HH-MM-SS"); + JDate.setDefaultTimeFormat("HH:mm:ss"); + } + + @Test + public void testGetDefaultTimeFormat() { + JDate.setDefaultTimeFormat("HH-MM-SS"); + assertEquals(JDate.getDefaultTimeFormat(), "HH-MM-SS"); + JDate.setDefaultTimeFormat("HH:mm:ss"); + } + + @Test + public void testCreateDate() { + //test creation '01-January-2021': + assertEquals(JDate.createDate(01, 00, 2021).getTime(), 1609452000000l); //01-01-2021 00:00:00 + } + + @Test + public void testGetDateString() { + assertEquals(JDate.getDate("05-05-2021").getTime(), 1620162000000l); //05-05-2021 00:00:00 + } + + @Test + public void testGetDateStringString() { + assertEquals(JDate.getDate("05-05-2021", "08:30:30").getTime(), 1620192630000l); //05-05-2021 08:30:30 + } + + @Test + public void testGetDateDate() { + Date date = new Date(1620192630000l); //05-05-2021 08:30:30 + assertEquals(JDate.getDate(date), "05-05-2021"); + } + + @Test + public void testSetDateDateString() { + Date date = new Date(1620192630000l); //05-05-2021 08:30:30 + assertEquals(JDate.setDate(date, "10-10-2022").getTime(), 1665379830000l); //10-10-2022 08:30:30 + } + + @Test + public void testSetDateDateIntIntInt() { + //test creation '10-October-2022': + Date date = new Date(1620192630000l); //05-05-2021 08:30:30 + assertEquals(JDate.setDate(date, 10, 9, 2022).getTime(), 1665379830000l); //10-10-2022 08:30:30 + } + + @Test + public void testGetTime() { + Date date = new Date(1620192630000l); //05-05-2021 08:30:30 + assertEquals(JDate.getTime(date), "08:30:30"); + } + + @Test + public void testSetTimeDateString() { + Date date = new Date(1665379830000l); //10-10-2022 08:30:30 + assertEquals(JDate.setTime(date, "12:48:11").getTime(), 1665395291000l); //10-10-2022 12:48:11 + } + + @Test + public void testSetTimeDateIntIntInt() { + Date date = new Date(1665379830000l); //10-10-2022 08:30:30 + assertEquals(JDate.setTime(date, 12, 48, 11).getTime(), 1665395291000l); //10-10-2022 12:48:11 + } + + @Test + public void testNullTime() { + Date date = new Date(1665395291000l); //10-10-2022 12:48:11 + assertEquals(JDate.nullTime(date).getTime(), 1665349200000l); //10-10-2022 00:00:00 + } + + @Test + public void testGetHours() { + Date date = new Date(1665395291000l); //10-10-2022 12:48:11 + assertEquals(JDate.getHours(date), 12); + } + + @Test + public void testGetMinutes() { + Date date = new Date(1665395291000l); //10-10-2022 12:48:11 + assertEquals(JDate.getMinutes(date), 48); + } + + @Test + public void testGetSeconds() { + Date date = new Date(1665395291000l); //10-10-2022 12:48:11 + assertEquals(JDate.getSeconds(date), 11); + } + + @Test + public void testIncHours() { + Date date = new Date(1665395291000l); //10-10-2022 12:48:11 + assertEquals(JDate.incHours(date, 3).getTime(), 1665406091000l); //10-10-2022 15:48:11 + } + + @Test + public void testIncMinutes() { + Date date = new Date(1665395291000l); //10-10-2022 12:48:11 + assertEquals(JDate.incMinutes(date, -10).getTime(), 1665394691000l); //10-10-2022 12:38:11 + } + + @Test + public void testIncSeconds() { + Date date = new Date(1665395291000l); //10-10-2022 12:48:11 + assertEquals(JDate.incSeconds(date, 20).getTime(), 1665395311000l); //10-10-2022 12:48:31 + } + + @Test + public void testGetDifferenceDays() { + Date date1 = new Date(1665395291000l); //10-10-2022 12:48:11 + Date date2 = new Date(1662185523000l); //03-09-2022 09:12:03 + Date date3 = new Date(1662200115000l); //03-09-2022 13:15:15 + + assertTrue((JDate.getDifferenceDays(date1, date2) == -37) && (JDate.getDifferenceDays(date3, date1) == 36)); + } + + @Test + public void testGetDifferenceYears() { + Date date1 = new Date(1592204400000l); //15-06-2020 10:00:00 + Date date2 = new Date(1670659200000l); //10-12-2022 10:00:00 + Date date3 = new Date(1577692800000l); //30-12-2019 10:00:00 + Date date4 = new Date(1551600000000l); //03-03-2019 10:00:00 + boolean t1 = JDate.getDifferenceYears(date1, date2) == 2; + boolean t2 = JDate.getDifferenceYears(date1, date3) == -1; + boolean t3 = JDate.getDifferenceYears(date1, date4) == -2; + assertTrue(t1 && t2 && t3); + } + + @Test + public void testGetWeekDay() { + Date date = new Date(1610870400000l); //17-01-2021 10:00:00 - SUNDAY + assertEquals(JDate.getWeekDay(date), 7); + } + + @Test + public void testGetDay() { + Date date = new Date(1610870400000l); //17-01-2021 10:00:00 + assertEquals(JDate.getDay(date), 17); + } + + @Test + public void testGetMonth() { + Date date = new Date(1610870400000l); //17-01-2021 10:00:00 + assertEquals(JDate.getMonth(date), 0); + } + + @Test + public void testGetCorrectMonth() { + Date date = new Date(1610870400000l); //17-01-2021 10:00:00 + assertEquals(JDate.getCorrectMonth(date), 1); + } + + @Test + public void testGetYear() { + Date date = new Date(1610870400000l); //17-01-2021 10:00:00 + assertEquals(JDate.getYear(date), 2021); + } + + @Test + public void testIncDay() { + Date date = new Date(1610870400000l); //17-01-2021 10:00:00 + assertEquals(JDate.incDay(date, 2).getTime(), 1611043200000l); //19-01-2021 10:00:00 + } + + @Test + public void testIncMonth() { + Date date = new Date(1610870400000l); //17-01-2021 10:00:00 + assertEquals(JDate.incMonth(date, 2).getTime(), 1615968000000l); //17-03-2021 10:00:00 + } + + @Test + public void testIncYear() { + Date date = new Date(1610870400000l); //17-01-2021 10:00:00 + assertEquals(JDate.incYear(date, -2).getTime(), 1547712000000l); //17-03-2021 10:00:00 + } + +} diff --git a/target/classes/com/gmail/develop/jcant/JDate.class b/target/classes/com/gmail/develop/jcant/JDate.class deleted file mode 100644 index d3640da1f69c1f9a1632b7228fe4b3df19c72040..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6126 zcmb7HTXa-c8U9Y@OwMHHgbX1eOfDti(uO3{v_Js^v?AAmObQL9jV+g9<|GWvC7nzt z=|!!gt!=GZ?3HR;k)pOJml|kUOVkJJs%v>!x^yj{)CcuNeepqkD1QGwXU@zdlYlJN z&YpAj{=Wb6{r}$Q!;jwoA%Nw0&yU5JsKFvUBEzEw9`i%TgdYYTH}EO>`)L_Iynvd{!R^^&SiTv=o_;MOG90MGGh&lrw>}W-LZoyKB@1| z#$%~Hv0PGqI}i2zq2!o`h5hktx_2ZUOQw1g)=?{!9qm0Fk7e?`+r=g_H;h^NP1CJx z?3`|h~?;R?O;9@KN5|NI&m_@4aKvhlE)<= z4y{I$n(fDV>sY>bXDl~nZ9W#aM)S#Rh75W_!Fk3K!x~ykRt_f9qbcQ-Ed{Qv&RJuW zhlb!(A_Lzr@VbUo6|Az?mI|msc=SA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