package org.synyx.urlaubsverwaltung.availability.api;

import org.junit.Assert;
import org.junit.Test;
import org.synyx.urlaubsverwaltung.availability.api.TimedAbsence;
import org.synyx.urlaubsverwaltung.availability.api.TimedAbsenceSpans;
import org.synyx.urlaubsverwaltung.period.DayLength;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


public class TimedAbsenceSpansTest {

    @Test
    public void ensurePresenceRatioCalculatedCorrectly() {

        TimedAbsence timedAbsence1 = new TimedAbsence(DayLength.MORNING, TimedAbsence.Type.FREETIME);
        TimedAbsence timedAbsence2 = new TimedAbsence(DayLength.NOON, TimedAbsence.Type.VACATION);

        List<TimedAbsence> absenceList = Arrays.asList(timedAbsence1, timedAbsence2);

        TimedAbsenceSpans timedAbsenceSpans = new TimedAbsenceSpans(absenceList);

        BigDecimal presenceRatio = timedAbsenceSpans.calculatePresenceRatio();
        Assert.assertTrue(BigDecimal.ZERO.compareTo(presenceRatio) == 0);
    }


    @Test
    public void ensurePresenceRatioIsNotNegative() {

        TimedAbsence timedAbsence1 = new TimedAbsence(DayLength.MORNING, TimedAbsence.Type.FREETIME);
        TimedAbsence timedAbsence2 = new TimedAbsence(DayLength.FULL, TimedAbsence.Type.SICK_NOTE);

        List<TimedAbsence> absenceList = Arrays.asList(timedAbsence1, timedAbsence2);

        TimedAbsenceSpans timedAbsenceSpans = new TimedAbsenceSpans(absenceList);

        BigDecimal presenceRatio = timedAbsenceSpans.calculatePresenceRatio();
        Assert.assertTrue(BigDecimal.ZERO.compareTo(presenceRatio) == 0);
    }


    @Test
    public void ensurePresenceRatioIsCalculatedCorrectlyForEmptyList() {

        BigDecimal presenceRatio = new TimedAbsenceSpans(new ArrayList<>()).calculatePresenceRatio();
        Assert.assertTrue(BigDecimal.ONE.compareTo(presenceRatio) == 0);
    }


    @Test
    public void ensureCalculationIsNullSave() {

        new TimedAbsenceSpans(null).calculatePresenceRatio();
    }
}

@@ -393,16 +393,75 @@
 .List;%0A%0A
+import static org.assertj.core.api.Assertions.assertThat;%0A%0A
 %0Apublic 
@@ -2025,16 +2025,46 @@
 %0A       
+ final BigDecimal bigDecimal =
  new Tim
@@ -2106,20 +2106,77 @@
 nceRatio();%0A
+        assertThat(bigDecimal).isSameAs(BigDecimal.ONE);%0A
     %7D%0A%7D%0A

Add assert for timed absence spans test for null safety