/*
 * Copyright (c) 2017, 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.indicator;

import android.support.test.runner.AndroidJUnit4;

import org.hisp.dhis.android.core.common.IdentifiableObjectStore;
import org.hisp.dhis.android.core.common.ObjectWithUid;
import org.hisp.dhis.android.core.data.database.AbsStoreTestCase;
import org.hisp.dhis.android.core.data.indicator.IndicatorSamples;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.IOException;

import static com.google.common.truth.Truth.assertThat;

@RunWith(AndroidJUnit4.class)
public class IndicatorStoreIntegrationShould extends AbsStoreTestCase {

    private final Indicator indicator = IndicatorSamples.getIndicator();

    @Before
    @Override
    public void setUp() throws IOException {
        super.setUp();
        database().setForeignKeyConstraintsEnabled(false);
    }

    @Test
    public void get_inserted_object() {
        IdentifiableObjectStore<Indicator> store = IndicatorStore.create(databaseAdapter());
        store.insert(indicator);
        Indicator indicatorFromDb = store.selectFirst();
        assertThat(indicatorFromDb).isEqualTo(indicator);
    }

    @Test
    public void delete_inserted_object() {
        IdentifiableObjectStore<Indicator> store = IndicatorStore.create(databaseAdapter());
        store.insert(indicator);
        store.delete(indicator.uid());
        assertThat(store.selectFirst()).isEqualTo(null);
    }

    @Test
    public void update_inserted_object() {
        IdentifiableObjectStore<Indicator> store = IndicatorStore.create(databaseAdapter());
        store.insert(indicator);
        Indicator indicatorToUpdate = indicator.toBuilder()
                .indicatorType(ObjectWithUid.create("new_indicator_type_uid"))
                .build();
        store.update(indicatorToUpdate);
        Indicator indicatorFromDb = store.selectFirst();
        assertThat(indicatorFromDb).isEqualTo(indicatorToUpdate);
    }

    @Test
    public void select_inserted_object_uid() {
        IdentifiableObjectStore<Indicator> store = IndicatorStore.create(databaseAdapter());
        store.insert(indicator);
        String indicatorUidFromDb = store.selectUids().iterator().next();
        assertThat(indicatorUidFromDb).isEqualTo(indicator.uid());
    }
}
@@ -1685,39 +1685,29 @@
 .common.
-IdentifiableObjectStore
+ObjectWithUid
 ;%0Aimport
@@ -1734,36 +1734,52 @@
 id.core.
-common.ObjectWithUid
+data.database.DatabaseAdapterFactory
 ;%0Aimport
@@ -1820,32 +1820,64 @@
 atabase.
-AbsStoreTestCase
+IdentifiableObjectStoreAbstractIntegrationShould
 ;%0Aimport
@@ -1941,33 +1941,8 @@
 es;%0A
-import org.junit.Before;%0A
 impo
@@ -1998,532 +1998,215 @@
 h;%0A%0A
-import java.io.IOException;%0A%0Aimport static com.google.common.truth.Truth.assertThat;%0A%0A@RunWith(AndroidJUnit4.class)%0Apublic class IndicatorStoreIntegrationShould extends AbsStoreTestCase %7B%0A%0A    private final Indicator indicator = IndicatorSamples.getIndicator();%0A%0A    @Before%0A    @Override%0A    public void setUp() throws IOException %7B%0A        super.setUp();%0A        database().setForeignKeyConstraintsEnabled(false);%0A    %7D%0A%0A    @Test%0A    public void get_inserted_object() %7B%0A        IdentifiableObjectStore%3CIndicator%3E store = 
+@RunWith(AndroidJUnit4.class)%0Apublic class IndicatorStoreIntegrationShould extends IdentifiableObjectStoreAbstractIntegrationShould%3CIndicator%3E %7B%0A%0A    public IndicatorStoreIntegrationShould() %7B%0A        super(
 Indi
@@ -2215,33 +2215,33 @@
 torStore.create(
-d
+D
 atabaseAdapter()
@@ -2234,33 +2234,50 @@
 abaseAdapter
-(
+Factory.get(false)
 ));%0A    
     store.in
@@ -2268,149 +2268,109 @@
     
+%7D%0A%0A
     
-store.insert(indicator);%0A        Indicator indicatorFromDb = store.selectFirst();%0A        assertThat(indicatorFromDb).isEqualTo(i
+@Override%0A    protected Indicator buildObject() %7B%0A        return IndicatorSamples.getI
 ndicator
 );%0A 
@@ -2361,24 +2361,25 @@
 getIndicator
+(
 );%0A    %7D%0A%0A  
@@ -2385,148 +2385,121 @@
    @
-Test%0A    public void delete_inserted_object() %7B%0A        IdentifiableObjectStore%3CIndicator%3E store = IndicatorStore.create(databaseAdapt
+Override%0A    protected Indicator buildObjectWithId() %7B%0A        return IndicatorSamples.getIndicator().toBuild
 er()
-);
 %0A   
@@ -2507,362 +2507,163 @@
     
-store.insert(indicator);%0A        store.delete(indicator.uid());%0A        assertThat(store.selectFirst()).isEqualTo(null);%0A    %7D%0A%0A    @Test%0A    public void update_inserted_object() %7B%0A        IdentifiableObjectStore%3CIndicator%3E store = IndicatorStore.create(databaseAdapter());%0A        store.insert(indicator);%0A        Indicator indicatorToUpdate = i
+        .id(1L)%0A                .build();%0A    %7D%0A%0A    @Override%0A    protected Indicator buildObjectToUpdate() %7B%0A        return IndicatorSamples.getI
 ndicator
 .toB
@@ -2658,16 +2658,18 @@
 ndicator
+()
 .toBuild
@@ -2786,498 +2786,62 @@
     
-    store.update(indicatorToUpdate);%0A        Indicator indicatorFromDb = store.selectFirst();%0A        assertThat(indicatorFromDb).isEqualTo(indicatorToUpdate);%0A    %7D%0A%0A    @Test%0A    public void select_inserted_object_uid() %7B%0A        IdentifiableObjectStore%3CIndicator%3E store = IndicatorStore.create(databaseAdapter());%0A        store.insert(indicator);%0A        String indicatorUidFromDb = store.selectUids().iterator().next();%0A        assertThat(indicatorUidFromDb).isEqualTo(indicator.uid());
+%7D%0A%0A    @Test%0A    public void stub() throws Exception %7B
 %0A   

Add IndicatorStoreIntegrationShould