Skip to content
Snippets Groups Projects
Commit ac15cd7c authored by Aalekh Jain's avatar Aalekh Jain
Browse files

Added UTs for `update` method in `LegalTagRepositoryImpl.java`

parent b385fbf0
No related branches found
No related tags found
1 merge request!61Improve code coverage
Pipeline #9593 failed
...@@ -22,6 +22,7 @@ import org.mockito.InjectMocks; ...@@ -22,6 +22,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.azure.CosmosStore; import org.opengroup.osdu.azure.CosmosStore;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.legal.LegalTag; import org.opengroup.osdu.core.common.model.legal.LegalTag;
...@@ -29,6 +30,7 @@ import java.util.List; ...@@ -29,6 +30,7 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
...@@ -100,6 +102,35 @@ public class LegalTagRepositoryImplTest { ...@@ -100,6 +102,35 @@ public class LegalTagRepositoryImplTest {
assertEquals(arg2.getValue(), strId); assertEquals(arg2.getValue(), strId);
} }
@Test
public void testUpdateLegalTag_whenProvidedLegalTagIsNull() {
LegalTag legalTag = sut.update(null);
assertNull(legalTag);
}
@Test(expected = AppException.class)
public void testUpdateLegalTag_whenValidItemDoesNotExist_throwsException() {
long id = 0;
LegalTag legalTag = getLegalTagWithId(id);
sut.update(legalTag);
}
@Test
public void testUpdateLegalTag_whenValidItemExists() {
long id = 0;
String strId = String.valueOf(id);
LegalTag legalTag = getLegalTagWithId(id);
Optional<LegalTag> optionalLegalTag = Optional.of(legalTag);
doReturn(optionalLegalTag).when(cosmosStore).findItem(eq(dataPartitionId), any(), any(), eq(strId), eq(strId), any());
LegalTag obtainedLegalTag = sut.update(legalTag);
ArgumentCaptor<LegalTagDoc> arg = ArgumentCaptor.forClass(LegalTagDoc.class);
verify(cosmosStore).upsertItem(anyString(), any(), any(), arg.capture());
assertEquals(arg.getValue().getId(), strId);
assertEquals(obtainedLegalTag.getId().longValue(), id);
}
private LegalTag getLegalTagWithId(long id) { private LegalTag getLegalTagWithId(long id) {
LegalTag legalTag = new LegalTag(); LegalTag legalTag = new LegalTag();
legalTag.setId(id); legalTag.setId(id);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment