/*
 * Copyright (c) 2004-2019, University of Oslo
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 * Neither the name of the HISP project nor the names of its contributors may
 * be used to endorse or promote products derived from this software without
 * specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package org.hisp.dhis.android.core.period;

import android.support.test.runner.AndroidJUnit4;

import org.hisp.dhis.android.core.data.database.DatabaseAdapterFactory;
import org.hisp.dhis.android.core.data.database.ObjectWithoutUidStoreAbstractIntegrationShould;
import org.hisp.dhis.android.core.data.period.PeriodSamples;
import org.junit.runner.RunWith;

import java.util.Date;

@RunWith(AndroidJUnit4.class)
public class PeriodStoreIntegrationShould extends ObjectWithoutUidStoreAbstractIntegrationShould<Period> {

    public PeriodStoreIntegrationShould() {
        super(PeriodStore.create(DatabaseAdapterFactory.get(false)), PeriodTableInfo.TABLE_INFO,
                DatabaseAdapterFactory.get(false));
    }

    @Override
    protected Period buildObject() {
        return PeriodSamples.getPeriod();
    }

    @Override
    protected Period buildObjectToUpdate() {
        return PeriodSamples.getPeriod().toBuilder()
                .startDate(new Date())
                .build();
    }

    @Override
    protected Period buildObjectWithId() {
        return PeriodSamples.getPeriod().toBuilder()
                .id(1L)
                .build();
    }
}
@@ -1646,16 +1646,81 @@
 Unit4;%0A%0A
+import org.hisp.dhis.android.core.common.BaseIdentifiableObject;%0A
 import o
@@ -1940,16 +1940,39 @@
 amples;%0A
+import org.junit.Test;%0A
 import o
@@ -2013,17 +2013,107 @@
 ava.
-util.Date
+text.ParseException;%0Aimport java.util.Date;%0A%0Aimport static com.google.common.truth.Truth.assertThat
 ;%0A%0A@
@@ -2249,16 +2249,54 @@
 iod%3E %7B%0A%0A
+    private PeriodStore periodStore;%0A%0A
     publ
@@ -2356,16 +2356,20 @@
 iodStore
+Impl
 .create(
@@ -2484,16 +2484,102 @@
 alse));%0A
+        this.periodStore = PeriodStoreImpl.create(DatabaseAdapterFactory.get(false));%0A
     %7D%0A%0A 
@@ -3026,10 +3026,459 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void select_correct_period_passing_period_type_and_a_date() throws ParseException %7B%0A        new PeriodHandler(periodStore, ParentPeriodGeneratorImpl.create()).generateAndPersist();%0A%0A        Period period = periodStore.selectPeriodByTypeAndDate(PeriodType.WeeklySaturday,%0A                BaseIdentifiableObject.DATE_FORMAT.parse(%222018-12-24T12:24:25.319%22));%0A%0A        assertThat(period.periodId()).isEqualTo(%222018SatW52%22);%0A    %7D
 %0A%7D

Add test to PeriodStoreIntegrationShould