Skip to content

Commit

Permalink
MET-5622 Added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanaCMS committed Nov 24, 2023
1 parent da3254c commit d4e7d8d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package eu.europeana.metis.sandbox.service.dataset;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.times;

import eu.europeana.metis.sandbox.common.exception.ServiceException;
import eu.europeana.metis.sandbox.common.locale.Country;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
import java.util.Optional;


import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.when;

@ExtendWith(SpringExtension.class)
Expand Down Expand Up @@ -121,4 +125,29 @@ void createDatasetHarvestingParameters_expectFail(){

}

@Test
void getDatasetHarvestingParameters_expectSuccess(){
DatasetEntity datasetEntity = new DatasetEntity();
datasetEntity.setDatasetId(1);
HarvestingParameterEntity entity = new HarvestingParameterEntity(datasetEntity, HarvestProtocol.FILE,
"fileName", "fileType", null, null, null);
when(harvestingParameterRepository.getHarvestingParametersEntitiesByDatasetId_DatasetId(1)).thenReturn(entity);

HarvestingParameterEntity resultEntity = harvestingParameterService.getDatasetHarvestingParameters("1");

assertEquals(entity, resultEntity);
}

@Test
void remove_expectSuccess(){
harvestingParameterService.remove("1");
verify(harvestingParameterRepository).deleteByDatasetId_DatasetId(1);
}

@Test
void remove_expectFail(){
doThrow(new RuntimeException("error")).when(harvestingParameterRepository).deleteByDatasetId_DatasetId(1);
assertThrows(ServiceException.class, () -> harvestingParameterService.remove("1"));
}

}

0 comments on commit d4e7d8d

Please sign in to comment.