@@ -0,0 +1,3578 @@
+package uk.ac.ebi.spot.goci.curation.service;%0A%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.Matchers;%0Aimport org.mockito.Mock;%0Aimport org.mockito.runners.MockitoJUnitRunner;%0Aimport org.springframework.mock.web.MockMultipartFile;%0Aimport uk.ac.ebi.spot.goci.curation.builder.SecureUserBuilder;%0Aimport uk.ac.ebi.spot.goci.curation.builder.StudyBuilder;%0Aimport uk.ac.ebi.spot.goci.curation.exception.FileUploadException;%0Aimport uk.ac.ebi.spot.goci.exception.SheetProcessingException;%0Aimport uk.ac.ebi.spot.goci.model.SecureUser;%0Aimport uk.ac.ebi.spot.goci.model.Study;%0Aimport uk.ac.ebi.spot.goci.service.AssociationFileUploadService;%0A%0Aimport java.io.File;%0Aimport java.io.FileNotFoundException;%0Aimport java.io.IOException;%0A%0Aimport static org.mockito.Mockito.doThrow;%0Aimport static org.mockito.Mockito.when;%0A%0A/**%0A * Created by emma on 16/06/2016.%0A *%0A * @author emma%0A */%0A@RunWith(MockitoJUnitRunner.class)%0Apublic class AssociationUploadServiceTest %7B%0A%0A    @Mock%0A    private StudyFileService studyFileService;%0A%0A    @Mock%0A    private AssociationFileUploadService associationFileUploadService;%0A%0A    @Mock%0A    private AssociationOperationsService associationOperationsService;%0A%0A%0A    private AssociationUploadService associationUploadService;%0A%0A    private static final SecureUser SECURE_USER =%0A            new SecureUserBuilder().setId(564L).setEmail(%22test@test.com%22).setPasswordHash(%22738274$$%22).build();%0A%0A    private static final Study STUDY = new StudyBuilder().setId(100L).build();%0A%0A    @Before%0A    public void setUp() throws Exception %7B%0A        associationUploadService = new AssociationUploadService(studyFileService,%0A                                                                associationFileUploadService,%0A                                                                associationOperationsService);%0A    %7D%0A%0A    @Test(expected = FileUploadException.class)%0A    public void uploadBlankFile() throws Exception %7B%0A        MockMultipartFile blankFile =%0A                new MockMultipartFile(%22data%22, %22filename.txt%22, %22text/plain%22, %22%22.getBytes());%0A        doThrow(new FileUploadException()).when(studyFileService).upload(blankFile, STUDY.getId());%0A        associationUploadService.upload(blankFile, STUDY, SECURE_USER);%0A    %7D%0A%0A    @Test(expected = SheetProcessingException.class)%0A    public void uploadIncorrectlyFormattedFile() throws Exception %7B%0A        MockMultipartFile incorrectlyFormattedFile =%0A                new MockMultipartFile(%22data%22, %22filename.txt%22, %22text/plain%22, %22Not an Excel file%22.getBytes());%0A        File file = new File(incorrectlyFormattedFile.getOriginalFilename());%0A%0A        // Stubbing%0A        when(studyFileService.getFileFromFileName(STUDY.getId(),%0A                                                  incorrectlyFormattedFile.getOriginalFilename())).thenReturn(file);%0A        when(associationFileUploadService.processAssociationFile(file,%0A                                                                 %22full%22)).thenThrow(new SheetProcessingException());%0A        associationUploadService.upload(incorrectlyFormattedFile, STUDY, SECURE_USER);%0A    %7D%0A%0A%0A    @Test(expected = IOException.class)%0A    public void uploadMissingFile() throws Exception %7B%0A%0A        MockMultipartFile file =%0A                new MockMultipartFile(%22data%22, %22filename.txt%22, %22text/plain%22, %22Blank file%22.getBytes());%0A%0A        // Stubbing%0A        when(studyFileService.getFileFromFileName(STUDY.getId(), file.getOriginalFilename())).thenThrow(new FileNotFoundException());%0A        associationUploadService.upload(file, STUDY, SECURE_USER);%0A    %7D%0A%7D

Add exception testing