Browse Source

create testing-class !!!

master
parent
commit
357adfcb94
10 changed files with 221 additions and 14 deletions
  1. +2
    -2
      .classpath
  2. +2
    -2
      .gitignore
  3. +7
    -0
      pom.xml
  4. +0
    -1
      some_new_file.txt
  5. +5
    -2
      src/main/java/com/gmail/develop/jcant/JDate.java
  6. +205
    -0
      src/test/java/com/gmail/develop/jcant/JDateTest.java
  7. BIN
      target/classes/com/gmail/develop/jcant/JDate.class
  8. +0
    -5
      target/maven-archiver/pom.properties
  9. +0
    -1
      target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
  10. +0
    -1
      target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst

+ 2
- 2
.classpath View File

@ -6,7 +6,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@ -18,9 +18,9 @@
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>


+ 2
- 2
.gitignore View File

@ -2,5 +2,5 @@
/.recommenders/
/RemoteSystemsTempFiles/
.settings/
target/
/target/
target/*.*
/target/

+ 7
- 0
pom.xml View File

@ -19,6 +19,13 @@
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>


+ 0
- 1
some_new_file.txt View File

@ -1 +0,0 @@
asdf asdf asdf adsf adsf adsf afds adsf

+ 5
- 2
src/main/java/com/gmail/develop/jcant/JDate.java View File

@ -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) {


+ 205
- 0
src/test/java/com/gmail/develop/jcant/JDateTest.java View File

@ -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
}
}

BIN
target/classes/com/gmail/develop/jcant/JDate.class View File


+ 0
- 5
target/maven-archiver/pom.properties View File

@ -1,5 +0,0 @@
#Generated by Maven
#Mon Oct 28 20:17:45 EET 2019
groupId=com.gmail.develop.jcant
artifactId=JDate
version=1.9

+ 0
- 1
target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst View File

@ -1 +0,0 @@
com/gmail/develop/jcant/JDate.class

+ 0
- 1
target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst View File

@ -1 +0,0 @@
/home/jcadm/LuckyProject/Helpers/JDate/src/main/java/com/gmail/develop/jcant/JDate.java

Loading…
Cancel
Save