package de.atomfrede.github.karaoke.server.mongo;

import com.mongodb.DB;
import mockit.Mocked;
import mockit.NonStrictExpectations;
import mockit.integration.junit4.JMockit;
import org.jongo.Jongo;
import org.jongo.MongoCollection;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

@RunWith(JMockit.class)
public class SingerRepositoryTest {

    @Mocked
    DB database;
    @Mocked
    MongoCollection mongoCollection;
    @Mocked
    Jongo jongo;

    SingerRepository singerRepository;

    @Before
    public void setup() {
        singerRepository = new SingerRepository(database);
    }

    @Test
    public void assertThatCountIsReturned() {

        new NonStrictExpectations() {{

            mongoCollection.count();
            times = 1;
            result = 42;
        }};

        assertThat(singerRepository.count(), is(42L));
    }
}

@@ -67,16 +67,73 @@
 odb.DB;%0A
+import de.atomfrede.github.karaoke.server.entity.Singer;%0A
 import m
@@ -146,16 +146,16 @@
 Mocked;%0A
-
 import m
@@ -365,16 +365,42 @@
 nWith;%0A%0A
+import java.util.Arrays;%0A%0A
 import s
@@ -992,16 +992,16 @@
    %7D%7D;%0A%0A
-
         
@@ -1052,11 +1052,1539 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void assertThatEntityIsRemovedById() %7B%0A%0A        new NonStrictExpectations() %7B%7B%0A%0A            mongoCollection.remove(%22%7B_id:#%7D%22, %2242%22);%0A            times = 1;%0A        %7D%7D;%0A%0A        singerRepository.delete(%2242%22);%0A    %7D%0A%0A    @Test%0A    public void assertThatEntitiesAreRemovedById() %7B%0A%0A        new NonStrictExpectations() %7B%7B%0A%0A            mongoCollection.remove(%22%7B_id:#%7D%22, %2242%22);%0A            times = 1;%0A%0A            mongoCollection.remove(%22%7B_id:#%7D%22, %2217%22);%0A            times = 1;%0A        %7D%7D;%0A%0A        Singer janeDoe = new Singer(%2242%22)%0A                .setFirstname(%22Jane%22)%0A                .setLastname(%22Doe%22);%0A%0A        Singer johnDoe = new Singer(%2217%22)%0A                .setFirstname(%22John%22)%0A                .setLastname(%22Doe%22);%0A%0A        singerRepository.delete(Arrays.asList(janeDoe, johnDoe));%0A    %7D%0A%0A    @Test%0A    public void assertThatAllEntitiesAreRemoved() %7B%0A%0A        new NonStrictExpectations() %7B%7B%0A%0A            mongoCollection.drop();%0A            times = 1;%0A        %7D%7D;%0A%0A        singerRepository.deleteAll();%0A    %7D%0A%0A    @Test%0A    public void assertThatOneCanBeFound() %7B%0A%0A        new NonStrictExpectations() %7B%7B%0A%0A            mongoCollection.findOne(%22%7B_id:#%7D%22, %2242%22).as(Singer.class);%0A            times = 1;%0A            result = new Singer(%2242%22);%0A%0A            mongoCollection.findOne(%22%7B_id:#%7D%22, %2217%22).as(Singer.class);%0A            times = 1;%0A            result = null;%0A        %7D%7D;%0A%0A        assertThat(singerRepository.exists(%2242%22), is(true));%0A        assertThat(singerRepository.exists(%2217%22), is(false));%0A    %7D
 %0A%7D%0A

Test coverage