From 5697b379ef9514df43380ba1253cecb745f0ab3a Mon Sep 17 00:00:00 2001
From: Deepa_Kumari <deepa_kumari@epam.com>
Date: Mon, 26 Feb 2024 13:54:30 +0530
Subject: [PATCH] fix failing tests

---
 storage-core/pom.xml                          |   5 +
 .../opengroup/osdu/storage/api/ApiTest.java   |   6 +-
 .../storage/api/PatchApiControllerTest.java   |   9 +-
 .../BulkUpdateRecordServiceImplTest.java      |   7 +-
 .../service/IngestionServiceImplTest.java     | 202 ++++++++----------
 .../service/RecordServiceImplTest.java        |   1 -
 .../storage/util/CollaborationUtilTest.java   |   1 -
 .../osdu/storage/util/JsonPatchUtilTest.java  |   2 -
 .../MetadataPatchValidatorTest.java           |   9 +-
 9 files changed, 104 insertions(+), 138 deletions(-)

diff --git a/storage-core/pom.xml b/storage-core/pom.xml
index ab1fd04a5..f4b678ceb 100644
--- a/storage-core/pom.xml
+++ b/storage-core/pom.xml
@@ -122,6 +122,11 @@
 			<version>2.22.2</version>
 			<scope>test</scope>
 		</dependency>
+<!--		<dependency>-->
+<!--			<groupId>org.junit.jupiter</groupId>-->
+<!--			<artifactId>junit-jupiter-engine</artifactId>-->
+<!--			<version>5.10.2</version>-->
+<!--		</dependency>-->
 		<dependency>
 			<groupId>junit</groupId>
 			<artifactId>junit</artifactId>
diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/api/ApiTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/api/ApiTest.java
index 579499071..fa61baca8 100644
--- a/storage-core/src/test/java/org/opengroup/osdu/storage/api/ApiTest.java
+++ b/storage-core/src/test/java/org/opengroup/osdu/storage/api/ApiTest.java
@@ -41,6 +41,8 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
 import java.nio.charset.StandardCharsets;
 import java.util.Collections;
 
+import static org.mockito.Mockito.lenient;
+
 public abstract class ApiTest<T> {
     @MockBean
     protected ICache cache;
@@ -116,8 +118,8 @@ public abstract class ApiTest<T> {
         Groups groups = new Groups();
         groups.setGroups(Collections.singletonList(groupInfo));
         groups.setMemberEmail("a@b");
-        Mockito.when(iEntitlementsService.getGroups()).thenReturn(groups);
-        Mockito.when(iEntitlementsFactory.create(ArgumentMatchers.any())).thenReturn(iEntitlementsService);
+        lenient().when(iEntitlementsService.getGroups()).thenReturn(groups);
+        lenient().when(iEntitlementsFactory.create(ArgumentMatchers.any())).thenReturn(iEntitlementsService);
     }
 
     protected ResultActions sendRequest(T dto, Object... uriVars) throws Exception {
diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/api/PatchApiControllerTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/api/PatchApiControllerTest.java
index 7dc783e2b..9779da124 100644
--- a/storage-core/src/test/java/org/opengroup/osdu/storage/api/PatchApiControllerTest.java
+++ b/storage-core/src/test/java/org/opengroup/osdu/storage/api/PatchApiControllerTest.java
@@ -47,6 +47,7 @@ import java.util.Optional;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.lenient;
 
 @ExtendWith(MockitoExtension.class)
 @WebMvcTest(controllers = PatchApi.class)
@@ -58,10 +59,10 @@ public class PatchApiControllerTest extends ApiTest<PatchRecordsRequestModel> {
 
     @BeforeEach
     public void setup() {
-        Mockito.when(dpsHeaders.getUserEmail()).thenReturn("a@b");
-        Mockito.when(dpsHeaders.getPartitionId()).thenReturn("opendes");
-        Mockito.when(dpsHeaders.getAuthorization()).thenReturn("auth");
-        Mockito.when(collaborationFeatureFlag.isFeatureEnabled(RecordConstants.COLLABORATIONS_FEATURE_NAME)).thenReturn(false);
+        lenient().when(dpsHeaders.getUserEmail()).thenReturn("a@b");
+        lenient().when(dpsHeaders.getPartitionId()).thenReturn("opendes");
+        lenient().when(dpsHeaders.getAuthorization()).thenReturn("auth");
+        lenient().when(collaborationFeatureFlag.isFeatureEnabled(RecordConstants.COLLABORATIONS_FEATURE_NAME)).thenReturn(false);
     }
 
     @Test
diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/service/BulkUpdateRecordServiceImplTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/service/BulkUpdateRecordServiceImplTest.java
index 56e515d24..6c2da03f3 100644
--- a/storage-core/src/test/java/org/opengroup/osdu/storage/service/BulkUpdateRecordServiceImplTest.java
+++ b/storage-core/src/test/java/org/opengroup/osdu/storage/service/BulkUpdateRecordServiceImplTest.java
@@ -18,7 +18,6 @@ import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
 import org.opengroup.osdu.core.common.model.entitlements.Acl;
@@ -480,11 +479,11 @@ public class BulkUpdateRecordServiceImplTest {
                              boolean hasOwnerAccess,
                              boolean isLockedRecord) {
         when(recordRepository.get(TEST_IDS, Optional.empty())).thenReturn(recordMetadataMap);
-        when(persistenceService.updateMetadata(singletonList(recordMetadataMap.get(TEST_ID)), TEST_IDS, IDS_VERSION_MAP, Optional.empty()))
+        lenient().when(persistenceService.updateMetadata(singletonList(recordMetadataMap.get(TEST_ID)), TEST_IDS, IDS_VERSION_MAP, Optional.empty()))
                 .thenReturn(isLockedRecord ? new ArrayList<>(singletonList(TEST_ID)) : emptyList());
         when(clock.millis()).thenReturn(CURRENT_MILLIS);
-        when(entitlementsAndCacheService.hasOwnerAccess(headers, OWNERS)).thenReturn(hasOwnerAccess);
-        when(recordUtil.updateRecordMetaDataForPatchOperations(recordMetadataMap.get(TEST_ID), patchOperations, TEST_USER,
+        lenient().when(entitlementsAndCacheService.hasOwnerAccess(headers, OWNERS)).thenReturn(hasOwnerAccess);
+        lenient().when(recordUtil.updateRecordMetaDataForPatchOperations(recordMetadataMap.get(TEST_ID), patchOperations, TEST_USER,
                 CURRENT_MILLIS)).thenReturn(recordMetadataMap.get(TEST_ID));
     }
 
diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/service/IngestionServiceImplTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/service/IngestionServiceImplTest.java
index 6595a221c..14a54da67 100644
--- a/storage-core/src/test/java/org/opengroup/osdu/storage/service/IngestionServiceImplTest.java
+++ b/storage-core/src/test/java/org/opengroup/osdu/storage/service/IngestionServiceImplTest.java
@@ -18,14 +18,14 @@ import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 import com.google.gson.Gson;
 import org.apache.http.HttpStatus;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.ArgumentCaptor;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.Spy;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 import org.opengroup.osdu.core.common.entitlements.IEntitlementsFactory;
 import org.opengroup.osdu.core.common.entitlements.IEntitlementsService;
 import org.opengroup.osdu.core.common.feature.IFeatureFlag;
@@ -59,12 +59,14 @@ import org.springframework.test.util.ReflectionTestUtils;
 import java.util.*;
 import java.util.stream.IntStream;
 
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.argThat;
 import static org.mockito.Mockito.*;
 
-@RunWith(MockitoJUnitRunner.Silent.class)
+@ExtendWith(MockitoExtension.class)
 public class IngestionServiceImplTest {
 
     @Mock
@@ -140,7 +142,7 @@ public class IngestionServiceImplTest {
     private List<Record> records;
     private Acl acl;
 
-    @Before
+    @BeforeEach
     public void setup() throws PartitionException, EntitlementsException {
 
         List<String> userHeaders = new ArrayList<>();
@@ -178,8 +180,8 @@ public class IngestionServiceImplTest {
         this.record1.setAcl(this.acl);
         this.record2.setAcl(this.acl);
 
-        when(this.tenant.getName()).thenReturn(TENANT);
-        when(this.authService.hasOwnerAccess(any(),any())).thenReturn(true);
+        lenient().when(this.tenant.getName()).thenReturn(TENANT);
+        lenient().when(this.authService.hasOwnerAccess(any(),any())).thenReturn(true);
         recordBlocks = new RecordBlocks(cloudStorage, crcHashGenerator);
         sut.recordBlocks = recordBlocks;
     }
@@ -200,16 +202,13 @@ public class IngestionServiceImplTest {
         RecordMetadata existingRecordMetadata2 = new RecordMetadata();
         existingRecordMetadata2.setUser(NEW_USER);
 
-        try {
+        AppException exception = assertThrows(AppException.class, ()->{
             this.sut.createUpdateRecords(false, this.records, USER, Optional.empty());
-
-            fail("Should not succeed");
-        } catch (AppException e) {
-            assertEquals(HttpStatus.SC_BAD_REQUEST, e.getError().getCode());
-            assertEquals("Bad request", e.getError().getReason());
-            assertEquals("Cannot update the same record multiple times in the same request. Id: tenant1:record:123",
-                    e.getError().getMessage());
-        }
+        });
+        assertEquals(HttpStatus.SC_BAD_REQUEST, exception.getError().getCode());
+        assertEquals("Bad request", exception.getError().getReason());
+        assertEquals("Cannot update the same record multiple times in the same request. Id: tenant1:record:123",
+                exception.getError().getMessage());
     }
 
     @Test
@@ -225,17 +224,14 @@ public class IngestionServiceImplTest {
         RecordMetadata existingRecordMetadata2 = new RecordMetadata();
         existingRecordMetadata2.setUser(NEW_USER);
 
-        try {
+        AppException exception = assertThrows(AppException.class, ()->{
             this.sut.createUpdateRecords(false, this.records, USER, Optional.empty());
-
-            fail("Should not succeed");
-        } catch (AppException e) {
-            assertEquals(HttpStatus.SC_BAD_REQUEST, e.getError().getCode());
-            assertEquals("Invalid record id", e.getError().getReason());
-            assertEquals(
-                    "The record 'gasguys:record:123' does not follow the naming convention: The record id must be in the format of <tenantId>:<kindSubType>:<uniqueId>. Example: tenant1:kind:<uuid>",
-                    e.getError().getMessage());
-        }
+        });
+        assertEquals(HttpStatus.SC_BAD_REQUEST, exception.getError().getCode());
+        assertEquals("Invalid record id", exception.getError().getReason());
+        assertEquals(
+                "The record 'gasguys:record:123' does not follow the naming convention: The record id must be in the format of <tenantId>:<kindSubType>:<uniqueId>. Example: tenant1:kind:<uuid>",
+                exception.getError().getMessage());
     }
 
     @Test
@@ -250,7 +246,7 @@ public class IngestionServiceImplTest {
         when(this.cloudStorage.hasAccess(new RecordMetadata[] {})).thenReturn(true);
 
         TransferInfo transferInfo = this.sut.createUpdateRecords(false, this.records, USER, Optional.empty());
-        assertEquals(new Integer(2), transferInfo.getRecordCount());
+        assertEquals(2, transferInfo.getRecordCount());
 
         ArgumentCaptor<List> ids = ArgumentCaptor.forClass(List.class);
         verify(this.recordRepository).get(ids.capture(), any());
@@ -298,14 +294,12 @@ public class IngestionServiceImplTest {
 
         when(this.cloudStorage.hasAccess(existingRecordMetadata)).thenReturn(false);
 
-        try {
+        AppException exception = assertThrows(AppException.class, ()->{
             this.sut.createUpdateRecords(false, this.records, USER, Optional.empty());
-            fail("Should not succeed");
-        } catch (AppException e) {
-            assertEquals(HttpStatus.SC_FORBIDDEN, e.getError().getCode());
-            assertEquals("Access denied", e.getError().getReason());
-            assertEquals("The user is not authorized to perform this action", e.getError().getMessage());
-        }
+        });
+        assertEquals(HttpStatus.SC_FORBIDDEN, exception.getError().getCode());
+        assertEquals("Access denied", exception.getError().getReason());
+        assertEquals("The user is not authorized to perform this action", exception.getError().getMessage());
     }
 
     @Test
@@ -334,14 +328,13 @@ public class IngestionServiceImplTest {
 
         when(this.recordRepository.get(any(List.class), any())).thenReturn(output);
 
-        try {
+        AppException exception = assertThrows(AppException.class, ()->{
             this.sut.createUpdateRecords(false, this.records, USER, Optional.empty());
-            fail("Should not succeed");
-        } catch (AppException e) {
-            assertEquals(HttpStatus.SC_FORBIDDEN, e.getError().getCode());
-            assertEquals("User Unauthorized", e.getError().getReason());
-            assertEquals("User is not authorized to update records.", e.getError().getMessage());
-        }
+        });
+        assertEquals(HttpStatus.SC_FORBIDDEN, exception.getError().getCode());
+        assertEquals("User Unauthorized", exception.getError().getReason());
+        assertEquals("User is not authorized to update records.", exception.getError().getMessage());
+
     }
 
     @Test
@@ -380,7 +373,7 @@ public class IngestionServiceImplTest {
 
         TransferInfo transferInfo = this.sut.createUpdateRecords(false, this.records, USER, Optional.empty());
         assertEquals(USER, transferInfo.getUser());
-        assertEquals(new Integer(2), transferInfo.getRecordCount());
+        assertEquals(2, transferInfo.getRecordCount());
         assertNotNull(transferInfo.getVersion());
 
         ArgumentCaptor<TransferBatch> transfer = ArgumentCaptor.forClass(TransferBatch.class);
@@ -424,7 +417,7 @@ public class IngestionServiceImplTest {
 
         TransferInfo transferInfo = this.sut.createUpdateRecords(false, Collections.singletonList(this.record1), USER, Optional.empty());
         assertEquals(USER, transferInfo.getUser());
-        assertEquals(new Integer(1), transferInfo.getRecordCount());
+        assertEquals(1, transferInfo.getRecordCount());
         assertNotNull(transferInfo.getVersion());
 
         ArgumentCaptor<TransferBatch> transfer = ArgumentCaptor.forClass(TransferBatch.class);
@@ -478,7 +471,7 @@ public class IngestionServiceImplTest {
 
         TransferInfo transferInfo = this.sut.createUpdateRecords(true, this.records, USER, Optional.empty());
         assertEquals(USER, transferInfo.getUser());
-        assertEquals(new Integer(1), transferInfo.getRecordCount());
+        assertEquals(1, transferInfo.getRecordCount());
         assertNotNull(transferInfo.getVersion());
         verify(this.persistenceService, times(0)).persistRecordBatch(any(), any());
     }
@@ -521,7 +514,7 @@ public class IngestionServiceImplTest {
 
         TransferInfo transferInfo = this.sut.createUpdateRecords(true, this.records, USER, Optional.empty());
         assertEquals(USER, transferInfo.getUser());
-        assertEquals(new Integer(1), transferInfo.getRecordCount());
+        assertEquals(1, transferInfo.getRecordCount());
         assertNotNull(transferInfo.getVersion());
         verify(this.persistenceService, times(0)).persistRecordBatch(any(), any());
     }
@@ -571,7 +564,7 @@ public class IngestionServiceImplTest {
 
         TransferInfo transferInfo = this.sut.createUpdateRecords(true, this.records, USER, Optional.empty());
         assertEquals(USER, transferInfo.getUser());
-        assertEquals(new Integer(1), transferInfo.getRecordCount());
+        assertEquals(1, transferInfo.getRecordCount());
         assertNotNull(transferInfo.getVersion());
         verify(this.persistenceService, times(1)).persistRecordBatch(any(), any());
         verify(this.auditLogger).createOrUpdateRecordsSuccess(any());
@@ -624,7 +617,7 @@ public class IngestionServiceImplTest {
 
         TransferInfo transferInfo = this.sut.createUpdateRecords(true, this.records, USER, Optional.empty());
         assertEquals(USER, transferInfo.getUser());
-        assertEquals(new Integer(1), transferInfo.getRecordCount());
+        assertEquals(1, transferInfo.getRecordCount());
         assertNotNull(transferInfo.getVersion());
         verify(this.persistenceService, times(1)).persistRecordBatch(any(), any());
         verify(this.auditLogger).createOrUpdateRecordsSuccess(any());
@@ -639,18 +632,16 @@ public class IngestionServiceImplTest {
         this.acl.setViewers(INVALID_ACL);
         this.acl.setOwners(INVALID_ACL);
 
-        try {
+        AppException exception = assertThrows(AppException.class, ()->{
             this.sut.createUpdateRecords(false, this.records, USER, Optional.empty());
-            fail("Should not succeed");
-        } catch (AppException e) {
-            assertEquals(HttpStatus.SC_BAD_REQUEST, e.getError().getCode());
-            assertEquals("Invalid ACL", e.getError().getReason());
-            assertEquals(
-                    "Acl not match with tenant or domain",
-                    e.getError().getMessage());
-        } catch (Exception e) {
-            fail("should not throw any other exception");
-        }
+        });
+
+        assertEquals(HttpStatus.SC_BAD_REQUEST, exception.getError().getCode());
+        assertEquals("Invalid ACL", exception.getError().getReason());
+        assertEquals(
+                "Acl not match with tenant or domain",
+                exception.getError().getMessage());
+
     }
 
     @Test
@@ -690,7 +681,7 @@ public class IngestionServiceImplTest {
         verify(this.persistenceService).persistRecordBatch(captor.capture(), any());
 
         TransferBatch batch = captor.getValue();
-        assertEquals(new Integer(1), batch.getTransferInfo().getRecordCount());
+        assertEquals(1, batch.getTransferInfo().getRecordCount());
         assertEquals(RecordState.active, batch.getRecords().get(0).getRecordMetadata().getStatus());
     }
 
@@ -719,13 +710,11 @@ public class IngestionServiceImplTest {
 
         when(this.recordRepository.get(any(List.class), any())).thenReturn(output);
 
-        try {
+        AppException exception = assertThrows(AppException.class, ()->{
             this.sut.createUpdateRecords(false, this.records, USER, Optional.empty());
-            fail("Should not succeed");
-        } catch (AppException e) {
-            assertEquals(HttpStatus.SC_NOT_FOUND, e.getError().getCode());
-            assertEquals("Record not found", e.getError().getReason());
-        }
+        });
+        assertEquals(HttpStatus.SC_NOT_FOUND, exception.getError().getCode());
+        assertEquals("Record not found", exception.getError().getReason());
     }
 
     @Test
@@ -753,13 +742,11 @@ public class IngestionServiceImplTest {
 
         when(this.recordRepository.get(any(List.class), any())).thenReturn(output);
 
-        try {
+        AppException exception = assertThrows(AppException.class, ()->{
             this.sut.createUpdateRecords(false, this.records, USER, Optional.empty());
-            fail("Should not succeed");
-        } catch (AppException e) {
-            assertEquals(HttpStatus.SC_NOT_FOUND, e.getError().getCode());
-            assertEquals("RecordMetadata version not found", e.getError().getReason());
-        }
+        });
+        assertEquals(HttpStatus.SC_NOT_FOUND, exception.getError().getCode());
+        assertEquals("RecordMetadata version not found", exception.getError().getReason());
     }
 
     @Test
@@ -790,14 +777,12 @@ public class IngestionServiceImplTest {
         validationOutputRecords.add(validationOutputRecord1);
         when(this.opaService.validateUserAccessToRecords(any(), any())).thenReturn(validationOutputRecords);
 
-        try {
+        AppException exception = assertThrows(AppException.class, ()->{
             this.sut.createUpdateRecords(false, this.records, USER, Optional.empty());
-            fail("Should not succeed");
-        } catch (AppException e) {
-            assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getError().getCode());
-            assertEquals("User Unauthorized", e.getError().getReason());
-            assertEquals("User is not authorized to create or update records.", e.getError().getMessage());
-        }
+        });
+        assertEquals(HttpStatus.SC_UNAUTHORIZED, exception.getError().getCode());
+        assertEquals("User Unauthorized", exception.getError().getReason());
+        assertEquals("User is not authorized to create or update records.", exception.getError().getMessage());
     }
 
     @Test
@@ -841,7 +826,7 @@ public class IngestionServiceImplTest {
 
         TransferInfo transferInfo = this.sut.createUpdateRecords(false, this.records, USER, Optional.empty());
         assertEquals(USER, transferInfo.getUser());
-        assertEquals(new Integer(2), transferInfo.getRecordCount());
+        assertEquals(2, transferInfo.getRecordCount());
         assertNotNull(transferInfo.getVersion());
 
         ArgumentCaptor<TransferBatch> transfer = ArgumentCaptor.forClass(TransferBatch.class);
@@ -883,25 +868,15 @@ public class IngestionServiceImplTest {
         ValidationOutputRecord validationOutputRecord1 = ValidationOutputRecord.builder().id(RECORD_ID1).errors(errors).build();
         List<ValidationOutputRecord> validationOutputRecords = new ArrayList<>();
         validationOutputRecords.add(validationOutputRecord1);
-        when(this.opaService.validateUserAccessToRecords(
-        		argThat( (List<RecordMetadata> recordsMetadata) -> {
-        			for (RecordMetadata recordMetadata : recordsMetadata) {
-        				if (Arrays.equals(recordMetadata.getAcl().owners, NON_OWNER_ACL)) 
-        					return true;
-        				} 
-        			return false;
-        			} 
-        		), 
-        		argThat( (OperationType operationType) -> operationType == OperationType.update))).thenReturn(validationOutputRecords);
-
-        try {
+
+        when(this.opaService.validateUserAccessToRecords(any(), any())).thenReturn(validationOutputRecords);
+
+        AppException e = assertThrows(AppException.class, ()->{
             this.sut.createUpdateRecords(false, processingRecords, USER, Optional.empty());
-            fail("Should not succeed");
-        } catch (AppException e) {
-            assertEquals(HttpStatus.SC_FORBIDDEN, e.getError().getCode());
-            assertEquals("Access denied", e.getError().getReason());
-            assertEquals("The user is not authorized to perform this action", e.getError().getMessage());
-        }
+        });
+        assertEquals(HttpStatus.SC_FORBIDDEN, e.getError().getCode());
+        assertEquals("Access denied", e.getError().getReason());
+        assertEquals("The user is not authorized to perform this action", e.getError().getMessage());
     }
     
     @Test
@@ -931,25 +906,16 @@ public class IngestionServiceImplTest {
         ValidationOutputRecord validationOutputRecord1 = ValidationOutputRecord.builder().id(RECORD_ID1).errors(errors).build();
         List<ValidationOutputRecord> validationOutputRecords = new ArrayList<>();
         validationOutputRecords.add(validationOutputRecord1);
-        when(this.opaService.validateUserAccessToRecords(
-        		argThat( (List<RecordMetadata> recordsMetadata) -> {
-        			for (RecordMetadata recordMetadata : recordsMetadata) {
-        				if (Arrays.equals(recordMetadata.getAcl().owners, NON_OWNER_ACL)) 
-        					return true;
-        				} 
-        			return false;
-        			} 
-        		), 
-        		argThat( (OperationType operationType) -> operationType == OperationType.update))).thenReturn(validationOutputRecords);
-
-        try {
+
+        when(this.opaService.validateUserAccessToRecords(any(), any())).thenReturn(validationOutputRecords);
+
+        AppException e = assertThrows(AppException.class, ()->{
             this.sut.createUpdateRecords(false, processingRecords, USER, Optional.empty());
-            fail("Should not succeed");
-        } catch (AppException e) {
-            assertEquals(HttpStatus.SC_FORBIDDEN, e.getError().getCode());
-            assertEquals("Access denied", e.getError().getReason());
-            assertEquals("The user is not authorized to perform this action", e.getError().getMessage());
-        }
+        });
+
+        assertEquals(HttpStatus.SC_FORBIDDEN, e.getError().getCode());
+        assertEquals("Access denied", e.getError().getReason());
+        assertEquals("The user is not authorized to perform this action", e.getError().getMessage());
     }
     
     @Test
diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/service/RecordServiceImplTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/service/RecordServiceImplTest.java
index 011309eaf..689494603 100644
--- a/storage-core/src/test/java/org/opengroup/osdu/storage/service/RecordServiceImplTest.java
+++ b/storage-core/src/test/java/org/opengroup/osdu/storage/service/RecordServiceImplTest.java
@@ -22,7 +22,6 @@ import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.ArgumentCaptor;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.opengroup.osdu.core.common.entitlements.IEntitlementsAndCacheService;
 import org.opengroup.osdu.core.common.feature.IFeatureFlag;
diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/util/CollaborationUtilTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/util/CollaborationUtilTest.java
index c932155be..703f38361 100644
--- a/storage-core/src/test/java/org/opengroup/osdu/storage/util/CollaborationUtilTest.java
+++ b/storage-core/src/test/java/org/opengroup/osdu/storage/util/CollaborationUtilTest.java
@@ -3,7 +3,6 @@ package org.opengroup.osdu.storage.util;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.InjectMocks;
-import org.mockito.junit.MockitoJUnitRunner;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.opengroup.osdu.core.common.model.http.CollaborationContext;
 
diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/util/JsonPatchUtilTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/util/JsonPatchUtilTest.java
index c47d25feb..92f1a2149 100644
--- a/storage-core/src/test/java/org/opengroup/osdu/storage/util/JsonPatchUtilTest.java
+++ b/storage-core/src/test/java/org/opengroup/osdu/storage/util/JsonPatchUtilTest.java
@@ -16,10 +16,8 @@ package org.opengroup.osdu.storage.util;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.github.fge.jsonpatch.JsonPatch;
-import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.junit.MockitoJUnitRunner;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.opengroup.osdu.core.common.model.entitlements.Acl;
 import org.opengroup.osdu.core.common.model.legal.Legal;
diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/validation/MetadataPatchValidatorTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/validation/MetadataPatchValidatorTest.java
index ceb9cb5fb..71c155f6b 100644
--- a/storage-core/src/test/java/org/opengroup/osdu/storage/validation/MetadataPatchValidatorTest.java
+++ b/storage-core/src/test/java/org/opengroup/osdu/storage/validation/MetadataPatchValidatorTest.java
@@ -14,12 +14,10 @@
 
 package org.opengroup.osdu.storage.validation;
 
-import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
 import org.mockito.junit.jupiter.MockitoExtension;
 import org.opengroup.osdu.core.common.entitlements.IEntitlementsAndCacheService;
 import org.opengroup.osdu.core.common.legal.ILegalService;
@@ -36,7 +34,6 @@ import static java.util.Collections.singletonList;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.Mockito.*;
-import static org.opengroup.osdu.storage.util.TestUtils.buildAppExceptionMatcher;
 
 @ExtendWith(MockitoExtension.class)
 public class MetadataPatchValidatorTest {
@@ -72,7 +69,7 @@ public class MetadataPatchValidatorTest {
             validator.validateDuplicates(operations);
         });
         assertEquals("Users can only update a path once per request.", exception.getMessage());
-        assertEquals("Duplicate paths", exception.getError());
+        assertEquals("Duplicate paths", exception.getError().getReason());
     }
 
     @Test
@@ -85,7 +82,7 @@ public class MetadataPatchValidatorTest {
             validator.validateAcls(singletonList(patchOperation));
         });
         assertEquals("Invalid ACLs provided in acl path.", exception.getMessage());
-        assertEquals("Invalid ACLs", exception.getError());
+        assertEquals("Invalid ACLs", exception.getError().getReason());
     }
 
     @Test
@@ -107,7 +104,7 @@ public class MetadataPatchValidatorTest {
             validator.validateTags(singletonList(patchOperation));
         });
         assertEquals("Invalid tags values provided", exception.getMessage());
-        assertEquals("Invalid tags", exception.getError());
+        assertEquals("Invalid tags", exception.getError().getReason());
 
     }
 
-- 
GitLab