<commit_before>package uk.ac.ebi.spot.goci.curation.service.tracking;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import uk.ac.ebi.spot.goci.curation.builder.EventBuilder;
import uk.ac.ebi.spot.goci.curation.builder.SecureUserBuilder;
import uk.ac.ebi.spot.goci.curation.builder.StudyBuilder;
import uk.ac.ebi.spot.goci.curation.service.EventOperationsService;
import uk.ac.ebi.spot.goci.model.Event;
import uk.ac.ebi.spot.goci.model.EventType;
import uk.ac.ebi.spot.goci.model.SecureUser;
import uk.ac.ebi.spot.goci.model.Study;

import java.util.Date;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
 * Created by emma on 24/05/2016.
 *
 * @author emma
 */
@RunWith(MockitoJUnitRunner.class)
public class StudyTrackingOperationServiceImplTest {


    private StudyTrackingOperationServiceImpl studyTrackingOperationService;

    @Mock
    private EventOperationsService eventOperationsService;

    private static final SecureUser SECURE_USER =
            new SecureUserBuilder().setId(564L).setEmail("<EMAIL>").setPasswordHash("<PASSWORD>$$").build();

    private static final Study STUDY = new StudyBuilder().setId(100L).build();

    private static final Event CREATE_EVENT = new EventBuilder().setId(99L).setEventDate(new Date()).setUser(SECURE_USER).setEventType(EventType.STUDY_CREATION).build();

    private static final Event STATUS_EVENT = new EventBuilder().setId(98L).setEventDate(new Date()).setUser(SECURE_USER).setEventType(EventType.STUDY_STATUS_CHANGE_LEVEL_1_CURATION_DONE).build();

    private static final Event UPDATE_EVENT = new EventBuilder().setId(97L).setEventDate(new Date()).setUser(SECURE_USER).setEventType(EventType.STUDY_UPDATE).build();

    @Before
    public void setUp() throws Exception {
        studyTrackingOperationService = new StudyTrackingOperationServiceImpl(eventOperationsService);
    }

    @Test
    public void create() throws Exception {
        when(eventOperationsService.createEvent(EventType.STUDY_CREATION, SECURE_USER)).thenReturn(CREATE_EVENT);
        studyTrackingOperationService.create(STUDY, SECURE_USER);
        verify(eventOperationsService, times(1)).createEvent(EventType.STUDY_CREATION, SECURE_USER);
        assertThat(STUDY.getEvents()).hasSize(1);
        assertThat(STUDY.getEvents()).extracting(event->event.getUser().getEmail()).contains("<EMAIL>");
        assertThat(STUDY.getEvents()).extracting(event->event.getEventType()).contains(EventType.STUDY_CREATION);
        assertThat(STUDY.getEvents()).extracting(event->event.getEventDate()).isNotNull();
    }

    @Test
    public void update() throws Exception {
        when(eventOperationsService.createEvent(EventType.STUDY_STATUS_CHANGE_LEVEL_1_CURATION_DONE, SECURE_USER)).thenReturn(STATUS_EVENT);
        when(eventOperationsService.createEvent(EventType.STUDY_UPDATE, SECURE_USER)).thenReturn(UPDATE_EVENT);

        studyTrackingOperationService.update(STUDY, SECURE_USER,EventType.STUDY_STATUS_CHANGE_LEVEL_1_CURATION_DONE);
        studyTrackingOperationService.update(STUDY, SECURE_USER,EventType.STUDY_UPDATE);

        verify(eventOperationsService, times(1)).createEvent(EventType.STUDY_STATUS_CHANGE_LEVEL_1_CURATION_DONE, SECURE_USER);
        verify(eventOperationsService, times(1)).createEvent(EventType.STUDY_UPDATE, SECURE_USER);

        assertThat(STUDY.getEvents()).hasSize(2);
        assertThat(STUDY.getEvents()).extracting(event->event.getUser().getEmail()).containsOnly("<EMAIL>");
        assertThat(STUDY.getEvents()).extracting(event->event.getEventType()).containsOnly(EventType.STUDY_STATUS_CHANGE_LEVEL_1_CURATION_DONE, EventType.STUDY_UPDATE);
        assertThat(STUDY.getEvents()).extracting(event->event.getEventDate()).isNotNull();
    }

    @Test
    public void delete() throws Exception {

    }

}<commit_msg>Fix to update method so it checks for study creation event<commit_after>package uk.ac.ebi.spot.goci.curation.service.tracking;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import uk.ac.ebi.spot.goci.curation.builder.EventBuilder;
import uk.ac.ebi.spot.goci.curation.builder.SecureUserBuilder;
import uk.ac.ebi.spot.goci.curation.builder.StudyBuilder;
import uk.ac.ebi.spot.goci.curation.service.EventOperationsService;
import uk.ac.ebi.spot.goci.model.Event;
import uk.ac.ebi.spot.goci.model.EventType;
import uk.ac.ebi.spot.goci.model.SecureUser;
import uk.ac.ebi.spot.goci.model.Study;

import java.util.Date;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
 * Created by emma on 24/05/2016.
 *
 * @author emma
 */
@RunWith(MockitoJUnitRunner.class)
public class StudyTrackingOperationServiceImplTest {


    private StudyTrackingOperationServiceImpl studyTrackingOperationService;

    @Mock
    private EventOperationsService eventOperationsService;

    private static final SecureUser SECURE_USER =
            new SecureUserBuilder().setId(564L).setEmail("<EMAIL>").setPasswordHash("<PASSWORD>$$").build();

    private static final Study STUDY = new StudyBuilder().setId(100L).build();

    private static final Event CREATE_EVENT = new EventBuilder().setId(99L).setEventDate(new Date()).setUser(SECURE_USER).setEventType(EventType.STUDY_CREATION).build();

    private static final Event STATUS_EVENT = new EventBuilder().setId(98L).setEventDate(new Date()).setUser(SECURE_USER).setEventType(EventType.STUDY_STATUS_CHANGE_LEVEL_1_CURATION_DONE).build();

    private static final Event UPDATE_EVENT = new EventBuilder().setId(97L).setEventDate(new Date()).setUser(SECURE_USER).setEventType(EventType.STUDY_UPDATE).build();

    @Before
    public void setUp() throws Exception {
        studyTrackingOperationService = new StudyTrackingOperationServiceImpl(eventOperationsService);
    }

    @Test
    public void create() throws Exception {
        when(eventOperationsService.createEvent(EventType.STUDY_CREATION, SECURE_USER)).thenReturn(CREATE_EVENT);
        studyTrackingOperationService.create(STUDY, SECURE_USER);
        verify(eventOperationsService, times(1)).createEvent(EventType.STUDY_CREATION, SECURE_USER);
        assertThat(STUDY.getEvents()).hasSize(1);
        assertThat(STUDY.getEvents()).extracting(event->event.getUser().getEmail()).contains("<EMAIL>");
        assertThat(STUDY.getEvents()).extracting(event->event.getEventType()).contains(EventType.STUDY_CREATION);
        assertThat(STUDY.getEvents()).extracting(event->event.getEventDate()).isNotNull();
    }

    @Test
    public void update() throws Exception {
        when(eventOperationsService.createEvent(EventType.STUDY_STATUS_CHANGE_LEVEL_1_CURATION_DONE, SECURE_USER)).thenReturn(STATUS_EVENT);
        when(eventOperationsService.createEvent(EventType.STUDY_UPDATE, SECURE_USER)).thenReturn(UPDATE_EVENT);

        studyTrackingOperationService.update(STUDY, SECURE_USER,EventType.STUDY_STATUS_CHANGE_LEVEL_1_CURATION_DONE);
        studyTrackingOperationService.update(STUDY, SECURE_USER,EventType.STUDY_UPDATE);

        verify(eventOperationsService, times(1)).createEvent(EventType.STUDY_STATUS_CHANGE_LEVEL_1_CURATION_DONE, SECURE_USER);
        verify(eventOperationsService, times(1)).createEvent(EventType.STUDY_UPDATE, SECURE_USER);

        assertThat(STUDY.getEvents()).hasSize(3);
        assertThat(STUDY.getEvents()).extracting(event->event.getUser().getEmail()).containsOnly("<EMAIL>");
        assertThat(STUDY.getEvents()).extracting(event->event.getEventType()).containsOnly(EventType.STUDY_CREATION,EventType.STUDY_STATUS_CHANGE_LEVEL_1_CURATION_DONE, EventType.STUDY_UPDATE);
        assertThat(STUDY.getEvents()).extracting(event->event.getEventDate()).isNotNull();
    }

    @Test
    public void delete() throws Exception {

    }

}
{'fraction_non_alphanumeric': 0.11790714812085483, 'fraction_numerical': 0.007369196757553427, 'mean_word_length': 5.5881877022653725, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, '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': '4946641', 'n_tokens_mistral': 2573, 'n_tokens_neox': 2543, 'n_words': 320}