Skip to content

Commit

Permalink
Issues #3 #12 Add CronDescriptorQuartzIntegrationTest.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmrozanec committed Jun 26, 2015
1 parent 4756362 commit 39313e7
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,21 @@ public String describe(Cron cron) {
.append(descriptor.describe(month, year, yearRange))
.toString().replaceAll("\\s+", " ").trim();
}

/**
* Creates an instance with UK locale
* @return CronDescriptor - never null.
*/
public static CronDescriptor instance() {
return new CronDescriptor();
}

/**
* Creates and instance with given locale
* @param locale - Locale in which descriptions will be given
* @return CronDescriptor - never null.
*/
public static CronDescriptor instance(Locale locale) {
return new CronDescriptor(locale);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ protected String describe(FieldExpression previous, FieldExpression current, Ran
}
}
if (current instanceof On) {
if(((On)current).getTime().getValue()==0){
return "";
}
return describeOnX(previous, (On)current, onX);
}
if (current instanceof And) {
Expand Down Expand Up @@ -161,7 +164,7 @@ protected String describe(FieldExpression previous, FieldExpression current, Ran
}

protected String describeAlways(FieldExpression previous, FieldExpression current, String always){
if(previous instanceof Always){
if(previous instanceof Always || previous instanceof Every){
return "";
}
return bundle.getString(always);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.cronutils.descriptor.refactor;

import com.cronutils.model.CronType;
import com.cronutils.model.definition.CronDefinitionBuilder;
import com.cronutils.parser.CronParser;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

public class CronDescriptorQuartzIntegrationTest {
private CronParser parser;
CronDescriptor descriptor;

@Before
public void setUp() throws Exception {
parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ));
descriptor = CronDescriptor.instance();
}

@Test
public void testDescribeEverySecond() throws Exception {
assertEquals("every second", descriptor.describe(parser.parse("* * * * * *")));
}

@Test
public void testDescribeEveryMinute() throws Exception {
assertExpression("0 * * * * *", "every minute");
}

@Test
public void testDescribeEveryHour() throws Exception {
assertExpression("0 0 * * * *", "every hour");
}

@Test
public void testDescribeEveryDayOfWeek() throws Exception {
assertExpression("0 0 0 * * *", "every day of week");
}

//TODO fix: we get: every day of week on day 1 every month
public void testDescribeEveryDayOfMonth() throws Exception {
assertExpression("0 0 0 1 * *", "first day of every month");
}

public void testDescribeEveryYear() throws Exception {
assertExpression("0 0 0 1 1 *", "first day in the year");
}

@Test
public void testEvery45Seconds(){
assertExpression("*/45 * * * * *", "every 45 seconds");
}

@Test
public void testEveryHour(){
assertExpression("0 0 * * * ?", "every hour");
assertExpression("0 0 0/1 * * ?", "every hour");
}

//TODO fix: now getting: between 5 minute at 14 hs every day of week
public void testEveryFiveMinutesBetween14and15EveryDay() throws Exception {
//check http://english.stackexchange.com/questions/56869/24-hour-time-how-to-say-it
assertExpression("0 0/5 14 * * ?", "every 5 minutes at 14");
}

private void assertExpression(String cron, String description){
assertEquals(description, descriptor.describe(parser.parse(cron)));
}
}

0 comments on commit 39313e7

Please sign in to comment.