<commit_before>package com.sloshydog.eventuate.filesystem;

import com.sloshydog.eventuate.api.Event;
import com.sloshydog.eventuate.api.EventSpecification;
import com.sloshydog.eventuate.api.EventStore;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

@RunWith(MockitoJUnitRunner.class)
public class FileSystemEventStoreTest {

    @Mock
    private EventStoreFileResolver eventStoreFileResolver;
    @Mock
    private FileSystemEventMessageWriter eventMessageWriter;

    @Test
    public void shouldBeAnEventStore() {
        Assertions.assertThat(EventStore.class).isAssignableFrom(FileSystemEventStore.class);
    }

    @Test(expected = IllegalArgumentException.class)
    public void shouldThrowAnExceptionWhenTheEventIsNull() {
        EventStore eventStore = new FileSystemEventStore(eventStoreFileResolver, eventMessageWriter);
        eventStore.store(null);
    }

    @Test
    public void shouldBeAbleToStoreAnEventToTheFileSystem() throws IOException {
        Event newEvent = Mockito.mock(Event.class);
        Mockito.when(newEvent.getAggregateIdentifier()).thenReturn("124");
        Mockito.when(newEvent.getAggregateType()).thenReturn("type");

        Mockito.when(newEvent.getPayload()).thenReturn("Events payload");

        File eventFileDirectory = new File(System.getProperty("java.io.tmpdir"), "/type");
        eventFileDirectory.mkdirs();
        File eventFile = new File(eventFileDirectory, "124.evt");

        Mockito.when(eventStoreFileResolver.getFileFor(new EventSpecification("type", "124"))).thenReturn(eventFile);

        EventStore eventStore = new FileSystemEventStore(eventStoreFileResolver, eventMessageWriter);
        eventStore.store(newEvent);

        FileInputStream inputStream = null;
        try {
            inputStream = new FileInputStream(eventFile);

            Assertions.assertThat(new DataInputStream(inputStream).readUTF()).isEqualTo("Events payload");
        } finally {
            if (inputStream != null) {
                inputStream.close();
            }
        }
    }

    // TODO require a test when exception is thrown during storage.
//    @Test()
//    public void shouldBeAbleToReadAnEventForTheStore() {
//        Event newEvent = mock(Event.class);
//        when(newEvent.getAggregateIdentifier()).thenReturn("123");
//        when(newEvent.getAggregateType()).thenReturn("type");
//
//        when(newEvent.getPayload()).thenReturn("Events payload");
//
//        EventStore eventStore = new FileSystemEventStore(System.getProperty("java.io.tmpdir"));
//        eventStore.store(newEvent);
//
//        EventStream events = eventStore.getMatching(new EventSpecification("123", "type"));
//        assertThat(events.iterator()).extracting("identifier").containsExactly("123");
//    }
}<commit_msg>Fixed broken build I hope....<commit_after>package com.sloshydog.eventuate.filesystem;

import com.sloshydog.eventuate.api.Event;
import com.sloshydog.eventuate.api.EventSpecification;
import com.sloshydog.eventuate.api.EventStore;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;

import java.io.DataOutput;
import java.io.File;
import java.io.IOException;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;

@RunWith(MockitoJUnitRunner.class)
public class FileSystemEventStoreTest {

    @Mock
    private EventStoreFileResolver eventStoreFileResolver;
    @Mock
    private FileSystemEventMessageWriter eventMessageWriter;

    @Test
    public void shouldBeAnEventStore() {
        Assertions.assertThat(EventStore.class).isAssignableFrom(FileSystemEventStore.class);
    }

    @Test(expected = IllegalArgumentException.class)
    public void shouldThrowAnExceptionWhenTheEventIsNull() {
        EventStore eventStore = new FileSystemEventStore(eventStoreFileResolver, eventMessageWriter);
        eventStore.store(null);
    }

    @Test
    public void shouldBeAbleToStoreAnEventToTheFileSystem() throws IOException {
        Event newEvent = Mockito.mock(Event.class);
        Mockito.when(newEvent.getAggregateIdentifier()).thenReturn("124");
        Mockito.when(newEvent.getAggregateType()).thenReturn("type");

        Mockito.when(newEvent.getPayload()).thenReturn("Events payload");

        File eventFileDirectory = new File(System.getProperty("java.io.tmpdir"), "/type");
        eventFileDirectory.mkdirs();
        File eventFile = new File(eventFileDirectory, "124.evt");

        Mockito.when(eventStoreFileResolver.getFileFor(new EventSpecification("type", "124"))).thenReturn(eventFile);

        EventStore eventStore = new FileSystemEventStore(eventStoreFileResolver, eventMessageWriter);
        eventStore.store(newEvent);

        verify(eventMessageWriter).writeEventMessage(any(DataOutput.class), eq(newEvent));
    }

    // TODO require a test when exception is thrown during storage.
//    @Test()
//    public void shouldBeAbleToReadAnEventForTheStore() {
//        Event newEvent = mock(Event.class);
//        when(newEvent.getAggregateIdentifier()).thenReturn("123");
//        when(newEvent.getAggregateType()).thenReturn("type");
//
//        when(newEvent.getPayload()).thenReturn("Events payload");
//
//        EventStore eventStore = new FileSystemEventStore(System.getProperty("java.io.tmpdir"));
//        eventStore.store(newEvent);
//
//        EventStream events = eventStore.getMatching(new EventSpecification("123", "type"));
//        assertThat(events.iterator()).extracting("identifier").containsExactly("123");
//    }
}
{'fraction_non_alphanumeric': 0.11674528301886793, 'fraction_numerical': 0.006064690026954178, 'mean_word_length': 4.070025619128949, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4560976', 'n_tokens_mistral': 1682, 'n_tokens_neox': 1649, 'n_words': 270}