Skip to content

Commit

Permalink
Add jakarta support
Browse files Browse the repository at this point in the history
Resolves #476
  • Loading branch information
zabka.pavol authored and fmbenhassine committed Jun 29, 2023
1 parent 4e70b52 commit c4d2a3c
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 46 deletions.
8 changes: 4 additions & 4 deletions easy-random-bean-validation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@
<artifactId>easy-random-randomizers</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<artifactId>jakarta.el</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.jeasy.random.api.RandomizerRegistry;
import org.jeasy.random.util.ReflectionUtils;

import javax.validation.constraints.*;
import jakarta.validation.constraints.*;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import org.jeasy.random.api.Randomizer;
import org.jeasy.random.util.ReflectionUtils;

import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.DecimalMin;
import jakarta.validation.constraints.DecimalMax;
import jakarta.validation.constraints.DecimalMin;
import java.lang.reflect.Field;
import java.math.BigDecimal;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import org.jeasy.random.api.Randomizer;
import org.jeasy.random.util.ReflectionUtils;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import java.lang.reflect.Field;
import java.math.BigDecimal;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.jeasy.random.randomizers.RegularExpressionRandomizer;
import org.jeasy.random.util.ReflectionUtils;

import javax.validation.constraints.Pattern;
import jakarta.validation.constraints.Pattern;
import java.lang.reflect.Field;
import java.util.Random;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.jeasy.random.util.ReflectionUtils;
import org.objenesis.ObjenesisStd;

import javax.validation.constraints.Size;
import jakarta.validation.constraints.Size;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
package org.jeasy.random.validation;

import javax.validation.constraints.*;
import jakarta.validation.constraints.*;
import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDateTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
package org.jeasy.random.validation;

import javax.validation.constraints.*;
import jakarta.validation.constraints.*;
import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDateTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import javax.validation.ConstraintViolation;
import javax.validation.Valid;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.Digits;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Valid;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import jakarta.validation.ValidatorFactory;
import jakarta.validation.constraints.DecimalMax;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.Digits;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
package org.jeasy.random.validation;

import javax.validation.constraints.NotNull;
import jakarta.validation.constraints.NotNull;

public class BeanValidationWithoutReadMethodBean {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import java.util.List;

import javax.validation.constraints.Size;
import jakarta.validation.constraints.Size;

public class EmbeddedBean {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
package org.jeasy.random.validation;

import javax.validation.constraints.Digits;
import jakarta.validation.constraints.Digits;

import org.jeasy.random.EasyRandomParameters;

Expand Down
23 changes: 12 additions & 11 deletions easy-random-core/src/test/java/org/jeasy/random/EasyRandomTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ void nextEnumShouldNotAlwaysReturnTheSameValue() {
}

@Test
// this test fails on jdk17
void fieldsOfTypeClassShouldBeSkipped() {
try {
TestBean testBean = easyRandom.nextObject(TestBean.class);
Expand All @@ -240,18 +241,18 @@ void fieldsOfTypeClassShouldBeSkipped() {
fail("Should skip fields of type Class");
}
}

@Test
void differentCollectionsShouldBeRandomizedWithDifferentSizes() {
// given
class Foo {
List<String> names;
List<String> addresses;
}

// when
Foo foo = new EasyRandom().nextObject(Foo.class);

// then
assertThat(foo.names.size()).isNotEqualTo(foo.addresses.size());
}
Expand All @@ -278,10 +279,10 @@ class Base<T> {
T t;
}
class Concrete extends Base<String> {}

// when
Concrete concrete = easyRandom.nextObject(Concrete.class);

// then
assertThat(concrete.t).isInstanceOf(String.class);
assertThat(concrete.t).isNotEmpty();
Expand All @@ -295,10 +296,10 @@ class Base<T, S> {
S s;
}
class Concrete extends Base<String, Long> {}

// when
Concrete concrete = easyRandom.nextObject(Concrete.class);

// then
assertThat(concrete.t).isInstanceOf(String.class);
assertThat(concrete.s).isInstanceOf(Long.class);
Expand All @@ -324,7 +325,7 @@ public String getY() {

// when
Concrete concrete = easyRandom.nextObject(Concrete.class);

// then
assertThat(concrete.getX().getClass()).isEqualTo(Integer.class);
assertThat(concrete.getY().getClass()).isEqualTo(String.class);
Expand All @@ -348,7 +349,7 @@ public String getY() {

// when
Concrete concrete = easyRandom.nextObject(Concrete.class);

// then
assertThat(concrete.getX().getClass()).isEqualTo(Street.class);
assertThat(concrete.getY().getClass()).isEqualTo(String.class);
Expand All @@ -372,7 +373,7 @@ public String getY() {

// when
Concrete concrete = easyRandom.nextObject(Concrete.class);

// then
assertThat(concrete.getX().getClass()).isEqualTo(BoundedBaseClass.IntWrapper.class);
assertThat(concrete.getY().getClass()).isEqualTo(String.class);
Expand Down Expand Up @@ -410,7 +411,7 @@ class Concrete extends GenericBaseClass<String, Long> {

// when
Concrete concrete = easyRandom.nextObject(Concrete.class);

// then
assertThat(concrete.getX()).isInstanceOf(String.class);
assertThat(concrete.getY()).isInstanceOf(Long.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ void shouldGenerateRandomLocale() {
@Test
void shouldGenerateTheSameValueForTheSameSeed() {
BigDecimal javaVersion = new BigDecimal(System.getProperty("java.specification.version"));
if (javaVersion.compareTo(new BigDecimal("14")) >= 0) {
if (javaVersion.compareTo(new BigDecimal("17")) >= 0) {
assertThat(new LocaleRandomizer(SEED).getRandomValue()).isEqualTo(new Locale("mni", ""));
} else if (javaVersion.compareTo(new BigDecimal("14")) >= 0) {
assertThat(new LocaleRandomizer(SEED).getRandomValue()).isEqualTo(new Locale("rn", "BI"));
} else if (javaVersion.compareTo(new BigDecimal("13")) >= 0) {
}else if (javaVersion.compareTo(new BigDecimal("13")) >= 0) {
assertThat(new LocaleRandomizer(SEED).getRandomValue()).isEqualTo(new Locale("zh", "CN"));
} else if (javaVersion.compareTo(new BigDecimal("11")) >= 0) {
assertThat(new LocaleRandomizer(SEED).getRandomValue()).isEqualTo(new Locale("en", "CK"));
Expand Down
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
<junit.version>5.9.3</junit.version>
<faker.version>1.0.2</faker.version>
<assertj.version>3.24.2</assertj.version>
<validation-api.version>2.0.1.Final</validation-api.version>
<validation-api.version>3.0.2</validation-api.version>
<objenesis.version>3.3</objenesis.version>
<classgraph.version>4.8.160</classgraph.version>
<hibernate-validator.version>8.0.1.Final</hibernate-validator.version>
<javax.el.version>3.0.0</javax.el.version>
<jakarta.el.version>4.0.2</jakarta.el.version>
<mockito.version>5.4.0</mockito.version>
<maven-surefire-plugin.version>3.1.2</maven-surefire-plugin.version>
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
Expand Down Expand Up @@ -98,8 +98,8 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>${validation-api.version}</version>
</dependency>
<dependency>
Expand All @@ -114,14 +114,14 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>${javax.el.version}</version>
<artifactId>jakarta.el</artifactId>
<version>${jakarta.el.version}</version>
</dependency>
<dependency>
<groupId>com.github.javafaker</groupId>
Expand Down

0 comments on commit c4d2a3c

Please sign in to comment.