Skip to content

Commit

Permalink
Version with Java 1.7 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
tvtreeck committed Aug 21, 2018
1 parent 9b9ca6f commit cc71f10
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 81 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>net.lonzak.common</groupId>
<artifactId>unittest-utilities</artifactId>
<name>Automating junit tests</name>
<version>2.0.9</version>
<version>1.3.0</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -33,10 +33,10 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>1.7</source>
<target>1.7</target>
<fork>true</fork>
<compilerVersion>1.8</compilerVersion>
<compilerVersion>1.7</compilerVersion>
</configuration>
</plugin>
<plugin>
Expand Down
122 changes: 62 additions & 60 deletions src/main/java/net/lonzak/common/unittest/AutoTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@
import java.security.cert.X509Certificate;
import java.sql.Blob;
import java.sql.SQLException;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
//import java.time.Instant;
//import java.time.LocalDate;
//import java.time.LocalDateTime;
//import java.time.LocalTime;
//import java.time.ZoneId;
//import java.time.ZoneOffset;
//import java.time.ZonedDateTime;
//import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
Expand Down Expand Up @@ -1660,55 +1660,57 @@ private static void fillSpecialJavaObjects(Class<?>[] parameters, Class<?>[] par
catch (DatatypeConfigurationException e) {
throw new InternalException("Error creating XMLGregorianCalendar!" + e.getMessage(), e);
}
} else if (constructorParameterType.isAssignableFrom(LocalDate.class)) {
paramListLeft[parameterIndex] = LocalDate.class;
paramListRight[parameterIndex] = LocalDate.class;

argListLeft[parameterIndex] = LocalDate.of(2020, 02, 29);
argListRight[parameterIndex] = LocalDate.of(2020, 02, 29);
} else if (constructorParameterType.isAssignableFrom(LocalTime.class)) {
paramListLeft[parameterIndex] = LocalTime.class;
paramListRight[parameterIndex] = LocalTime.class;

argListLeft[parameterIndex] = LocalTime.of(23, 59, 59, 999999999);
argListRight[parameterIndex] = LocalTime.of(23, 59, 59, 999999999);
} else if (constructorParameterType.isAssignableFrom(LocalDateTime.class)) {
paramListLeft[parameterIndex] = LocalDateTime.class;
paramListRight[parameterIndex] = LocalDateTime.class;

argListLeft[parameterIndex] = LocalDateTime.of(2020, 02, 29, 23, 59, 59, 999999999);
argListRight[parameterIndex] = LocalDateTime.of(2020, 02, 29, 23, 59, 59, 999999999);
} else if (constructorParameterType.isAssignableFrom(ZoneId.class)) {
paramListLeft[parameterIndex] = ZoneId.class;
paramListRight[parameterIndex] = ZoneId.class;

argListLeft[parameterIndex] = ZoneId.systemDefault();
argListRight[parameterIndex] = ZoneId.systemDefault();
} else if (constructorParameterType.isAssignableFrom(ZoneOffset.class)) {
paramListLeft[parameterIndex] = ZoneOffset.class;
paramListRight[parameterIndex] = ZoneOffset.class;

argListLeft[parameterIndex] = ZoneOffset.ofHoursMinutesSeconds(17, 59, 59);
argListRight[parameterIndex] = ZoneOffset.ofHoursMinutesSeconds(17, 59, 59);
} else if (constructorParameterType.isAssignableFrom(DateTimeFormatter.class)) {
paramListLeft[parameterIndex] = DateTimeFormatter.class;
paramListRight[parameterIndex] = DateTimeFormatter.class;

argListLeft[parameterIndex] = DateTimeFormatter.BASIC_ISO_DATE;
argListRight[parameterIndex] = DateTimeFormatter.BASIC_ISO_DATE;
} else if (constructorParameterType.isAssignableFrom(Instant.class)) {
paramListLeft[parameterIndex] = Instant.class;
paramListRight[parameterIndex] = Instant.class;

argListLeft[parameterIndex] = Instant.ofEpochSecond(1, 999999999);
argListRight[parameterIndex] = Instant.ofEpochSecond(1, 999999999);
} else if (constructorParameterType.isAssignableFrom(ZonedDateTime.class)) {
paramListLeft[parameterIndex] = ZonedDateTime.class;
paramListRight[parameterIndex] = ZonedDateTime.class;

argListLeft[parameterIndex] = ZonedDateTime.of(2020, 02, 29, 23, 59, 59, 999999999, ZoneId.systemDefault());
argListRight[parameterIndex] = ZonedDateTime.of(2020, 02, 29, 23, 59, 59, 999999999, ZoneId.systemDefault());
} else {
}
// else if (constructorParameterType.isAssignableFrom(LocalDate.class)) {
// paramListLeft[parameterIndex] = LocalDate.class;
// paramListRight[parameterIndex] = LocalDate.class;
//
// argListLeft[parameterIndex] = LocalDate.of(2020, 02, 29);
// argListRight[parameterIndex] = LocalDate.of(2020, 02, 29);
// } else if (constructorParameterType.isAssignableFrom(LocalTime.class)) {
// paramListLeft[parameterIndex] = LocalTime.class;
// paramListRight[parameterIndex] = LocalTime.class;
//
// argListLeft[parameterIndex] = LocalTime.of(23, 59, 59, 999999999);
// argListRight[parameterIndex] = LocalTime.of(23, 59, 59, 999999999);
// } else if (constructorParameterType.isAssignableFrom(LocalDateTime.class)) {
// paramListLeft[parameterIndex] = LocalDateTime.class;
// paramListRight[parameterIndex] = LocalDateTime.class;
//
// argListLeft[parameterIndex] = LocalDateTime.of(2020, 02, 29, 23, 59, 59, 999999999);
// argListRight[parameterIndex] = LocalDateTime.of(2020, 02, 29, 23, 59, 59, 999999999);
// } else if (constructorParameterType.isAssignableFrom(ZoneId.class)) {
// paramListLeft[parameterIndex] = ZoneId.class;
// paramListRight[parameterIndex] = ZoneId.class;
//
// argListLeft[parameterIndex] = ZoneId.systemDefault();
// argListRight[parameterIndex] = ZoneId.systemDefault();
// } else if (constructorParameterType.isAssignableFrom(ZoneOffset.class)) {
// paramListLeft[parameterIndex] = ZoneOffset.class;
// paramListRight[parameterIndex] = ZoneOffset.class;
//
// argListLeft[parameterIndex] = ZoneOffset.ofHoursMinutesSeconds(17, 59, 59);
// argListRight[parameterIndex] = ZoneOffset.ofHoursMinutesSeconds(17, 59, 59);
// } else if (constructorParameterType.isAssignableFrom(DateTimeFormatter.class)) {
// paramListLeft[parameterIndex] = DateTimeFormatter.class;
// paramListRight[parameterIndex] = DateTimeFormatter.class;
//
// argListLeft[parameterIndex] = DateTimeFormatter.BASIC_ISO_DATE;
// argListRight[parameterIndex] = DateTimeFormatter.BASIC_ISO_DATE;
// } else if (constructorParameterType.isAssignableFrom(Instant.class)) {
// paramListLeft[parameterIndex] = Instant.class;
// paramListRight[parameterIndex] = Instant.class;
//
// argListLeft[parameterIndex] = Instant.ofEpochSecond(1, 999999999);
// argListRight[parameterIndex] = Instant.ofEpochSecond(1, 999999999);
// } else if (constructorParameterType.isAssignableFrom(ZonedDateTime.class)) {
// paramListLeft[parameterIndex] = ZonedDateTime.class;
// paramListRight[parameterIndex] = ZonedDateTime.class;
//
// argListLeft[parameterIndex] = ZonedDateTime.of(2020, 02, 29, 23, 59, 59, 999999999, ZoneId.systemDefault());
// argListRight[parameterIndex] = ZonedDateTime.of(2020, 02, 29, 23, 59, 59, 999999999, ZoneId.systemDefault());
// }
else {
throw new AssertionError("Unsupported class: " + constructorParameterType.getName()
+ " - report this to the unittest-utilities project! (And for now disable automatic testing for that class)");
}
Expand Down Expand Up @@ -2144,7 +2146,7 @@ private static boolean objectHasChanged(Object left, Object right) {
private static void compareOldAndNew(Class<?> dtoClass, Method method, Object[] argList, Object constructor)
throws IllegalAccessException, InvocationTargetException {

// extract the old values for a later comparison (old=value after creating object with constructor)
// extract the old values for a later comparison (old=value after creating object with construcdtor)
ExtractionValue oldValueOfTheField = extractValueFromField(dtoClass, method, constructor);
ExtractionValue oldValueOfGetter = extractValueFromGetter(dtoClass, method, constructor);

Expand Down Expand Up @@ -2311,9 +2313,9 @@ private static void specialValuesValid(Constructor<?>[] constructors, SpecialVal

for (Constructor<?> constructor : constructors) {

boolean numberOfArgumentsMatch = value.getNumberOfArguments() == constructor.getParameterCount();
boolean numberOfArgumentsMatch = value.getNumberOfArguments() == constructor.getParameterTypes().length;

if (numberOfArgumentsMatch && constructor.getParameterCount() >= value.getParameterIndex()) {
if (numberOfArgumentsMatch && constructor.getParameterTypes().length >= value.getParameterIndex()) {
Class<?> paramType = constructor.getParameterTypes()[value.getParameterIndex() - 1];
if (paramType.isAssignableFrom(value.getDataType())) {
foundMatch = true;
Expand Down
34 changes: 17 additions & 17 deletions src/test/java/net/lonzak/common/unittest/AutoTesterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
package net.lonzak.common.unittest;

import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
//import java.time.Instant;
//import java.time.LocalDate;
//import java.time.LocalDateTime;
//import java.time.LocalTime;
//import java.time.ZoneOffset;
//import java.time.ZonedDateTime;
//import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;
Expand Down Expand Up @@ -100,16 +100,16 @@ public void testPrivate() {
AutoTester.testPrivateMethod(map.keySet().toArray()[0], "setA", "TEST");
}

@Test
public void testTimes() {
AutoTester.testClass(LocalTime.class);
AutoTester.testClass(LocalDate.class);
AutoTester.testClass(LocalDateTime.class);
AutoTester.testClass(ZoneOffset.class);
AutoTester.testClass(DateTimeFormatter.class);
AutoTester.testClass(Instant.class);
AutoTester.testClass(ZonedDateTime.class);
}
// @Test
// public void testTimes() {
// AutoTester.testClass(LocalTime.class);
// AutoTester.testClass(LocalDate.class);
// AutoTester.testClass(LocalDateTime.class);
// AutoTester.testClass(ZoneOffset.class);
// AutoTester.testClass(DateTimeFormatter.class);
// AutoTester.testClass(Instant.class);
// AutoTester.testClass(ZonedDateTime.class);
// }

@Test
public void testArrays() {
Expand Down

0 comments on commit cc71f10

Please sign in to comment.