package com.cronutils.utils.descriptor;

import com.cronutils.descriptor.CronDescriptor;
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 java.util.Locale;

import static org.junit.Assert.assertEquals;
/*
 * Copyright 2015 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.
 */
public class CronDescriptorQuartzIntegrationTest {

    private CronDescriptor descriptor;
    private CronParser parser;

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

    @Test
    public void testCronWithAndHours(){
        assertEquals("at 1, 2, 3 and 4 hours", descriptor.describe(parser.parse("* * 1,2,3,4 * * * *")));
    }

    @Test
    public void testCronAndWithRangeHours(){
        assertEquals("at 1, 2, 3 and 4 hours and every hour between 6 and 9",
                descriptor.describe(parser.parse("* * 1,2,3,4,6-9 * * * *")));
    }

    @Test
    public void testCronAndWithRangesAndEveryExpressions(){
        assertEquals("every 3 minutes between 2 and 59 at 1, 9 " +
                "and 22 hours every day between 11 and 26 every month between January and June",
                descriptor.describe(parser.parse("0 2-59/3 1,9,22 11-26 1-6 ?")));
    }

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

    @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");
    }

    /* Examples exposed at cron documentations */
    @Test
    public void testEveryDayFireAtNoon() throws Exception {
        assertExpression("0 0 12 * * ?", "at 12:00");
    }

    @Test
    public void testEveryDayFireAtTenFifteen() throws Exception {
        String description = "at 10:15";
        assertExpression("0 15 10 ? * *", description);
        assertExpression("0 15 10 * * ?", description);
        assertExpression("0 15 10 * * ? *", description);
    }

    @Test
    public void testEveryDayFireAtTenFifteenYear2005() throws Exception {
        assertExpression("0 15 10 * * ? 2005", "at 10:15 at 2005 year");
    }

    @Test
    public void testEveryMinuteBetween14and15EveryDay() throws Exception {
        assertExpression("0 * 14 * * ?", "at 14 hour");
    }

    @Test
    public void testEveryFiveMinutesBetween14and15EveryDay() throws Exception {
        assertExpression("0 0/5 14 * * ?", "every 5 minutes at 14 hour");
    }

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

@@ -3338,24 +3338,223 @@
 r%22);%0A    %7D%0A%0A
+    @Test%0A    public void testEveryFiveMinutesBetween14and15AndBetween18And19EveryDay() throws Exception %7B%0A        assertExpression(%220 0/5 14,18 * * ?%22, %22every 5 minutes at 14 and 18 hours%22);%0A    %7D%0A%0A
     private 

Add more test cases for Quartz expressions.