From 21dfdbb7029c3fbf488573eb25b90530aca8e44d Mon Sep 17 00:00:00 2001 From: Yves Galante Date: Fri, 16 Feb 2024 09:36:17 +0100 Subject: [PATCH 1/4] fix(test): Fix CronConverterTest that failed on Standard Time - America/St_Johns UTC-3:30 Standard Time - America/St_Johns UTC-2:30 Daylight Time --- .../cronutils/converter/CronConverter.java | 104 +++++++++--------- .../converter/CronConverterTest.java | 83 +++++++++----- 2 files changed, 107 insertions(+), 80 deletions(-) diff --git a/src/main/java/com/cronutils/converter/CronConverter.java b/src/main/java/com/cronutils/converter/CronConverter.java index 4e1416b0..a7ebb69c 100644 --- a/src/main/java/com/cronutils/converter/CronConverter.java +++ b/src/main/java/com/cronutils/converter/CronConverter.java @@ -13,71 +13,75 @@ package com.cronutils.converter; +import com.cronutils.utils.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.time.ZoneId; import java.util.Calendar; import java.util.TimeZone; - -import com.cronutils.utils.StringUtils; +import java.util.function.Function; public class CronConverter { - private static final Logger LOGGER = LoggerFactory.getLogger(CronConverter.class); + private static final Logger LOGGER = LoggerFactory.getLogger(CronConverter.class); + private static final Function DEFAULT_CALENDAR_FACTORY = (zoneId) -> Calendar.getInstance(TimeZone.getTimeZone(zoneId)); + + private static final String CRON_FIELDS_SEPARATOR = " "; + private String[] cronParts; + private Calendar fromCalendar; + private String sourceCron; + private ZoneId sourceZoneId; + private ZoneId targetZoneId; - private static final String CRON_FIELDS_SEPARATOR = " "; - private String[] cronParts; - private Calendar fromCalendar; - private String sourceCron; - private ZoneId sourceZoneId; - private ZoneId targetZoneId; + private CronToCalendarTransformer toCalendarConverter; + private CalendarToCronTransformer toCronConverter; - private CronToCalendarTransformer toCalendarConverter; - private CalendarToCronTransformer toCronConverter; + private Function calendarFactory; - public CronConverter(CronToCalendarTransformer toCalendarConverter, CalendarToCronTransformer toCronConverter){ - this.toCalendarConverter = toCalendarConverter; - this.toCronConverter = toCronConverter; - } + public CronConverter(CronToCalendarTransformer toCalendarConverter, CalendarToCronTransformer toCronConverter) { + this(toCalendarConverter, toCronConverter, DEFAULT_CALENDAR_FACTORY); + } - public CronConverter using(String cronExpression) { - this.sourceCron = cronExpression; - cronParts = cronExpression.split(CRON_FIELDS_SEPARATOR); - LOGGER.debug("Cron '{}' split into {}", cronExpression, cronParts); - return this; - } + public CronConverter(CronToCalendarTransformer toCalendarConverter, CalendarToCronTransformer toCronConverter, Function calendarFactory) { + this.toCalendarConverter = toCalendarConverter; + this.toCronConverter = toCronConverter; + this.calendarFactory = calendarFactory; + } - public CronConverter from(ZoneId zoneId) { - sourceZoneId = zoneId; - fromCalendar = getCalendar(zoneId); - toCalendarConverter.apply(cronParts, fromCalendar); - LOGGER.debug("Calendar object built using cron :{} and zoneID {} => {}", - cronParts, zoneId, fromCalendar); - return this; - } + public CronConverter using(String cronExpression) { + this.sourceCron = cronExpression; + cronParts = cronExpression.split(CRON_FIELDS_SEPARATOR); + LOGGER.debug("Cron '{}' split into {}", cronExpression, cronParts); + return this; + } - public CronConverter to(ZoneId zoneId) { - targetZoneId = zoneId; - Calendar toCalendar = getCalendar(zoneId); - toCalendar.setTimeInMillis(fromCalendar.getTimeInMillis()); - LOGGER.debug( - "Calendar object built from calendar {} and zoneID {} => {}", - fromCalendar, zoneId, toCalendar); - toCronConverter.apply(cronParts, toCalendar); - LOGGER.debug("cron after applying calendar {} => {}", toCalendar, - cronParts); - return this; - } + public CronConverter from(ZoneId zoneId) { + sourceZoneId = zoneId; + fromCalendar = calendarFactory.apply(zoneId); + toCalendarConverter.apply(cronParts, fromCalendar); + LOGGER.debug("Calendar object built using cron :{} and zoneID {} => {}", + cronParts, zoneId, fromCalendar); + return this; + } - public String convert() { - String targetCron = StringUtils.join(cronParts, CRON_FIELDS_SEPARATOR); - LOGGER.info("Converted CRON -- {} :[{}] => {} :[{}]", sourceZoneId, - sourceCron, targetZoneId, targetCron); - return targetCron; - } + public CronConverter to(ZoneId zoneId) { + targetZoneId = zoneId; + Calendar toCalendar = calendarFactory.apply(zoneId); + toCalendar.setTimeInMillis(fromCalendar.getTimeInMillis()); + LOGGER.debug( + "Calendar object built from calendar {} and zoneID {} => {}", + fromCalendar, zoneId, toCalendar); + toCronConverter.apply(cronParts, toCalendar); + LOGGER.debug("cron after applying calendar {} => {}", toCalendar, + cronParts); + return this; + } - private Calendar getCalendar(ZoneId id) { - return Calendar.getInstance(TimeZone.getTimeZone(id)); - } + public String convert() { + String targetCron = StringUtils.join(cronParts, CRON_FIELDS_SEPARATOR); + LOGGER.info("Converted CRON -- {} :[{}] => {} :[{}]", sourceZoneId, + sourceCron, targetZoneId, targetCron); + return targetCron; + } } diff --git a/src/test/java/com/cronutils/converter/CronConverterTest.java b/src/test/java/com/cronutils/converter/CronConverterTest.java index 364dc6dc..0344c9b2 100644 --- a/src/test/java/com/cronutils/converter/CronConverterTest.java +++ b/src/test/java/com/cronutils/converter/CronConverterTest.java @@ -13,44 +13,67 @@ package com.cronutils.converter; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import java.time.ZoneId; +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.TimeZone; +import java.util.function.Function; import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.spy; public class CronConverterTest { - private CronConverter cronConverter = spy(new CronConverter( - new CronToCalendarTransformer(), - new CalendarToCronTransformer() - )); - - public static Stream cronExpressions() { - return Stream.of(Arguments.of("Pacific/Pago_Pago", "15 * * * *", "15 * * * *"), - Arguments.of("Antarctica/Casey", "? * * * *", "? * * * *"), - Arguments.of("Antarctica/Troll", "45 * * * *", "45 * * * *"), - Arguments.of("Pacific/Chatham", "15 * * * *", "30 * * * *"), - Arguments.of("Asia/Colombo", "45 * * ? *", "15 * * ? *"), - Arguments.of("Asia/Colombo", "0/45 * * ? *", "0/45 * * ? *"), - Arguments.of("Australia/Eucla", "13 * * ? *", "28 * * ? *"), - Arguments.of("America/St_Johns", "0 0/15 * * * ?", "30 0/15 * * * ?"), - Arguments.of("America/St_Johns", "0 8 * * ?", "30 10 * * ?"), - Arguments.of("America/St_Johns", "0 0/1 * * ?", "30 0/1 * * ?"), - Arguments.of("America/St_Johns", "20 0 * * ?", "50 2 * * ?"), - Arguments.of("Asia/Kolkata", "20 0 * * ?", "50 18 * * ?") - ); - } - - @ParameterizedTest - @MethodSource("cronExpressions") - public void testCronConverterBuilder(String timezone, String inputCronExpression, String expectedCronExpression) { - assertEquals(expectedCronExpression, - cronConverter.using(inputCronExpression) - .from(ZoneId.of(timezone)).to(ZoneId.of("UTC")) - .convert()); - } + + // Fix the date to prevent test failure during the transition between Standard Time and Daylight Time. + Function calendarFactory = (zoneId) -> { + Calendar fixedDay = new GregorianCalendar(2020, 06, 01); + fixedDay.setTimeZone(TimeZone.getTimeZone(zoneId)); + return fixedDay; + }; + + private CronConverter cronConverter = new CronConverter( + new CronToCalendarTransformer(), + new CalendarToCronTransformer(), + calendarFactory + ); + + public static Stream cronExpressions() { + return Stream.of(Arguments.of("Pacific/Pago_Pago", "15 * * * *", "15 * * * *"), + Arguments.of("Antarctica/Casey", "? * * * *", "? * * * *"), + Arguments.of("Antarctica/Troll", "45 * * * *", "45 * * * *"), + Arguments.of("Pacific/Chatham", "15 * * * *", "30 * * * *"), + Arguments.of("Asia/Colombo", "45 * * ? *", "15 * * ? *"), + Arguments.of("Asia/Colombo", "0/45 * * ? *", "0/45 * * ? *"), + Arguments.of("Australia/Eucla", "13 * * ? *", "28 * * ? *"), + Arguments.of("America/St_Johns", "0 0/15 * * * ?", "30 0/15 * * * ?"), + Arguments.of("America/St_Johns", "0 8 * * ?", "30 10 * * ?"), + Arguments.of("America/St_Johns", "0 0/1 * * ?", "30 0/1 * * ?"), + Arguments.of("America/St_Johns", "20 0 * * ?", "50 2 * * ?"), + Arguments.of("Asia/Kolkata", "20 0 * * ?", "50 18 * * ?") + ); + } + + @ParameterizedTest + @MethodSource("cronExpressions") + public void testCronConverterBuilder(String timezone, String inputCronExpression, String expectedCronExpression) { + assertEquals(expectedCronExpression, + cronConverter.using(inputCronExpression) + .from(ZoneId.of(timezone)).to(ZoneId.of("UTC")) + .convert()); + } + + @Test + public void testCronExpressionsDefaultTimeFactory() { + CronConverter defaultCronConverter = new CronConverter(new CronToCalendarTransformer(), new CalendarToCronTransformer()); + // No Daylight Time @ Kolkata + assertEquals("50 18 * * ?", + defaultCronConverter.using("20 0 * * ?") + .from(ZoneId.of("Asia/Kolkata")).to(ZoneId.of("UTC")) + .convert()); + } } From cb599f4a86f2ce0efa0a8e86cb76816dfa96c709 Mon Sep 17 00:00:00 2001 From: Yves Galante Date: Fri, 16 Feb 2024 09:42:44 +0100 Subject: [PATCH 2/4] feat(validation): Add new @Cron validation expression based on jakarta.validation #618 --- README.md | 4 +- pom.xml | 13 ++++ .../validation/AbstractCronValidator.java | 25 +++++++ .../java/com/cronutils/validation/Cron.java | 2 +- .../cronutils/validation/CronValidator.java | 19 +---- .../cronutils/validation/jakarta/Cron.java | 24 +++++++ .../jakarta/CronJakartaValidator.java | 24 +++++++ .../jakarta/CronJakartaTestValidatorTest.java | 69 +++++++++++++++++++ 8 files changed, 160 insertions(+), 20 deletions(-) create mode 100644 src/main/java/com/cronutils/validation/AbstractCronValidator.java create mode 100644 src/main/java/com/cronutils/validation/jakarta/Cron.java create mode 100644 src/main/java/com/cronutils/validation/jakarta/CronJakartaValidator.java create mode 100644 src/test/java/com/cronutils/validation/jakarta/CronJakartaTestValidatorTest.java diff --git a/README.md b/README.md index 6fc94ed3..3663cbbb 100644 --- a/README.md +++ b/README.md @@ -20,12 +20,10 @@ cron-utils is available on [Maven central](http://search.maven.org/#search%7Cga% For Android developers, cron-utils 7.0.0 assumes Android 26+. For earlier Android versions consider using cron-utils 6.0.6. -If using ScheduleExpression from Java EE, this should be provided as a runtime dependency. +If using ScheduleExpression from Java EE or Jakarta, this should be provided as a runtime dependency. **Current development** -*We are currently working to update the codebase towards JDK 16, to ensure will be fully compatible with JDK 17 when released.* - Now we are developing a new generation of cron-descriptors using neural-translation! Any kind of contributions are welcome: from help with dataset generation to machine learning models training and utilities to load them! If interested, please follow issue [#3](https://github.com/jmrozanec/cron-utils/issues/3) **Features** diff --git a/pom.xml b/pom.xml index cf685796..3aecb880 100644 --- a/pom.xml +++ b/pom.xml @@ -81,6 +81,12 @@ 2.0.1.Final provided + + jakarta.validation + jakarta.validation-api + 3.0.2 + provided + @@ -123,6 +129,13 @@ test + + org.hibernate.validator + hibernate-validator + 7.0.5.Final + test + + javax.el diff --git a/src/main/java/com/cronutils/validation/AbstractCronValidator.java b/src/main/java/com/cronutils/validation/AbstractCronValidator.java new file mode 100644 index 00000000..a107cb6f --- /dev/null +++ b/src/main/java/com/cronutils/validation/AbstractCronValidator.java @@ -0,0 +1,25 @@ +package com.cronutils.validation; + +import com.cronutils.model.CronType; +import com.cronutils.model.definition.CronDefinition; +import com.cronutils.model.definition.CronDefinitionBuilder; +import com.cronutils.parser.CronParser; + +public abstract class AbstractCronValidator { + + private CronType type; + + protected void initialize(CronType constraintAnnotation) { + this.type = constraintAnnotation; + } + + protected boolean isValid(String value) throws IllegalArgumentException { + if (value == null) { + return true; + } + CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(type); + CronParser cronParser = new CronParser(cronDefinition); + cronParser.parse(value).validate(); + return true; + } +} diff --git a/src/main/java/com/cronutils/validation/Cron.java b/src/main/java/com/cronutils/validation/Cron.java index d022e1fd..cff760df 100644 --- a/src/main/java/com/cronutils/validation/Cron.java +++ b/src/main/java/com/cronutils/validation/Cron.java @@ -21,4 +21,4 @@ CronType type(); -} \ No newline at end of file +} diff --git a/src/main/java/com/cronutils/validation/CronValidator.java b/src/main/java/com/cronutils/validation/CronValidator.java index bf7350c8..a05d0a08 100644 --- a/src/main/java/com/cronutils/validation/CronValidator.java +++ b/src/main/java/com/cronutils/validation/CronValidator.java @@ -1,33 +1,20 @@ package com.cronutils.validation; -import com.cronutils.model.CronType; -import com.cronutils.model.definition.CronDefinition; -import com.cronutils.model.definition.CronDefinitionBuilder; -import com.cronutils.parser.CronParser; - import javax.validation.ConstraintValidator; import javax.validation.ConstraintValidatorContext; -public class CronValidator implements ConstraintValidator { +public class CronValidator extends AbstractCronValidator implements ConstraintValidator { - private CronType type; @Override public void initialize(Cron constraintAnnotation) { - this.type = constraintAnnotation.type(); + super.initialize(constraintAnnotation.type()); } @Override public boolean isValid(String value, ConstraintValidatorContext context) { - if (value == null) { - return true; - } - - CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(type); - CronParser cronParser = new CronParser(cronDefinition); try { - cronParser.parse(value).validate(); - return true; + return super.isValid(value); } catch (IllegalArgumentException e) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(e.getMessage()).addConstraintViolation(); diff --git a/src/main/java/com/cronutils/validation/jakarta/Cron.java b/src/main/java/com/cronutils/validation/jakarta/Cron.java new file mode 100644 index 00000000..bad69c90 --- /dev/null +++ b/src/main/java/com/cronutils/validation/jakarta/Cron.java @@ -0,0 +1,24 @@ +package com.cronutils.validation.jakarta; + +import com.cronutils.model.CronType; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; + +import java.lang.annotation.*; + +@Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = CronJakartaValidator.class) +@Inherited +@Documented +public @interface Cron { + + String message() default "UNUSED"; + + Class[] groups() default {}; + + Class[] payload() default {}; + + CronType type(); + +} \ No newline at end of file diff --git a/src/main/java/com/cronutils/validation/jakarta/CronJakartaValidator.java b/src/main/java/com/cronutils/validation/jakarta/CronJakartaValidator.java new file mode 100644 index 00000000..d886a05c --- /dev/null +++ b/src/main/java/com/cronutils/validation/jakarta/CronJakartaValidator.java @@ -0,0 +1,24 @@ +package com.cronutils.validation.jakarta; + +import com.cronutils.validation.AbstractCronValidator; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; + +public class CronJakartaValidator extends AbstractCronValidator implements ConstraintValidator { + + @Override + public void initialize(Cron constraintAnnotation) { + super.initialize(constraintAnnotation.type()); + } + + @Override + public boolean isValid(String value, ConstraintValidatorContext context) { + try { + return super.isValid(value); + } catch (IllegalArgumentException e) { + context.disableDefaultConstraintViolation(); + context.buildConstraintViolationWithTemplate(e.getMessage()).addConstraintViolation(); + return false; + } + } +} diff --git a/src/test/java/com/cronutils/validation/jakarta/CronJakartaTestValidatorTest.java b/src/test/java/com/cronutils/validation/jakarta/CronJakartaTestValidatorTest.java new file mode 100644 index 00000000..845c5009 --- /dev/null +++ b/src/test/java/com/cronutils/validation/jakarta/CronJakartaTestValidatorTest.java @@ -0,0 +1,69 @@ +package com.cronutils.validation.jakarta; + +import com.cronutils.model.CronType; +import jakarta.validation.ConstraintViolation; +import jakarta.validation.Validation; +import jakarta.validation.Validator; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Set; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class CronJakartaTestValidatorTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(CronJakartaTestValidatorTest.class); + + private final Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); + + public static Stream expressions() { + return Stream.of( + Arguments.of("0 0 * * * *", true), + Arguments.of("*/10 * * * * *", true), + Arguments.of("0 0 8-10 * * *", true), + Arguments.of("0 0 6,19 * * *", true), + Arguments.of("0 0/30 8-10 * * *", true), + Arguments.of("0 0 9-17 * * MON-FRI", true), + Arguments.of("0 0 0 25 12 ?", true), + Arguments.of("0 0 0 L 12 ?", false), + Arguments.of("1,2, * * * * *", false), + Arguments.of("1- * * * * *", false), + // Verification for RCE security vulnerability fix: https://github.com/jmrozanec/cron-utils/issues/461 + Arguments.of("java.lang.Runtime.getRuntime().exec('touch /tmp/pwned'); // 4 5 [${''.getClass().forName('javax.script.ScriptEngineManager').newInstance().getEngineByName('js').eval(validatedValue)}]", false) + ); + } + + @ParameterizedTest(name = "{0} ") + @MethodSource("expressions") + public void validateExamples(String expression, boolean valid) { + TestPojo testPojo = new TestPojo(expression); + Set> violations = validator.validate(testPojo); + violations.stream().map(ConstraintViolation::getMessage).forEach(LOGGER::info); + + if (valid) { + assertTrue(violations.isEmpty()); + } else { + assertFalse(violations.isEmpty()); + } + } + + public static class TestPojo { + @Cron(type = CronType.SPRING) + private final String cron; + + public TestPojo(String cron) { + this.cron = cron; + } + + public String getCron() { + return cron; + } + + } +} From 0d8a5574639f8b803c20fbc447f62e3dc64506e4 Mon Sep 17 00:00:00 2001 From: Yves Galante Date: Fri, 16 Feb 2024 10:01:47 +0100 Subject: [PATCH 3/4] feat(pom.xml): Update dependencies versions & maven plugins - Replace com.cronutils.Function by java.util.function.Function --- .github/workflows/maven-publish.yml | 8 +- .github/workflows/maven-test.yml | 11 +- pom.xml | 49 ++- pom.xml.jdk16 | 400 ------------------ src/main/java/com/cronutils/Function.java | 28 -- .../descriptor/DescriptionStrategy.java | 2 +- .../DescriptionStrategyFactory.java | 2 +- .../NominalDescriptionStrategy.java | 2 +- .../descriptor/TimeDescriptionStrategy.java | 2 +- .../java/com/cronutils/mapper/CronMapper.java | 5 +- .../java/com/cronutils/mapper/WeekDay.java | 2 +- .../ValueMappingFieldExpressionVisitor.java | 3 +- .../generator/AndFieldValueGenerator.java | 2 +- src/test/java/com/cronutils/Issue430Test.java | 3 +- src/test/java/com/cronutils/Issue446Test.java | 3 +- src/test/java/com/cronutils/Issue462Test.java | 6 +- src/test/java/com/cronutils/Issue470Test.java | 11 +- src/test/java/com/cronutils/Issue477Test.java | 11 +- src/test/java/com/cronutils/Issue499Test.java | 5 +- src/test/java/com/cronutils/Issue503Test.java | 5 +- src/test/java/com/cronutils/Issue512Test.java | 15 +- src/test/java/com/cronutils/Issue528Test.java | 2 +- src/test/java/com/cronutils/Issue539Test.java | 2 +- .../com/cronutils/mapper/CronMapperTest.java | 8 +- .../java/com/cronutils/model/CronTest.java | 5 +- .../definition/CronDefinitionBuilderTest.java | 4 +- .../model/definition/CronDefinitionTest.java | 15 +- .../model/definition/FieldDefinitionTest.java | 5 +- .../model/definition/Issue343Test.java | 3 +- .../cronutils/model/field/CronFieldTest.java | 5 +- .../field/FieldDefinitionBuilderTest.java | 6 +- .../model/field/FieldParserTest.java | 4 +- .../field/expression/FieldExpressionTest.java | 3 +- .../ValidationFieldExpressionVisitorTest.java | 9 +- ...alueMappingFieldExpressionVisitorTest.java | 3 +- .../FieldValueGeneratorFactoryTest.java | 4 +- .../OnDayOfMonthValueGeneratorTest.java | 4 +- .../OnDayOfWeekValueGeneratorTest.java | 4 +- .../cronutils/parser/CronParserFieldTest.java | 5 +- .../com/cronutils/parser/CronParserTest.java | 9 +- .../utils/CronFrequencyComparatorTest.java | 3 +- .../com/cronutils/utils/StringUtilsTest.java | 4 +- .../utils/descriptor/CronDescriptorTest.java | 5 +- .../utils/descriptor/TestDescriptor.java | 15 +- .../org.mockito.plugins.MockMaker | 1 + 45 files changed, 134 insertions(+), 569 deletions(-) delete mode 100644 pom.xml.jdk16 delete mode 100644 src/main/java/com/cronutils/Function.java create mode 100644 src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index 83fdfbae..2d7aab42 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -21,19 +21,19 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up JDK 1.8 - uses: actions/setup-java@v1 + uses: actions/setup-java@v4 with: java-version: 1.8 server-id: github # Value of the distributionManagement/repository/id field of the pom.xml settings-path: ${{ github.workspace }} # location for the settings.xml file - name: compile and test - run: mvn compile test --file pom.xml + run: mvn -B compile test --file pom.xml - name: build source code - run: mvn -B package --file pom.xml + run: mvn -B -DskipTests=true package --file pom.xml - name: Publish to GitHub Packages Apache Maven run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml diff --git a/.github/workflows/maven-test.yml b/.github/workflows/maven-test.yml index 53fdc762..1ce4367a 100644 --- a/.github/workflows/maven-test.yml +++ b/.github/workflows/maven-test.yml @@ -15,20 +15,19 @@ on: jobs: build: - strategy: matrix: - java: [ '16' ] + java: [ '8', '16' ] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up JDK - uses: actions/setup-java@v2 + - uses: actions/checkout@v4 + - name: Set up JDK ${{ matrix.java }} + uses: actions/setup-java@v4 with: distribution: 'zulu' java-version: ${{ matrix.java }} - name: compile and test - run: mvn compile test --file pom.xml + run: mvn -B compile test --file pom.xml diff --git a/pom.xml b/pom.xml index 3aecb880..11aed21e 100644 --- a/pom.xml +++ b/pom.xml @@ -59,8 +59,8 @@ - 2.0.7 - 5.8.1 + 2.0.12 + 5.10.2 4.11.0 github @@ -103,7 +103,7 @@ org.mockito - mockito-inline + mockito-junit-jupiter ${mockito.version} test @@ -125,7 +125,7 @@ org.springframework spring-context - 5.3.26 + 5.3.31 test @@ -136,7 +136,6 @@ test - javax.el javax.el-api @@ -162,7 +161,7 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.2.1 + 3.3.1 config/checkstyle.xml @@ -170,7 +169,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.11.0 + 3.12.1 1.8 1.8 @@ -179,7 +178,7 @@ org.apache.maven.plugins maven-assembly-plugin - 3.5.0 + 3.6.0 @@ -194,7 +193,7 @@ org.apache.maven.plugins maven-source-plugin - 3.2.1 + 3.3.0 attach-sources @@ -204,15 +203,16 @@ + org.apache.maven.plugins maven-clean-plugin - 3.2.0 + 3.3.2 org.apache.maven.plugins maven-install-plugin - 3.1.0 + 3.1.1 org.apache.maven.plugins @@ -234,12 +234,12 @@ org.apache.maven.plugins maven-resources-plugin - 3.3.0 + 3.3.1 org.apache.maven.plugins maven-javadoc-plugin - 3.5.0 + 3.6.3 attach-javadocs @@ -257,12 +257,12 @@ org.apache.maven.plugins maven-surefire-plugin - 3.0.0 + 3.2.5 org.apache.maven.plugins maven-deploy-plugin - 3.1.0 + 3.1.1 org.sonatype.plugins @@ -278,24 +278,24 @@ org.codehaus.mojo findbugs-maven-plugin - 2.5.3 + 3.0.5 - org.codehaus.mojo - clirr-maven-plugin - 2.8 + org.apache.maven + maven-plugin-api + 3.9.6 org.codehaus.mojo versions-maven-plugin - 2.1 + 2.16.2 org.jacoco jacoco-maven-plugin - 0.8.6 + 0.8.11 @@ -314,11 +314,10 @@ - org.apache.felix maven-bundle-plugin - 5.1.8 + 5.1.9 bundle-manifest @@ -355,7 +354,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.0.1 + 3.1.0 sign-artifacts @@ -384,7 +383,7 @@ org.eluder.coveralls coveralls-maven-plugin - 2.2.0 + 4.3.0 diff --git a/pom.xml.jdk16 b/pom.xml.jdk16 deleted file mode 100644 index 9b94dead..00000000 --- a/pom.xml.jdk16 +++ /dev/null @@ -1,400 +0,0 @@ - - 4.0.0 - - - org.sonatype.oss - oss-parent - 7 - - - com.cronutils - cron-utils - 9.1.6-SNAPSHOT - - cron-utils - A Java library to parse, migrate and validate crons as well as describe them in human readable - language - - http://cron-parser.com/ - - - - Apache 2.0 - http://www.apache.org/licenses/LICENSE-2.0.html - repo - - - - - - jmrozanec - https://github.com/jmrozanec - - - - - https://github.com/jmrozanec/cron-utils/issues - GitHub Issues - - - - https://github.com/jmrozanec/cron-utils - scm:git:git@github.com:jmrozanec/cron-utils.git - scm:git:git@github.com:jmrozanec/cron-utils.git - HEAD - - - - - ossrh - Release Repository - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - ossrh - Snapshots Repository - https://oss.sonatype.org/content/repositories/snapshots/ - - - - - 1.7.30 - 5.8.1 - 3.9.0 - - github - UTF-8 - https://sonarqube.com - jmrozanec-github - - - - - org.slf4j - slf4j-api - ${slf4j.version} - - - javax.validation - validation-api - 2.0.1.Final - provided - - - - - org.slf4j - slf4j-simple - ${slf4j.version} - test - - - org.junit.jupiter - junit-jupiter - ${junit.version} - test - - - org.mockito - mockito-inline - ${mockito.version} - test - - - org.quartz-scheduler - quartz - 2.3.2 - test - - - org.apache.bval - bval-jsr - 2.0.5 - - - - test - - - org.springframework - spring-context - 5.3.6 - test - - - org.javassist - javassist - 3.27.0-GA - - - - - javax.el - javax.el-api - 3.0.0 - provided - - - org.glassfish - jakarta.el - 3.0.4 - - - org.projectlombok - lombok - 1.18.20 - provided - - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - 3.2.0 - - src/main/resources/checkstyle.xml - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.10.1 - - 16 - 16 - - -J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED - -J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED - -J--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED - -J--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED - -J--add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED - -J--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED - -J--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED - -J--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED - -J--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED - -J--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED - - - - - org.apache.maven.plugins - maven-assembly-plugin - 3.4.2 - - - - - - - - jar-with-dependencies - - - - - org.apache.maven.plugins - maven-source-plugin - 3.2.1 - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-clean-plugin - 3.2.0 - - - org.apache.maven.plugins - maven-install-plugin - 3.0.1 - - - org.apache.maven.plugins - maven-jar-plugin - 3.3.0 - - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - true - - - - com.cronutils - - - - - - org.apache.maven.plugins - maven-resources-plugin - 3.3.0 - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.4.1 - - - attach-javadocs - - jar - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.0.0-M7 - - ${argLine} --add-opens java.xml/jdk.xml.internal=ALL-UNNAMED - - - - org.apache.maven.plugins - maven-deploy-plugin - 3.0.0 - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.8 - true - - ossrh - https://oss.sonatype.org/ - true - - - - org.codehaus.mojo - findbugs-maven-plugin - 2.5.3 - - - org.codehaus.mojo - clirr-maven-plugin - 2.8 - - - org.codehaus.mojo - versions-maven-plugin - 2.1 - - - - - org.jacoco - jacoco-maven-plugin - 0.8.6 - - - - jacoco-initialize - - prepare-agent - - - - jacoco-site - package - - report - - - - - - - - org.apache.felix - maven-bundle-plugin - 5.1.2 - - - bundle-manifest - process-classes - - manifest - - - - - - - - - - org.apache.maven.wagon - wagon-webdav - 1.0-beta-2 - - - - - - - release-sign-artifacts - - - performRelease - true - - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.5 - - - sign-artifacts - verify - - sign - - - - - - - - - - - travis - - - env.TRAVIS - true - - - - - - org.eluder.coveralls - coveralls-maven-plugin - 2.2.0 - - - - - - - diff --git a/src/main/java/com/cronutils/Function.java b/src/main/java/com/cronutils/Function.java deleted file mode 100644 index ffe245f6..00000000 --- a/src/main/java/com/cronutils/Function.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2014 jmrozanec - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.cronutils; - -/** - * Created by kiran on 19/3/17. - */ -public interface Function { - - /** - * - * @param t - some parameter - * @return R - result - */ - R apply(T t); -} diff --git a/src/main/java/com/cronutils/descriptor/DescriptionStrategy.java b/src/main/java/com/cronutils/descriptor/DescriptionStrategy.java index de2d8ddc..24989377 100755 --- a/src/main/java/com/cronutils/descriptor/DescriptionStrategy.java +++ b/src/main/java/com/cronutils/descriptor/DescriptionStrategy.java @@ -13,7 +13,6 @@ package com.cronutils.descriptor; -import com.cronutils.Function; import com.cronutils.model.field.expression.*; import com.cronutils.model.field.value.FieldValue; import com.cronutils.model.field.value.IntegerFieldValue; @@ -24,6 +23,7 @@ import java.util.ArrayList; import java.util.List; import java.util.ResourceBundle; +import java.util.function.Function; /** * Description strategy to handle cases on how to present cron information in a diff --git a/src/main/java/com/cronutils/descriptor/DescriptionStrategyFactory.java b/src/main/java/com/cronutils/descriptor/DescriptionStrategyFactory.java index 61920609..055ef17b 100755 --- a/src/main/java/com/cronutils/descriptor/DescriptionStrategyFactory.java +++ b/src/main/java/com/cronutils/descriptor/DescriptionStrategyFactory.java @@ -13,7 +13,6 @@ package com.cronutils.descriptor; -import com.cronutils.Function; import com.cronutils.model.field.definition.DayOfWeekFieldDefinition; import com.cronutils.model.field.definition.FieldDefinition; import com.cronutils.model.field.expression.Every; @@ -25,6 +24,7 @@ import java.time.Month; import java.time.format.TextStyle; import java.util.ResourceBundle; +import java.util.function.Function; class DescriptionStrategyFactory { diff --git a/src/main/java/com/cronutils/descriptor/NominalDescriptionStrategy.java b/src/main/java/com/cronutils/descriptor/NominalDescriptionStrategy.java index 9739f0e1..206fd911 100644 --- a/src/main/java/com/cronutils/descriptor/NominalDescriptionStrategy.java +++ b/src/main/java/com/cronutils/descriptor/NominalDescriptionStrategy.java @@ -13,12 +13,12 @@ package com.cronutils.descriptor; -import com.cronutils.Function; import com.cronutils.model.field.expression.FieldExpression; import java.util.HashSet; import java.util.ResourceBundle; import java.util.Set; +import java.util.function.Function; import static com.cronutils.model.field.expression.FieldExpression.always; diff --git a/src/main/java/com/cronutils/descriptor/TimeDescriptionStrategy.java b/src/main/java/com/cronutils/descriptor/TimeDescriptionStrategy.java index bd397840..2c4f2fd3 100644 --- a/src/main/java/com/cronutils/descriptor/TimeDescriptionStrategy.java +++ b/src/main/java/com/cronutils/descriptor/TimeDescriptionStrategy.java @@ -13,7 +13,6 @@ package com.cronutils.descriptor; -import com.cronutils.Function; import com.cronutils.model.field.expression.*; import com.cronutils.model.field.value.IntegerFieldValue; import com.cronutils.utils.Preconditions; @@ -22,6 +21,7 @@ import java.util.HashSet; import java.util.ResourceBundle; import java.util.Set; +import java.util.function.Function; import static com.cronutils.model.field.expression.FieldExpression.always; diff --git a/src/main/java/com/cronutils/mapper/CronMapper.java b/src/main/java/com/cronutils/mapper/CronMapper.java index 8446fac4..f226ddb9 100755 --- a/src/main/java/com/cronutils/mapper/CronMapper.java +++ b/src/main/java/com/cronutils/mapper/CronMapper.java @@ -13,7 +13,6 @@ package com.cronutils.mapper; -import com.cronutils.Function; import com.cronutils.model.Cron; import com.cronutils.model.CronType; import com.cronutils.model.RebootCron; @@ -29,7 +28,6 @@ import com.cronutils.model.field.definition.FieldDefinition; import com.cronutils.model.field.expression.*; import com.cronutils.model.field.expression.visitor.FieldExpressionVisitorAdaptor; -import com.cronutils.model.field.expression.visitor.ValueMappingFieldExpressionVisitor; import com.cronutils.model.field.value.FieldValue; import com.cronutils.model.field.value.IntegerFieldValue; import com.cronutils.model.field.value.SpecialChar; @@ -40,6 +38,7 @@ import java.util.EnumMap; import java.util.List; import java.util.Map; +import java.util.function.Function; import static com.cronutils.model.field.expression.FieldExpression.always; import static com.cronutils.model.field.expression.FieldExpression.questionMark; @@ -284,7 +283,7 @@ private static FieldValue mapDayOfWeek(DayOfWeekFieldDefinition sourceDef, Da static Function dayOfWeekMapping(final DayOfWeekFieldDefinition sourceDef, final DayOfWeekFieldDefinition targetDef) { return field -> { final FieldExpression expression = field.getExpression(); - FieldExpression dest = null; + FieldExpression dest; dest = expression.accept(new FieldExpressionVisitorAdaptor() { public FieldExpression visit(Every every) { return new Every(every.getExpression().accept(this), every.getPeriod()); diff --git a/src/main/java/com/cronutils/mapper/WeekDay.java b/src/main/java/com/cronutils/mapper/WeekDay.java index ea10c44c..c7394e33 100644 --- a/src/main/java/com/cronutils/mapper/WeekDay.java +++ b/src/main/java/com/cronutils/mapper/WeekDay.java @@ -13,11 +13,11 @@ package com.cronutils.mapper; -import com.cronutils.Function; import com.cronutils.utils.Preconditions; import com.cronutils.utils.VisibleForTesting; import java.io.Serializable; +import java.util.function.Function; @VisibleForTesting public class WeekDay implements Serializable { diff --git a/src/main/java/com/cronutils/model/field/expression/visitor/ValueMappingFieldExpressionVisitor.java b/src/main/java/com/cronutils/model/field/expression/visitor/ValueMappingFieldExpressionVisitor.java index bee8ae04..16102799 100644 --- a/src/main/java/com/cronutils/model/field/expression/visitor/ValueMappingFieldExpressionVisitor.java +++ b/src/main/java/com/cronutils/model/field/expression/visitor/ValueMappingFieldExpressionVisitor.java @@ -13,11 +13,12 @@ package com.cronutils.model.field.expression.visitor; -import com.cronutils.Function; import com.cronutils.model.field.expression.*; import com.cronutils.model.field.value.FieldValue; import com.cronutils.model.field.value.IntegerFieldValue; +import java.util.function.Function; + import static com.cronutils.model.field.expression.FieldExpression.questionMark; /** diff --git a/src/main/java/com/cronutils/model/time/generator/AndFieldValueGenerator.java b/src/main/java/com/cronutils/model/time/generator/AndFieldValueGenerator.java index 91a2e48b..6d47817d 100755 --- a/src/main/java/com/cronutils/model/time/generator/AndFieldValueGenerator.java +++ b/src/main/java/com/cronutils/model/time/generator/AndFieldValueGenerator.java @@ -13,7 +13,6 @@ package com.cronutils.model.time.generator; -import com.cronutils.Function; import com.cronutils.model.field.CronField; import com.cronutils.model.field.expression.*; import org.slf4j.Logger; @@ -22,6 +21,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.function.Function; class AndFieldValueGenerator extends FieldValueGenerator { private static final Logger log = LoggerFactory.getLogger(AndFieldValueGenerator.class); diff --git a/src/test/java/com/cronutils/Issue430Test.java b/src/test/java/com/cronutils/Issue430Test.java index fc36ff0b..4cabe75f 100644 --- a/src/test/java/com/cronutils/Issue430Test.java +++ b/src/test/java/com/cronutils/Issue430Test.java @@ -11,7 +11,8 @@ import java.time.ZoneOffset; import java.time.ZonedDateTime; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class Issue430Test { @Test diff --git a/src/test/java/com/cronutils/Issue446Test.java b/src/test/java/com/cronutils/Issue446Test.java index 50f60b21..6eadb671 100644 --- a/src/test/java/com/cronutils/Issue446Test.java +++ b/src/test/java/com/cronutils/Issue446Test.java @@ -17,7 +17,8 @@ import static com.cronutils.model.field.expression.FieldExpression.questionMark; import static com.cronutils.model.field.expression.FieldExpressionFactory.every; import static com.cronutils.model.field.expression.FieldExpressionFactory.on; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class Issue446Test { diff --git a/src/test/java/com/cronutils/Issue462Test.java b/src/test/java/com/cronutils/Issue462Test.java index 74234f7e..b66d94b0 100644 --- a/src/test/java/com/cronutils/Issue462Test.java +++ b/src/test/java/com/cronutils/Issue462Test.java @@ -13,16 +13,18 @@ package com.cronutils; -import static org.junit.jupiter.api.Assertions.assertEquals; import com.cronutils.descriptor.CronDescriptor; import com.cronutils.model.Cron; import com.cronutils.model.CronType; import com.cronutils.model.definition.CronDefinitionBuilder; import com.cronutils.parser.CronParser; -import java.util.Locale; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.Locale; + +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * Provide an example on how convert a cron expression to ISO8601 */ diff --git a/src/test/java/com/cronutils/Issue470Test.java b/src/test/java/com/cronutils/Issue470Test.java index 1eae0f8c..5586cddc 100644 --- a/src/test/java/com/cronutils/Issue470Test.java +++ b/src/test/java/com/cronutils/Issue470Test.java @@ -1,17 +1,16 @@ package com.cronutils; -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.util.Optional; - -import org.junit.jupiter.api.Test; - import com.cronutils.model.Cron; import com.cronutils.model.CronType; import com.cronutils.model.definition.CronDefinition; import com.cronutils.model.definition.CronDefinitionBuilder; import com.cronutils.model.time.ExecutionTime; import com.cronutils.parser.CronParser; +import org.junit.jupiter.api.Test; + +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.Optional; public class Issue470Test { diff --git a/src/test/java/com/cronutils/Issue477Test.java b/src/test/java/com/cronutils/Issue477Test.java index e9eea931..3a6c304c 100644 --- a/src/test/java/com/cronutils/Issue477Test.java +++ b/src/test/java/com/cronutils/Issue477Test.java @@ -1,16 +1,15 @@ package com.cronutils; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.Locale; - -import org.junit.jupiter.api.Test; - import com.cronutils.descriptor.CronDescriptor; import com.cronutils.model.CronType; import com.cronutils.model.definition.CronDefinition; import com.cronutils.model.definition.CronDefinitionBuilder; import com.cronutils.parser.CronParser; +import org.junit.jupiter.api.Test; + +import java.util.Locale; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class Issue477Test { diff --git a/src/test/java/com/cronutils/Issue499Test.java b/src/test/java/com/cronutils/Issue499Test.java index feea642e..b2b80e28 100644 --- a/src/test/java/com/cronutils/Issue499Test.java +++ b/src/test/java/com/cronutils/Issue499Test.java @@ -1,13 +1,12 @@ package com.cronutils; -import static org.junit.jupiter.api.Assertions.assertThrows; - import com.cronutils.model.CronType; import com.cronutils.model.definition.CronDefinitionBuilder; import com.cronutils.parser.CronParser; - import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertThrows; + class Issue499Test { /** * We want to convert Unix cron expressions to Quartz cron expressions. We diff --git a/src/test/java/com/cronutils/Issue503Test.java b/src/test/java/com/cronutils/Issue503Test.java index 5a115c7a..d7c29f1b 100644 --- a/src/test/java/com/cronutils/Issue503Test.java +++ b/src/test/java/com/cronutils/Issue503Test.java @@ -11,15 +11,12 @@ package com.cronutils; -import static org.junit.jupiter.api.Assertions.assertArrayEquals; - import com.cronutils.model.Cron; import com.cronutils.model.definition.CronConstraintsFactory; import com.cronutils.model.definition.CronDefinition; import com.cronutils.model.definition.CronDefinitionBuilder; import com.cronutils.model.time.ExecutionTime; import com.cronutils.parser.CronParser; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -31,6 +28,8 @@ import java.util.List; import java.util.stream.IntStream; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; + class Issue503Test { diff --git a/src/test/java/com/cronutils/Issue512Test.java b/src/test/java/com/cronutils/Issue512Test.java index a7fab981..56bf3868 100644 --- a/src/test/java/com/cronutils/Issue512Test.java +++ b/src/test/java/com/cronutils/Issue512Test.java @@ -1,19 +1,18 @@ package com.cronutils; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import com.cronutils.builder.CronBuilder; +import com.cronutils.model.definition.CronDefinitionBuilder; +import com.cronutils.model.field.expression.FieldExpressionFactory; +import com.cronutils.model.time.ExecutionTime; +import org.junit.jupiter.api.Test; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.Optional; -import org.junit.jupiter.api.Test; - -import com.cronutils.builder.CronBuilder; -import com.cronutils.model.definition.CronDefinitionBuilder; -import com.cronutils.model.field.expression.FieldExpressionFactory; -import com.cronutils.model.time.ExecutionTime; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class Issue512Test { diff --git a/src/test/java/com/cronutils/Issue528Test.java b/src/test/java/com/cronutils/Issue528Test.java index 7536b9c2..6716c23b 100644 --- a/src/test/java/com/cronutils/Issue528Test.java +++ b/src/test/java/com/cronutils/Issue528Test.java @@ -7,8 +7,8 @@ import com.cronutils.model.definition.CronDefinitionBuilder; import com.cronutils.model.time.ExecutionTime; import com.cronutils.parser.CronParser; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.time.ZonedDateTime; import java.util.Locale; diff --git a/src/test/java/com/cronutils/Issue539Test.java b/src/test/java/com/cronutils/Issue539Test.java index 46c8cde7..720af24c 100644 --- a/src/test/java/com/cronutils/Issue539Test.java +++ b/src/test/java/com/cronutils/Issue539Test.java @@ -4,11 +4,11 @@ import com.cronutils.model.definition.CronDefinitionBuilder; import com.cronutils.model.time.ExecutionTime; import com.cronutils.parser.CronParser; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import java.time.ZonedDateTime; -import org.junit.jupiter.api.Disabled; import static org.junit.jupiter.api.Assertions.assertEquals; @Disabled diff --git a/src/test/java/com/cronutils/mapper/CronMapperTest.java b/src/test/java/com/cronutils/mapper/CronMapperTest.java index 6fc24508..0cce7ca9 100755 --- a/src/test/java/com/cronutils/mapper/CronMapperTest.java +++ b/src/test/java/com/cronutils/mapper/CronMapperTest.java @@ -13,7 +13,6 @@ package com.cronutils.mapper; -import com.cronutils.Function; import com.cronutils.model.definition.CronDefinition; import com.cronutils.model.field.CronField; import com.cronutils.model.field.CronFieldName; @@ -21,13 +20,17 @@ import com.cronutils.model.field.expression.On; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.function.Function; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; +@ExtendWith(MockitoExtension.class) public class CronMapperTest { private CronFieldName testCronFieldName; @Mock @@ -35,7 +38,6 @@ public class CronMapperTest { @BeforeEach public void setUp() { - MockitoAnnotations.initMocks(this); testCronFieldName = CronFieldName.SECOND; } diff --git a/src/test/java/com/cronutils/model/CronTest.java b/src/test/java/com/cronutils/model/CronTest.java index 936d16b5..e1ee9d53 100755 --- a/src/test/java/com/cronutils/model/CronTest.java +++ b/src/test/java/com/cronutils/model/CronTest.java @@ -22,8 +22,9 @@ import com.cronutils.parser.CronParser; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; import java.io.*; import java.util.Collections; @@ -33,6 +34,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +@ExtendWith(MockitoExtension.class) public class CronTest { private Cron cron; private CronFieldName testName; @@ -42,7 +44,6 @@ public class CronTest { @BeforeEach public void setUp() { - MockitoAnnotations.initMocks(this); testName = CronFieldName.SECOND; when(mockField.getField()).thenReturn(testName); fields = Collections.singletonList(mockField); diff --git a/src/test/java/com/cronutils/model/definition/CronDefinitionBuilderTest.java b/src/test/java/com/cronutils/model/definition/CronDefinitionBuilderTest.java index 10cc67ad..1ba07d4a 100755 --- a/src/test/java/com/cronutils/model/definition/CronDefinitionBuilderTest.java +++ b/src/test/java/com/cronutils/model/definition/CronDefinitionBuilderTest.java @@ -29,9 +29,7 @@ import java.util.Set; import static com.cronutils.model.field.expression.FieldExpressionFactory.*; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.*; public class CronDefinitionBuilderTest { diff --git a/src/test/java/com/cronutils/model/definition/CronDefinitionTest.java b/src/test/java/com/cronutils/model/definition/CronDefinitionTest.java index 37c796aa..09f03b72 100755 --- a/src/test/java/com/cronutils/model/definition/CronDefinitionTest.java +++ b/src/test/java/com/cronutils/model/definition/CronDefinitionTest.java @@ -19,11 +19,12 @@ import com.cronutils.model.field.definition.FieldDefinition; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; import java.util.ArrayList; import java.util.HashSet; @@ -33,8 +34,9 @@ import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.lenient; +@ExtendWith(MockitoExtension.class) public class CronDefinitionTest { private boolean matchDayOfWeekAndDayOfMonth; @@ -50,11 +52,10 @@ public void setUp() { final CronFieldName testFieldName1 = CronFieldName.SECOND; final CronFieldName testFieldName2 = CronFieldName.MINUTE; final CronFieldName testFieldName3 = CronFieldName.HOUR; - MockitoAnnotations.initMocks(this); - when(mockFieldDefinition1.getFieldName()).thenReturn(testFieldName1); - when(mockFieldDefinition2.getFieldName()).thenReturn(testFieldName2); - when(mockFieldDefinition3optional.getFieldName()).thenReturn(testFieldName3); - when(mockFieldDefinition3optional.isOptional()).thenReturn(Boolean.TRUE); + lenient().when(mockFieldDefinition1.getFieldName()).thenReturn(testFieldName1); + lenient().when(mockFieldDefinition2.getFieldName()).thenReturn(testFieldName2); + lenient().when(mockFieldDefinition3optional.getFieldName()).thenReturn(testFieldName3); + lenient().when(mockFieldDefinition3optional.isOptional()).thenReturn(Boolean.TRUE); matchDayOfWeekAndDayOfMonth = false; } diff --git a/src/test/java/com/cronutils/model/definition/FieldDefinitionTest.java b/src/test/java/com/cronutils/model/definition/FieldDefinitionTest.java index cff80515..a8831fe0 100755 --- a/src/test/java/com/cronutils/model/definition/FieldDefinitionTest.java +++ b/src/test/java/com/cronutils/model/definition/FieldDefinitionTest.java @@ -18,12 +18,14 @@ import com.cronutils.model.field.definition.FieldDefinition; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.mock; +@ExtendWith(MockitoExtension.class) public class FieldDefinitionTest { private CronFieldName testFieldName; @@ -34,7 +36,6 @@ public class FieldDefinitionTest { @BeforeEach public void setUp() { - MockitoAnnotations.initMocks(this); testFieldName = CronFieldName.SECOND; fieldDefinition = new FieldDefinition(testFieldName, mockConstraints); } diff --git a/src/test/java/com/cronutils/model/definition/Issue343Test.java b/src/test/java/com/cronutils/model/definition/Issue343Test.java index cafe6cba..ab20a9a6 100644 --- a/src/test/java/com/cronutils/model/definition/Issue343Test.java +++ b/src/test/java/com/cronutils/model/definition/Issue343Test.java @@ -6,7 +6,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; public class Issue343Test { @ParameterizedTest diff --git a/src/test/java/com/cronutils/model/field/CronFieldTest.java b/src/test/java/com/cronutils/model/field/CronFieldTest.java index e09c0ae5..722fdeef 100755 --- a/src/test/java/com/cronutils/model/field/CronFieldTest.java +++ b/src/test/java/com/cronutils/model/field/CronFieldTest.java @@ -17,8 +17,9 @@ import com.cronutils.model.field.expression.FieldExpression; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; import java.util.Comparator; @@ -26,6 +27,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +@ExtendWith(MockitoExtension.class) public class CronFieldTest { private CronField result; @@ -35,7 +37,6 @@ public class CronFieldTest { @BeforeEach public void setUp() { - MockitoAnnotations.initMocks(this); cronFieldName = CronFieldName.SECOND; result = new CronField(cronFieldName, mockFieldExpression, FieldConstraintsBuilder.instance().createConstraintsInstance()); } diff --git a/src/test/java/com/cronutils/model/field/FieldDefinitionBuilderTest.java b/src/test/java/com/cronutils/model/field/FieldDefinitionBuilderTest.java index a71d55f8..d53ea906 100755 --- a/src/test/java/com/cronutils/model/field/FieldDefinitionBuilderTest.java +++ b/src/test/java/com/cronutils/model/field/FieldDefinitionBuilderTest.java @@ -22,11 +22,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.MockedStatic; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.*; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; diff --git a/src/test/java/com/cronutils/model/field/FieldParserTest.java b/src/test/java/com/cronutils/model/field/FieldParserTest.java index c7b22b6b..754e9c0f 100755 --- a/src/test/java/com/cronutils/model/field/FieldParserTest.java +++ b/src/test/java/com/cronutils/model/field/FieldParserTest.java @@ -19,9 +19,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; public class FieldParserTest { private FieldParser parser; diff --git a/src/test/java/com/cronutils/model/field/expression/FieldExpressionTest.java b/src/test/java/com/cronutils/model/field/expression/FieldExpressionTest.java index 340c7d1c..59221175 100755 --- a/src/test/java/com/cronutils/model/field/expression/FieldExpressionTest.java +++ b/src/test/java/com/cronutils/model/field/expression/FieldExpressionTest.java @@ -13,8 +13,7 @@ package com.cronutils.model.field.expression; -import com.cronutils.model.field.expression.visitor.*; - +import com.cronutils.model.field.expression.visitor.FieldExpressionVisitor; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/cronutils/model/field/expression/visitor/ValidationFieldExpressionVisitorTest.java b/src/test/java/com/cronutils/model/field/expression/visitor/ValidationFieldExpressionVisitorTest.java index b6eb80e3..76b7848c 100755 --- a/src/test/java/com/cronutils/model/field/expression/visitor/ValidationFieldExpressionVisitorTest.java +++ b/src/test/java/com/cronutils/model/field/expression/visitor/ValidationFieldExpressionVisitorTest.java @@ -9,15 +9,17 @@ import com.cronutils.utils.StringUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; import java.util.Collections; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; +@ExtendWith(MockitoExtension.class) public class ValidationFieldExpressionVisitorTest { private static final int DEFAULT_INT = -1; @@ -42,13 +44,12 @@ public class ValidationFieldExpressionVisitorTest { @BeforeEach public void setUp() { - MockitoAnnotations.initMocks(this); final int startRange = 0; final int endRange = 59; fieldConstraints = new FieldConstraints(Collections.emptyMap(), Collections.emptyMap(), Collections.emptySet(), startRange, endRange, true); - when(stringValidations.removeValidChars(any(String.class))).thenReturn(StringUtils.EMPTY); - when(invalidStringValidations.removeValidChars(any(String.class))).thenReturn("$$$"); + lenient().when(stringValidations.removeValidChars(any(String.class))).thenReturn(StringUtils.EMPTY); + lenient().when(invalidStringValidations.removeValidChars(any(String.class))).thenReturn("$$$"); strictVisitor = new ValidationFieldExpressionVisitor(fieldConstraints, stringValidations); visitor = new ValidationFieldExpressionVisitor(fieldConstraints, stringValidations); diff --git a/src/test/java/com/cronutils/model/field/expression/visitor/ValueMappingFieldExpressionVisitorTest.java b/src/test/java/com/cronutils/model/field/expression/visitor/ValueMappingFieldExpressionVisitorTest.java index 73d05f34..f139cab3 100755 --- a/src/test/java/com/cronutils/model/field/expression/visitor/ValueMappingFieldExpressionVisitorTest.java +++ b/src/test/java/com/cronutils/model/field/expression/visitor/ValueMappingFieldExpressionVisitorTest.java @@ -13,13 +13,14 @@ package com.cronutils.model.field.expression.visitor; -import com.cronutils.Function; import com.cronutils.model.field.expression.FieldExpression; import com.cronutils.model.field.expression.QuestionMark; import com.cronutils.model.field.value.FieldValue; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.function.Function; + import static org.junit.jupiter.api.Assertions.assertTrue; public class ValueMappingFieldExpressionVisitorTest { diff --git a/src/test/java/com/cronutils/model/time/generator/FieldValueGeneratorFactoryTest.java b/src/test/java/com/cronutils/model/time/generator/FieldValueGeneratorFactoryTest.java index acaee54a..cac0f985 100755 --- a/src/test/java/com/cronutils/model/time/generator/FieldValueGeneratorFactoryTest.java +++ b/src/test/java/com/cronutils/model/time/generator/FieldValueGeneratorFactoryTest.java @@ -23,9 +23,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/src/test/java/com/cronutils/model/time/generator/OnDayOfMonthValueGeneratorTest.java b/src/test/java/com/cronutils/model/time/generator/OnDayOfMonthValueGeneratorTest.java index dd20a4f1..9044a371 100755 --- a/src/test/java/com/cronutils/model/time/generator/OnDayOfMonthValueGeneratorTest.java +++ b/src/test/java/com/cronutils/model/time/generator/OnDayOfMonthValueGeneratorTest.java @@ -25,9 +25,7 @@ import java.util.Random; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.mock; public class OnDayOfMonthValueGeneratorTest { diff --git a/src/test/java/com/cronutils/model/time/generator/OnDayOfWeekValueGeneratorTest.java b/src/test/java/com/cronutils/model/time/generator/OnDayOfWeekValueGeneratorTest.java index 2b74f646..dd178c16 100755 --- a/src/test/java/com/cronutils/model/time/generator/OnDayOfWeekValueGeneratorTest.java +++ b/src/test/java/com/cronutils/model/time/generator/OnDayOfWeekValueGeneratorTest.java @@ -24,9 +24,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.mock; public class OnDayOfWeekValueGeneratorTest { diff --git a/src/test/java/com/cronutils/parser/CronParserFieldTest.java b/src/test/java/com/cronutils/parser/CronParserFieldTest.java index 06096748..67063351 100755 --- a/src/test/java/com/cronutils/parser/CronParserFieldTest.java +++ b/src/test/java/com/cronutils/parser/CronParserFieldTest.java @@ -21,11 +21,12 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.MockedConstruction; import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; import java.util.UUID; @@ -33,6 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; @Disabled +@ExtendWith(MockitoExtension.class) public class CronParserFieldTest { private CronFieldName testFieldName; @@ -47,7 +49,6 @@ public class CronParserFieldTest { @BeforeEach public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); testFieldName = CronFieldName.SECOND; mockedConstruction = Mockito.mockConstruction(FieldParser.class, (mock, context) -> { diff --git a/src/test/java/com/cronutils/parser/CronParserTest.java b/src/test/java/com/cronutils/parser/CronParserTest.java index 08aa4e96..3be2edc6 100755 --- a/src/test/java/com/cronutils/parser/CronParserTest.java +++ b/src/test/java/com/cronutils/parser/CronParserTest.java @@ -23,18 +23,18 @@ import com.cronutils.model.field.definition.FieldDefinition; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; import java.util.Collections; import java.util.HashSet; import java.util.Set; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.when; +@ExtendWith(MockitoExtension.class) public class CronParserTest { @Mock private CronDefinition definition; @@ -43,7 +43,6 @@ public class CronParserTest { @BeforeEach public void setUp() { - MockitoAnnotations.initMocks(this); } @Test diff --git a/src/test/java/com/cronutils/utils/CronFrequencyComparatorTest.java b/src/test/java/com/cronutils/utils/CronFrequencyComparatorTest.java index 38a10aa3..d5756934 100644 --- a/src/test/java/com/cronutils/utils/CronFrequencyComparatorTest.java +++ b/src/test/java/com/cronutils/utils/CronFrequencyComparatorTest.java @@ -12,7 +12,8 @@ import java.time.ZoneId; import java.time.ZonedDateTime; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class CronFrequencyComparatorTest { private CronFrequencyComparator comparator; diff --git a/src/test/java/com/cronutils/utils/StringUtilsTest.java b/src/test/java/com/cronutils/utils/StringUtilsTest.java index 192a5088..5465b576 100644 --- a/src/test/java/com/cronutils/utils/StringUtilsTest.java +++ b/src/test/java/com/cronutils/utils/StringUtilsTest.java @@ -1,10 +1,10 @@ package com.cronutils.utils; +import org.junit.jupiter.api.Test; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; -import org.junit.jupiter.api.Test; - public class StringUtilsTest { @Test diff --git a/src/test/java/com/cronutils/utils/descriptor/CronDescriptorTest.java b/src/test/java/com/cronutils/utils/descriptor/CronDescriptorTest.java index b7c08dac..b64adb7f 100755 --- a/src/test/java/com/cronutils/utils/descriptor/CronDescriptorTest.java +++ b/src/test/java/com/cronutils/utils/descriptor/CronDescriptorTest.java @@ -29,8 +29,9 @@ import com.cronutils.model.field.value.SpecialCharFieldValue; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; import java.util.ArrayList; import java.util.Collections; @@ -40,6 +41,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +@ExtendWith(MockitoExtension.class) public class CronDescriptorTest { private CronDescriptor descriptor; private FieldConstraints nullFieldConstraints; @@ -48,7 +50,6 @@ public class CronDescriptorTest { @BeforeEach public void setUp() { - MockitoAnnotations.initMocks(this); descriptor = CronDescriptor.instance(Locale.UK); nullFieldConstraints = FieldConstraintsBuilder.instance() diff --git a/src/test/java/com/cronutils/utils/descriptor/TestDescriptor.java b/src/test/java/com/cronutils/utils/descriptor/TestDescriptor.java index 7e5e0909..b8d16578 100644 --- a/src/test/java/com/cronutils/utils/descriptor/TestDescriptor.java +++ b/src/test/java/com/cronutils/utils/descriptor/TestDescriptor.java @@ -1,13 +1,5 @@ package com.cronutils.utils.descriptor; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.Locale; -import java.util.ResourceBundle; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - import com.cronutils.descriptor.CronDescriptor; import com.cronutils.descriptor.refactor.TimeDescriptor; import com.cronutils.model.Cron; @@ -15,6 +7,13 @@ import com.cronutils.model.definition.CronDefinition; import com.cronutils.model.definition.CronDefinitionBuilder; import com.cronutils.parser.CronParser; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import java.util.Locale; +import java.util.ResourceBundle; + +import static org.junit.jupiter.api.Assertions.assertEquals; //FIXME https://github.com/jmrozanec/cron-utils/issues/3 diff --git a/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker new file mode 100644 index 00000000..ca6ee9ce --- /dev/null +++ b/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker @@ -0,0 +1 @@ +mock-maker-inline \ No newline at end of file From 0849dd7fc05b51f58202bf1e700e765a4f62ad80 Mon Sep 17 00:00:00 2001 From: Yves Galante Date: Fri, 16 Feb 2024 10:18:21 +0100 Subject: [PATCH 4/4] fix(code): Small code clean up --- src/main/java/com/cronutils/descriptor/CronDescriptor.java | 2 +- .../java/com/cronutils/descriptor/TimeDescriptionStrategy.java | 2 +- .../com/cronutils/model/definition/CronDefinitionBuilder.java | 3 +-- .../java/com/cronutils/model/definition/CronNicknames.java | 2 +- src/main/java/com/cronutils/model/field/CronFieldName.java | 2 +- src/main/java/com/cronutils/model/field/expression/And.java | 2 +- .../java/com/cronutils/model/field/expression/Weekdays.java | 2 +- .../com/cronutils/model/field/value/SpecialCharFieldValue.java | 2 +- .../java/com/cronutils/model/time/CompositeExecutionTime.java | 2 +- src/main/java/com/cronutils/model/time/ExecutionTime.java | 2 +- src/test/java/com/cronutils/Issue305Test.java | 2 +- src/test/java/com/cronutils/Issue423Test.java | 2 +- src/test/java/com/cronutils/converter/CronConverterTest.java | 2 +- .../cronutils/model/field/expression/FieldExpressionTest.java | 2 +- src/test/java/com/cronutils/parser/CronParserTest.java | 2 +- 15 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/cronutils/descriptor/CronDescriptor.java b/src/main/java/com/cronutils/descriptor/CronDescriptor.java index fe5e2468..71cf6445 100755 --- a/src/main/java/com/cronutils/descriptor/CronDescriptor.java +++ b/src/main/java/com/cronutils/descriptor/CronDescriptor.java @@ -143,7 +143,7 @@ public String describeDayOfWeek(final Map fields, fina final String description = DescriptionStrategyFactory.daysOfWeekInstance( resourceBundle, fields.containsKey(CronFieldName.DAY_OF_WEEK) ? fields.get(CronFieldName.DAY_OF_WEEK).getExpression() : null, - definitions.containsKey(CronFieldName.DAY_OF_WEEK) ? definitions.get(CronFieldName.DAY_OF_WEEK) : null + definitions.getOrDefault(CronFieldName.DAY_OF_WEEK, null) ).describe(); return addExpressions(description, resourceBundle.getString("day"), resourceBundle.getString("days")); } diff --git a/src/main/java/com/cronutils/descriptor/TimeDescriptionStrategy.java b/src/main/java/com/cronutils/descriptor/TimeDescriptionStrategy.java index 2c4f2fd3..863f3e35 100644 --- a/src/main/java/com/cronutils/descriptor/TimeDescriptionStrategy.java +++ b/src/main/java/com/cronutils/descriptor/TimeDescriptionStrategy.java @@ -303,7 +303,7 @@ private void registerFunctions() { /** * Contains CronFieldExpression instances for hours, minutes and seconds. */ - class TimeFields { + static class TimeFields { private final FieldExpression seconds; private final FieldExpression minutes; private final FieldExpression hours; diff --git a/src/main/java/com/cronutils/model/definition/CronDefinitionBuilder.java b/src/main/java/com/cronutils/model/definition/CronDefinitionBuilder.java index e51b37d4..a7784139 100755 --- a/src/main/java/com/cronutils/model/definition/CronDefinitionBuilder.java +++ b/src/main/java/com/cronutils/model/definition/CronDefinitionBuilder.java @@ -240,8 +240,7 @@ public void register(final FieldDefinition definition) { * @return returns CronDefinition instance, never null */ public CronDefinition instance() { - final Set validations = new HashSet<>(); - validations.addAll(cronConstraints); + final Set validations = new HashSet<>(cronConstraints); final List values = new ArrayList<>(fields.values()); values.sort(FieldDefinition.createFieldDefinitionComparator()); return new CronDefinition(values, validations, cronNicknames, matchDayOfWeekAndDayOfMonth); diff --git a/src/main/java/com/cronutils/model/definition/CronNicknames.java b/src/main/java/com/cronutils/model/definition/CronNicknames.java index cbc1a94a..8041292a 100644 --- a/src/main/java/com/cronutils/model/definition/CronNicknames.java +++ b/src/main/java/com/cronutils/model/definition/CronNicknames.java @@ -1,5 +1,5 @@ package com.cronutils.model.definition; public enum CronNicknames { - YEARLY, ANNUALLY, MONTHLY, WEEKLY, DAILY, MIDNIGHT, HOURLY, REBOOT; + YEARLY, ANNUALLY, MONTHLY, WEEKLY, DAILY, MIDNIGHT, HOURLY, REBOOT } diff --git a/src/main/java/com/cronutils/model/field/CronFieldName.java b/src/main/java/com/cronutils/model/field/CronFieldName.java index 75d21c91..42a2b0b3 100644 --- a/src/main/java/com/cronutils/model/field/CronFieldName.java +++ b/src/main/java/com/cronutils/model/field/CronFieldName.java @@ -23,7 +23,7 @@ public enum CronFieldName { * effective bi-, tri- or quad-weekly schedules via proprietary cron expressions. */ - private int order; + private final int order; /** * Constructor. diff --git a/src/main/java/com/cronutils/model/field/expression/And.java b/src/main/java/com/cronutils/model/field/expression/And.java index 909f663c..3dcf06a7 100644 --- a/src/main/java/com/cronutils/model/field/expression/And.java +++ b/src/main/java/com/cronutils/model/field/expression/And.java @@ -50,7 +50,7 @@ public String asString() { builder.append(expressions.get(j).asString()); builder.append(","); } - if(expressions.size()>0){ + if(!expressions.isEmpty()){ builder.append(expressions.get(expressions.size() - 1).asString()); } return builder.toString(); diff --git a/src/main/java/com/cronutils/model/field/expression/Weekdays.java b/src/main/java/com/cronutils/model/field/expression/Weekdays.java index ad27ab88..e73dbe03 100644 --- a/src/main/java/com/cronutils/model/field/expression/Weekdays.java +++ b/src/main/java/com/cronutils/model/field/expression/Weekdays.java @@ -22,7 +22,7 @@ public enum Weekdays { MONDAY(1), TUESDAY(2), WEDNESDAY(3), THURSDAY(4), FRIDAY(5), SATURDAY(6), SUNDAY(7); - private int weekday; + private final int weekday; Weekdays(int weekday) { this.weekday = weekday; diff --git a/src/main/java/com/cronutils/model/field/value/SpecialCharFieldValue.java b/src/main/java/com/cronutils/model/field/value/SpecialCharFieldValue.java index aca07ff0..64e979a4 100644 --- a/src/main/java/com/cronutils/model/field/value/SpecialCharFieldValue.java +++ b/src/main/java/com/cronutils/model/field/value/SpecialCharFieldValue.java @@ -18,7 +18,7 @@ public class SpecialCharFieldValue extends FieldValue { private static final long serialVersionUID = -2177180413324528746L; - private SpecialChar specialChar = SpecialChar.NONE; + private SpecialChar specialChar; public SpecialCharFieldValue(final SpecialChar specialChar) { Preconditions.checkNotNull(specialChar, "special char must not be null"); diff --git a/src/main/java/com/cronutils/model/time/CompositeExecutionTime.java b/src/main/java/com/cronutils/model/time/CompositeExecutionTime.java index 79d69968..86375922 100644 --- a/src/main/java/com/cronutils/model/time/CompositeExecutionTime.java +++ b/src/main/java/com/cronutils/model/time/CompositeExecutionTime.java @@ -58,6 +58,6 @@ public Optional timeFromLastExecution(ZonedDateTime date) { @Override public boolean isMatch(ZonedDateTime date) { - return executionTimes.parallelStream().map(e->e.isMatch(date)).filter(v-> v).count()>0; + return executionTimes.parallelStream().map(e -> e.isMatch(date)).anyMatch(v -> v); } } diff --git a/src/main/java/com/cronutils/model/time/ExecutionTime.java b/src/main/java/com/cronutils/model/time/ExecutionTime.java index b56a10d3..705d0e82 100644 --- a/src/main/java/com/cronutils/model/time/ExecutionTime.java +++ b/src/main/java/com/cronutils/model/time/ExecutionTime.java @@ -35,7 +35,7 @@ public interface ExecutionTime { * @param cron - Cron instance * @return ExecutionTime instance */ - public static ExecutionTime forCron(final Cron cron) { + static ExecutionTime forCron(final Cron cron) { if (cron instanceof SingleCron) { final Map fields = cron.retrieveFieldsAsMap(); final ExecutionTimeBuilder executionTimeBuilder = new ExecutionTimeBuilder(cron); diff --git a/src/test/java/com/cronutils/Issue305Test.java b/src/test/java/com/cronutils/Issue305Test.java index 74fe55df..721412b8 100644 --- a/src/test/java/com/cronutils/Issue305Test.java +++ b/src/test/java/com/cronutils/Issue305Test.java @@ -33,7 +33,7 @@ public void testIssue305(){ dates.add(nextExecution.get()); nextExecution = executionTime.nextExecution(nextExecution.get()); } - Set years = dates.stream().map(d->d.getYear()).collect(Collectors.toSet()); + Set years = dates.stream().map(ZonedDateTime::getYear).collect(Collectors.toSet()); Set expectedYears = new HashSet<>(); expectedYears.add(2015); expectedYears.add(2017); diff --git a/src/test/java/com/cronutils/Issue423Test.java b/src/test/java/com/cronutils/Issue423Test.java index ac5b2b35..3e3151f7 100644 --- a/src/test/java/com/cronutils/Issue423Test.java +++ b/src/test/java/com/cronutils/Issue423Test.java @@ -43,7 +43,7 @@ public void issue423() { final CronParser parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ)); final Cron cron = parser.parse("0 0 0-07,17-0 ? * SAT"); final CronDescriptor cd = CronDescriptor.instance(Locale.UK); - assertTrue(cd.describe(cron).length() > 0); + assertTrue(!cd.describe(cron).isEmpty()); // at time of test creation, the descriptor is // "every hour between 0 and 7 and every hour between 17 and 0 at Saturday day" diff --git a/src/test/java/com/cronutils/converter/CronConverterTest.java b/src/test/java/com/cronutils/converter/CronConverterTest.java index 0344c9b2..4fb7e93b 100644 --- a/src/test/java/com/cronutils/converter/CronConverterTest.java +++ b/src/test/java/com/cronutils/converter/CronConverterTest.java @@ -31,7 +31,7 @@ public class CronConverterTest { // Fix the date to prevent test failure during the transition between Standard Time and Daylight Time. Function calendarFactory = (zoneId) -> { - Calendar fixedDay = new GregorianCalendar(2020, 06, 01); + Calendar fixedDay = new GregorianCalendar(2020, Calendar.JULY, 01); fixedDay.setTimeZone(TimeZone.getTimeZone(zoneId)); return fixedDay; }; diff --git a/src/test/java/com/cronutils/model/field/expression/FieldExpressionTest.java b/src/test/java/com/cronutils/model/field/expression/FieldExpressionTest.java index 59221175..5439d6f6 100755 --- a/src/test/java/com/cronutils/model/field/expression/FieldExpressionTest.java +++ b/src/test/java/com/cronutils/model/field/expression/FieldExpressionTest.java @@ -36,7 +36,7 @@ public void testAnd() { assertTrue(and.getExpressions().contains(testCronFieldExpression)); } - class TestFieldExpression extends FieldExpression { + static class TestFieldExpression extends FieldExpression { private static final long serialVersionUID = 8101930390397976027L; diff --git a/src/test/java/com/cronutils/parser/CronParserTest.java b/src/test/java/com/cronutils/parser/CronParserTest.java index 3be2edc6..86819e39 100755 --- a/src/test/java/com/cronutils/parser/CronParserTest.java +++ b/src/test/java/com/cronutils/parser/CronParserTest.java @@ -71,7 +71,7 @@ public void testParseIncompleteEvery() { private static void validateExpression(CronType cronType, String expression) { CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(cronType); CronParser parser = new CronParser(cronDefinition); - System.out.println(String.format("Validating expression '%s' using %s definition", expression, cronType)); + System.out.printf("Validating expression '%s' using %s definition%n", expression, cronType); parser.parse(expression); }