/*
 * Copyright 2015, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.android.testing.notes.model;

import com.example.android.testing.notes.model.NotesRepository.LoadNotesCallback;
import com.example.android.testing.notes.model.NotesServiceApi.NotesServiceCallback;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.verify;

/**
 * TODO: javadoc, add tests for caching notes behaviour
 */
public class NotesRepositoryTest {

    @Mock
    private NotesServiceApiImpl mServiceApi;

    @Mock
    private LoadNotesCallback mLoadNotesCallback;

    private InMemoryNotesRepository mNotesRepository;

    @Before
    public void setupNotesRepository() {
        MockitoAnnotations.initMocks(this);
        mNotesRepository = new InMemoryNotesRepository(mServiceApi);
    }

    @Test
    public void getNotes_RequestsAllNotesFromServiceApi() {
        mNotesRepository.getNotes(mLoadNotesCallback);
        verify(mServiceApi).getAllNotes(any(NotesServiceCallback.class));
    }

    @Test
    public void saveNote_savesNoteToServiceAPIAndInvalidatesCache() {
        final Note newNote = new Note("New Note Title", "Some Note Description");
        mNotesRepository.saveNote(newNote);
        assertThat(mNotesRepository.mCachedNotes, is(nullValue()));
    }
    
    @Test
    public void getNote_RequestsSingleNoteFromServiceApi() {
        mNotesRepository.getNote(any(String.class), any(NotesRepository.GetNoteCallback.class));
        verify(mServiceApi).getNote(any(String.class), any(NotesServiceCallback.class));
    }
}

@@ -661,16 +661,96 @@
 model;%0A%0A
+import com.example.android.testing.notes.model.NotesRepository.GetNoteCallback;%0A
 import c
@@ -815,32 +815,32 @@
 dNotesCallback;%0A
-
 import com.examp
@@ -1192,16 +1192,55 @@
 rs.any;%0A
+import static org.mockito.Matchers.eq;%0A
 import s
@@ -1374,16 +1374,71 @@
 Test %7B%0A%0A
+    private final static String NOTE_TITLE = %22title%22;%0A%0A
     @Moc
@@ -1546,16 +1546,73 @@
 lback;%0A%0A
+    @Mock%0A    private GetNoteCallback mGetNoteCallback;%0A%0A
     priv
@@ -1866,17 +1866,17 @@
 etNotes_
-R
+r
 equestsA
@@ -2159,24 +2159,18 @@
 ote(
-%22New Note Title%22
+NOTE_TITLE
 , %22S
@@ -2315,13 +2315,9 @@
   %7D%0A
-    
 %0A
+
     
@@ -2346,17 +2346,17 @@
 getNote_
-R
+r
 equestsS
@@ -2420,47 +2420,21 @@
 ote(
-any(String.class), any(NotesRepository.
+NOTE_TITLE, m
 GetN
@@ -2440,31 +2440,24 @@
 NoteCallback
-.class)
 );%0A        v
@@ -2487,24 +2487,21 @@
 ote(
-any(String.class
+eq(NOTE_TITLE
 ), a

Fix for test following new checkNotNull in code