package fi.github.marsojm.runnersnotes.core.interactors;

import fi.github.marsojm.runnersnotes.boundary.CreateNoteRequest;
import fi.github.marsojm.runnersnotes.boundary.GetNoteListRequest;
import fi.github.marsojm.runnersnotes.boundary.GetNoteRequest;
import fi.github.marsojm.runnersnotes.boundary.NoteData;
import fi.github.marsojm.runnersnotes.gateway.implementations.InMemoryDb;
import org.junit.Before;
import org.junit.Test;

import java.util.Date;
import java.util.List;

import static org.junit.Assert.*;

/**
 * Created by Marko on 7.9.2015.
 */
public class NotesInteractorTest {

    private NotesInteractor interactor;

    @Before
    public void setUp() {
        interactor = new NotesInteractor(new InMemoryDb());
    }

    @Test
    public void testGetNote() throws Exception, EntityValidationException {
        int id = interactor.createNote(new CreateNoteRequest(new Date(), 10, 20, "no comments"));
        NoteData response = interactor.getNote(new GetNoteRequest(id));
        assertNotNull(response);
    }

    @Test
    public void testGetEmptyListOfNotes() throws Exception {
        List<NoteData> notes = interactor.getNoteList(new GetNoteListRequest());
        assertEquals(0, notes.size());
    }

    @Test
    public void testGetListOfNotes() throws Exception, EntityValidationException {
        interactor.createNote(new CreateNoteRequest(new Date(), 10, 20, "no comments"));
        interactor.createNote(new CreateNoteRequest(new Date(), 10, 20, "no comments"));
        interactor.createNote(new CreateNoteRequest(new Date(), 10, 20, "no comments"));

        List<NoteData> notes = interactor.getNoteList(new GetNoteListRequest());
        assertEquals(3, notes.size());
    }

    @Test
    public void testGetNoteWhenMultipleNotesExists() throws Exception, EntityValidationException {
        interactor.createNote(new CreateNoteRequest(new Date(), 10, 20, "no comments"));
        int id = interactor.createNote(new CreateNoteRequest(new Date(), 15, 30, "many comments"));
        NoteData response = interactor.getNote(new GetNoteRequest(id));
        assertNotNull(response);
    }
}
@@ -2122,10 +2122,280 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testValidationErrors() %7B%0A        try %7B%0A            interactor.createNote(new CreateNoteRequest(null, -10, -20, %22no comments%22));%0A        %7D catch (EntityValidationException e) %7B%0A            assertEquals(3, e.getErrors().size());%0A        %7D%0A    %7D
 %0A%7D

Test to make sure that entity validation errors propagate into interactor level