<commit_before>package be.doji.productivity.trambucore.exporters;

import be.doji.productivity.trambucore.TrambuTest;
import be.doji.productivity.trambucore.managers.ActivityManager;
import be.doji.productivity.trambucore.managers.TimeTrackingManager;
import be.doji.productivity.trambucore.model.tasks.Activity;
import be.doji.productivity.trambucore.model.tracker.ActivityLog;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;

import java.io.IOException;
import java.nio.file.Path;
import java.util.*;

public class TimesheetToCSVExporterTest extends TrambuTest {

    private static final String ACTIVITY_NAME = "TestAct";
    @Mock ActivityManager activityManagerMock;

    @Before public void init() {
        MockitoAnnotations.initMocks(this);
        Optional<Activity> activity = Optional.of(new Activity(ACTIVITY_NAME));
        Mockito.when(activityManagerMock.getSavedActivityById(Mockito.anyString())).thenReturn(activity);
    }

    @Test public void testExportFull() throws IOException {
        Path tempFile = createTempFile();
        TimeTrackingManager tm = new TimeTrackingManager(tempFile.toString());

        UUID activityOneId = UUID.randomUUID();
        ActivityLog logActivityOne = new ActivityLog(activityOneId);
        Calendar logOneStart = new GregorianCalendar(2017, Calendar.DECEMBER, 1, 14, 0, 0);
        Calendar logOneEnd = new GregorianCalendar(2017, Calendar.DECEMBER, 1, 18, 0, 0);
        logActivityOne.addLogPoint(createTimeLog(logOneStart.getTime(), logOneEnd.getTime()));

        UUID activityTwoId = UUID.randomUUID();
        ActivityLog logActivityTwo = new ActivityLog(activityTwoId);
        Calendar logTwoStart = new GregorianCalendar(2017, Calendar.DECEMBER, 4, 14, 0, 0);
        Calendar logTwoEnd = new GregorianCalendar(2017, Calendar.DECEMBER, 4, 19, 0, 0);
        logActivityTwo.addLogPoint(createTimeLog(logTwoStart.getTime(), logTwoEnd.getTime()));

        tm.save(logActivityOne);
        tm.save(logActivityTwo);

        List<ActivityLog> allLogsBeforeStop = tm.getLogs();

        TimesheetToCSVExporter exporter = new TimesheetToCSVExporter(activityManagerMock);
        List<String> fileLines = exporter.createFileLines(allLogsBeforeStop);
        Assert.assertNotNull(fileLines);
        Assert.assertFalse(fileLines.isEmpty());
        Assert.assertEquals(3, fileLines.size());
        String csvOfFirstLog = fileLines.get(1);
        Assert.assertEquals("TestAct,4.0,240.0,14000.0,TestAct", csvOfFirstLog);

    }
}<commit_msg>Fixed test<commit_after>package be.doji.productivity.trambucore.exporters;

import be.doji.productivity.trambucore.TrambuTest;
import be.doji.productivity.trambucore.managers.ActivityManager;
import be.doji.productivity.trambucore.managers.TimeTrackingManager;
import be.doji.productivity.trambucore.model.tasks.Activity;
import be.doji.productivity.trambucore.model.tracker.ActivityLog;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;

import java.io.IOException;
import java.nio.file.Path;
import java.util.*;

public class TimesheetToCSVExporterTest extends TrambuTest {

    private static final String ACTIVITY_NAME = "TestAct";
    @Mock ActivityManager activityManagerMock;

    @Before public void init() {
        MockitoAnnotations.initMocks(this);
        Optional<Activity> activity = Optional.of(new Activity(ACTIVITY_NAME));
        Mockito.when(activityManagerMock.getSavedActivityById(Mockito.anyString())).thenReturn(activity);
    }

    @Test public void testExportFull() throws IOException {
        Path tempFile = createTempFile();
        TimeTrackingManager tm = new TimeTrackingManager(tempFile.toString());

        UUID activityOneId = UUID.randomUUID();
        ActivityLog logActivityOne = new ActivityLog(activityOneId);
        Calendar logOneStart = new GregorianCalendar(2017, Calendar.DECEMBER, 1, 14, 0, 0);
        Calendar logOneEnd = new GregorianCalendar(2017, Calendar.DECEMBER, 1, 18, 0, 0);
        logActivityOne.addLogPoint(createTimeLog(logOneStart.getTime(), logOneEnd.getTime()));

        UUID activityTwoId = UUID.randomUUID();
        ActivityLog logActivityTwo = new ActivityLog(activityTwoId);
        Calendar logTwoStart = new GregorianCalendar(2017, Calendar.DECEMBER, 4, 14, 0, 0);
        Calendar logTwoEnd = new GregorianCalendar(2017, Calendar.DECEMBER, 4, 19, 0, 0);
        logActivityTwo.addLogPoint(createTimeLog(logTwoStart.getTime(), logTwoEnd.getTime()));

        tm.save(logActivityOne);
        tm.save(logActivityTwo);

        List<ActivityLog> allLogsBeforeStop = tm.getLogs();

        TimesheetToCSVExporter exporter = new TimesheetToCSVExporter(activityManagerMock);
        List<String> fileLines = exporter.createFileLines(allLogsBeforeStop);
        Assert.assertNotNull(fileLines);
        Assert.assertFalse(fileLines.isEmpty());
        Assert.assertEquals(3, fileLines.size());
        String csvOfFirstLog = fileLines.get(1);
        Assert.assertEquals("TestAct,\"4.0\",\"240.0\",\"14000.0\",TestAct", csvOfFirstLog);

    }
}
{'fraction_non_alphanumeric': 0.10558414331999237, 'fraction_numerical': 0.01905850962454736, 'mean_word_length': 4.410309278350516, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6821769', 'n_tokens_mistral': 1675, 'n_tokens_neox': 1559, 'n_words': 285}