package com.github.gfx.hankei_n.test;

import com.google.android.gms.maps.model.LatLng;

import com.github.gfx.hankei_n.BuildConfig;
import com.github.gfx.hankei_n.model.LocationMemo;
import com.github.gfx.hankei_n.model.LocationMemoManager;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

import android.content.Context;

import java.util.List;

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, manifest = Config.NONE)
public class LocationMemoManagerTest {

    Context context;

    LocationMemoManager memos;

    @Before
    public void setUp() throws Exception {
        context = RuntimeEnvironment.application;
        reset();
        memos.clear();
    }

    void reset() {
        memos = new LocationMemoManager(context, "test.db");
    }

    @Test
    public void testAdd() throws Exception {
        memos.upsert(new LocationMemo("foo", "note 1", new LatLng(1.0, 2.0), 1.5));
        memos.upsert(new LocationMemo("bar", "note 2", new LatLng(3.0, 4.0), 1.5));

        List<LocationMemo> list = memos.all();

        assertThat(list.size(), is(2));

        assertThat(list.get(0).address, is("foo"));
        assertThat(list.get(1).address, is("bar"));
    }

    @Test
    public void testRemove() throws Exception {
        LocationMemo a = new LocationMemo("foo", "note 1", new LatLng(1.0, 2.0), 1.5);
        LocationMemo b = new LocationMemo("bar", "note 2", new LatLng(3.0, 4.0), 1.5);


        memos.upsert(a);
        memos.upsert(b);

        memos.remove(a);

        List<LocationMemo> list = memos.all();

        assertThat(list.size(), is(1));

        assertThat(list.get(0), is(b));
    }


    @Test
    public void testSaveAndLoad() throws Exception {

        memos.upsert(new LocationMemo("foo", "note 1", new LatLng(1.0, 2.0), 1.5));
        memos.upsert(new LocationMemo("bar", "note 2", new LatLng(3.0, 4.0), 1.5));

        reset();

        List<LocationMemo> list = memos.all();
        assertThat(list.size(), is(2));

        assertThat(list.get(0).address, is("foo"));
        assertThat(list.get(0).note, is("note 1"));
        assertThat(list.get(0).buildLocation(), is(new LatLng(1.0, 2.0)));

        assertThat(list.get(1).address, is("bar"));
        assertThat(list.get(1).note, is("note 2"));
        assertThat(list.get(1).buildLocation(), is(new LatLng(3.0, 4.0)));
    }
}

@@ -1151,32 +1151,35 @@
 g(1.0, 2.0), 1.5
+, 0
 ));%0A        memo
@@ -1238,32 +1238,35 @@
 g(3.0, 4.0), 1.5
+, 0
 ));%0A%0A        Lis
@@ -1596,16 +1596,19 @@
 .0), 1.5
+, 0
 );%0A     
@@ -1686,16 +1686,19 @@
 .0), 1.5
+, 0
 );%0A%0A%0A   
@@ -2048,24 +2048,27 @@
 0, 2.0), 1.5
+, 0
 ));%0A        
@@ -2139,16 +2139,19 @@
 .0), 1.5
+, 0
 ));%0A%0A   

fix tests