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

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

parent 016c7212
No related branches found
No related tags found
1 merge request!61Improve code coverage
Pipeline #9579 failed
......@@ -15,6 +15,7 @@
package org.opengroup.osdu.legal.azure.tags.dataaccess;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
......@@ -22,7 +23,12 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.azure.CosmosStore;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.legal.LegalTag;
import java.util.List;
import java.util.Optional;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class)
......@@ -43,4 +49,34 @@ public class LegalTagRepositoryImplTest {
public void init() {
lenient().doReturn(dataPartitionId).when(headers).getPartitionId();
}
@Test
public void testGetLegalTagCollections_whenIdsIsNull() {
long[] ids = null;
List<LegalTag> output = (List<LegalTag>) sut.get(ids);
assertEquals(output.size(),0);
}
@Test
public void testGetLegalTagCollections_whenIdsIsNotNull() {
long[] ids = {0, 1};
String[] strIds = {"0", "1"};
Optional[] legalTagDocs = new Optional[2];
legalTagDocs[0] = Optional.of(new LegalTagDoc(strIds[0], getLegalTagWithId(ids[0])));
legalTagDocs[1] = Optional.of(new LegalTagDoc(strIds[0], getLegalTagWithId(ids[1])));
doReturn(legalTagDocs[0]).when(cosmosStore).findItem(eq(dataPartitionId), any(), any(), eq(strIds[0]), eq(strIds[0]), any());
doReturn(legalTagDocs[1]).when(cosmosStore).findItem(eq(dataPartitionId), any(), any(), eq(strIds[1]), eq(strIds[1]), any());
List<LegalTag> output = (List<LegalTag>) sut.get(ids);
assertEquals(output.size(),2);
assertEquals(output.get(0).getId().longValue(), ids[0]);
assertEquals(output.get(1).getId().longValue(), ids[1]);
}
private LegalTag getLegalTagWithId(long id) {
LegalTag legalTag = new LegalTag();
legalTag.setId(id);
return legalTag;
}
}
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