/*
 * 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.common;

import android.database.Cursor;
import android.database.sqlite.SQLiteConstraintException;
import android.support.test.runner.AndroidJUnit4;

import org.hisp.dhis.android.core.data.database.AbsStoreTestCase;
import org.hisp.dhis.android.core.option.OptionSetModel;
import org.hisp.dhis.android.core.option.OptionSetStore;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.IOException;

import static org.hisp.dhis.android.core.common.StoreMocks.optionSetCursorAssert;

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

    private ObjectStore<OptionSetModel> store;

    private OptionSetModel model;

    @Override
    @Before
    public void setUp() throws IOException {
        super.setUp();
        this.model = StoreMocks.generateOptionSetModel();
        this.store = OptionSetStore.create(databaseAdapter());
    }

    @Test
    public void insert_model() {
        store.insert(model);
        Cursor cursor = getCursor(OptionSetModel.TABLE, new OptionSetModel.Columns().all());
        optionSetCursorAssert(cursor, model);
    }

    @Test(expected = IllegalArgumentException.class)
    public void throw_exception_for_null_when_inserting() {
        store.insert(null);
    }

    @Test(expected = SQLiteConstraintException.class)
    public void throw_exception_for_second_identical_insertion() {
        store.insert(this.model);
        store.insert(this.model);
    }
}

@@ -1847,21 +1847,16 @@
 ptionSet
-Model
 ;%0Aimport
@@ -1902,24 +1902,85 @@
 onSetStore;%0A
+import org.hisp.dhis.android.core.option.OptionSetTableInfo;%0A
 import org.j
@@ -2273,16 +2273,28 @@
 private 
+Identifiable
 ObjectSt
@@ -2306,21 +2306,16 @@
 ptionSet
-Model
 %3E store;
@@ -2341,19 +2341,18 @@
 nSet
-Model model
+ optionSet
 ;%0A%0A 
@@ -2457,21 +2457,25 @@
    this.
-model
+optionSet
  = Store
@@ -2497,21 +2497,16 @@
 ptionSet
-Model
 ();%0A    
@@ -2604,21 +2604,26 @@
  insert_
-model
+option_set
 () %7B%0A   
@@ -2640,21 +2640,25 @@
 .insert(
-model
+optionSet
 );%0A     
@@ -2699,41 +2699,68 @@
 nSet
-Model.TABLE, new OptionSetModel.C
+TableInfo.TABLE_INFO.name(), OptionSetTableInfo.TABLE_INFO.c
 olum
@@ -2810,21 +2810,25 @@
 cursor, 
-model
+optionSet
 );%0A    %7D
@@ -3120,29 +3120,33 @@
 insert(this.
-model
+optionSet
 );%0A        s
@@ -3166,13 +3166,17 @@
 his.
-model
+optionSet
 );%0A 

Unify ObjectStoreIntegrationShould