<commit_before>package de.otto.edison.mongo;

import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import de.otto.edison.mongo.configuration.MongoProperties;
import de.otto.edison.mongo.testsupport.EmbeddedMongoHelper;
import org.bson.Document;
import org.hamcrest.CustomMatcher;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.io.IOException;
import java.util.*;

import static java.util.Arrays.asList;
import static java.util.stream.Collectors.toList;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.IsNot.not;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

public class AbstractMongoRepositoryTest {

    private TestRepository testee;

    @BeforeAll
    public static void setupMongo() throws IOException {
        EmbeddedMongoHelper.startMongoDB();
    }

    @AfterAll
    public static void teardownMongo() {
        EmbeddedMongoHelper.stopMongoDB();
    }

    @BeforeEach
    public void setUp() {
        final MongoDatabase mongoDatabase = EmbeddedMongoHelper.getMongoClient().getDatabase("test-" + UUID.randomUUID());
        testee = new TestRepository(mongoDatabase);
    }

    @Test
    public void shouldCreateOrUpdateBulk() {
        // given
        final TestObject testObjectA = new TestObject("someIdA", "someValueA");
        final TestObject testObjectB = new TestObject("someIdB", "someValueB");

        // when
        testee.createOrUpdateBulk(asList(testObjectA, testObjectB));

        // then
        final List<TestObject> foundObjects = testee.findAll();
        assertThat(foundObjects.size(), is(2));
        assertThat(foundObjects, Matchers.containsInAnyOrder(asList(
                new TestObjectMatcher(testObjectA),
                new TestObjectMatcher(testObjectB)));
    }

    @Test
    public void shouldHaveNoDbInteractionForEmptyListsUsingCreateOrUpdateBulk() {
        testee = spy(new TestRepository(Mockito.mock(MongoDatabase.class)));

        // given
        final List<TestObject> emptyList = Collections.emptyList();

        // when
        testee.createOrUpdateBulk(emptyList);

        // then
        verify(testee, never()).collection();
    }

    @Test
    public void shouldUpdateExistingDocument() {
        // given
        final TestObject testObject = new TestObject("someId", "someValue");
        testee.create(testObject);

        final TestObject testObjectToUpdate = new TestObject("someId", "someUpdatedValue");

        // when<commit_msg>Fixes broken test after merge<commit_after>package de.otto.edison.mongo;

import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import de.otto.edison.mongo.configuration.MongoProperties;
import de.otto.edison.mongo.testsupport.EmbeddedMongoHelper;
import org.bson.Document;
import org.hamcrest.CustomMatcher;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.io.IOException;
import java.util.*;

import static java.util.Arrays.asList;
import static java.util.stream.Collectors.toList;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.IsNot.not;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.*;

public class AbstractMongoRepositoryTest {

    private TestRepository testee;

    @BeforeAll
    public static void setupMongo() throws IOException {
        EmbeddedMongoHelper.startMongoDB();
    }

    @AfterAll
    public static void teardownMongo() {
        EmbeddedMongoHelper.stopMongoDB();
    }

    @BeforeEach
    public void setUp() {
        final MongoDatabase mongoDatabase = EmbeddedMongoHelper.getMongoClient().getDatabase("test-" + UUID.randomUUID());
        testee = new TestRepository(mongoDatabase);
    }

    @Test
    public void shouldCreateOrUpdateBulk() {
        // given
        final TestObject testObjectA = new TestObject("someIdA", "someValueA");
        final TestObject testObjectB = new TestObject("someIdB", "someValueB");

        // when
        testee.createOrUpdateBulk(asList(testObjectA, testObjectB));

        // then
        final List<TestObject> foundObjects = testee.findAll();
        assertThat(foundObjects.size(), is(2));
        assertThat(foundObjects, Matchers.containsInAnyOrder(asList(
                new TestObjectMatcher(testObjectA),
                new TestObjectMatcher(testObjectB))));
    }

    @Test
    public void shouldHaveNoDbInteractionForEmptyListsUsingCreateOrUpdateBulk() {
        testee = spy(new TestRepository(Mockito.mock(MongoDatabase.class)));

        // given
        final List<TestObject> emptyList = Collections.emptyList();

        // when
        testee.createOrUpdateBulk(emptyList);

        // then
        verify(testee, never()).collection();
    }

    @Test
    public void shouldUpdateExistingDocument() {
        // given
        final TestObject testObject = new TestObject("someId", "someValue");
        testee.create(testObject);

        final TestObject testObjectToUpdate = new TestObject("someId", "someUpdatedValue");

        // when
{'fraction_non_alphanumeric': 0.1016330785267547, 'fraction_numerical': 0.00034746351633078526, 'mean_word_length': 3.5945730247406225, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6746946', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1662, 'n_words': 324}