/*
 *  Copyright (c) 2004-2021, 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.testapp.datastore;

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

import org.hisp.dhis.android.core.datastore.KeyValuePair;
import org.hisp.dhis.android.core.maintenance.D2Error;
import org.hisp.dhis.android.core.utils.integration.mock.BaseMockIntegrationTestFullDispatcher;
import org.hisp.dhis.android.core.utils.runner.D2JunitRunner;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(D2JunitRunner.class)
public class LocalDataStoreCollectionRepositoryMockIntegrationShould extends BaseMockIntegrationTestFullDispatcher {

    @Test
    public void add_values() throws D2Error {
        d2.localDataStoreModule().localDataStore().blockingAdd(
                KeyValuePair.builder()
                        .key("key1")
                        .value("value1")
                        .build()
        );
        d2.localDataStoreModule().localDataStore().blockingAdd(
                KeyValuePair.builder()
                        .key("key2")
                        .value("value2")
                        .build()
        );
        assertThat(d2.localDataStoreModule().localDataStore().blockingGet().size()).isEqualTo(2);
    }

    @Test
    public void find_all() {
        assertThat(d2.localDataStoreModule().localDataStore().blockingGet().size()).isEqualTo(2);
    }

    @Test
    public void filter_by_key() {
        KeyValuePair pair = d2.localDataStoreModule().localDataStore()
                .byKey().eq("key1")
                .one()
                .blockingGet();

        assertThat(pair.key()).isEqualTo("key1");
        assertThat(pair.value()).isEqualTo("value1");
    }

    @Test
    public void filter_by_value() {
        KeyValuePair pair = d2.localDataStoreModule().localDataStore()
                .byValue().eq("value2")
                .one()
                .blockingGet();

        assertThat(pair.key()).isEqualTo("key2");
        assertThat(pair.value()).isEqualTo("value2");
    }
}
@@ -2192,631 +2192,42 @@
 oid 
-add_values() throws D2Error %7B%0A        d2.localDataStoreModule().localDataStore().blockingAdd(%0A                KeyValuePair.builder()%0A                        .key(%22key1%22)%0A                        .value(%22value1%22)%0A                        .build()%0A        );%0A        d2.localDataStoreModule().localDataStore().blockingAdd(%0A                KeyValuePair.builder()%0A                        .key(%22key2%22)%0A                        .value(%22value2%22)%0A                        .build()%0A        );%0A        assertThat(d2.localDataStoreModule().localDataStore().blockingGet().size()).isEqualTo(2);%0A    %7D%0A%0A    @Test%0A    public void find_all() %7B
+find_all() %7B%0A        add_values();
 %0A   
@@ -2368,24 +2368,46 @@
 _by_key() %7B%0A
+        add_values();%0A
         KeyV
@@ -2710,24 +2710,46 @@
 y_value() %7B%0A
+        add_values();%0A
         KeyV
@@ -2949,24 +2949,24 @@
 To(%22key2%22);%0A
-
         asse
@@ -3012,10 +3012,718 @@
 );%0A    %7D
+%0A%0A    private void add_values() %7B%0A        try %7B%0A            d2.localDataStoreModule().localDataStore().blockingAdd(%0A                    KeyValuePair.builder()%0A                            .key(%22key1%22)%0A                            .value(%22value1%22)%0A                            .build());%0A            d2.localDataStoreModule().localDataStore().blockingAdd(%0A                    KeyValuePair.builder()%0A                            .key(%22key2%22)%0A                            .value(%22value2%22)%0A                            .build());%0A        %7D catch (D2Error d2Error) %7B%0A            d2Error.printStackTrace();%0A        %7D%0A        assertThat(d2.localDataStoreModule().localDataStore().blockingGet().size()).isEqualTo(2);%0A    %7D
 %0A%7D

Improve LocalDataStoreCollectionRepositoryMockIntegrationShould