FINERACT-2094: Update to Java 21
modernize locale instantiations (fixes an error found by the modernizer plugin) - use Locale.of() instead of new Locale() use recommended gradle toolchain syntax to specify Java class file format version see https://docs.gradle.org/current/userguide/java_plugin.html#toolchain_and_compatibility mark html5 for later fix (it's the default) use dummy byte arrays to work around mockito exception ``` org.mockito.exceptions.base.MockitoException: Mockito cannot mock this class: class java.nio.ByteBuffer. If you're not sure why you're getting this error, please open an issue on GitHub. Java : 21 JVM vendor name : Ubuntu JVM vendor version : 21.0.6+7-Ubuntu-122.04.1 JVM name : OpenJDK 64-Bit Server VM JVM version : 21.0.6+7-Ubuntu-122.04.1 JVM info : mixed mode, sharing OS name : Linux OS version : 5.15.0-136-generic You are seeing this disclaimer because Mockito is configured to create inlined mocks. You can learn about inline mocks and their limitations under item #39 of the Mockito class javadoc. Underlying exception : org.mockito.exceptions.base.MockitoException: Unsupported settings with this type 'java.nio.ByteBuffer' at app//org.apache.fineract.infrastructure.event.external.jobs.SendAsynchronousEventsTaskletTest.givenBatchSize2WhenEventSendFailsThenExecutionStops(SendAsynchronousEventsTaskletTest.java:170) at java.base@21.0.6/java.lang.reflect.Method.invoke(Method.java:580) at java.base@21.0.6/java.util.ArrayList.forEach(ArrayList.java:1596) at java.base@21.0.6/java.util.ArrayList.forEach(ArrayList.java:1596) Caused by: org.mockito.exceptions.base.MockitoException: Unsupported settings with this type 'java.nio.ByteBuffer' at app//net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:168) at app//net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:399) at app//net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:190) at app//net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:410) ... 4 more ``` see also: https://stackoverflow.com/questions/47046996/java-lang-unsupportedoperationexception-when-mocking-java-nio-bytebuffer-class wrap byte arrays with ByteBuffer fix: ``` /home/adamm/git/apache/fineract/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/jobs/SendAsynchronousEventsTaskletTest.java:148: error: incompatible types: byte[] cannot be converted to ByteBuffer "anidempotencyKey", "aSchema", "dummy".getBytes()); ^ /home/adamm/git/apache/fineract/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/jobs/SendAsynchronousEventsTaskletTest.java:170: error: incompatible types: byte[] cannot be converted to ByteBuffer "anidempotencyKey", "aSchema", "dummy".getBytes()); ^ /home/adamm/git/apache/fineract/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/jobs/SendAsynchronousEventsTaskletTest.java:189: error: incompatible types: byte[] cannot be converted to ByteBuffer "anidempotencyKey", "aSchema", "dummy".getBytes()); ^ /home/adamm/git/apache/fineract/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/jobs/SendAsynchronousEventsTaskletTest.java:210: error: incompatible types: byte[] cannot be converted to ByteBuffer "anidempotencyKey", "aSchema", "dummy".getBytes()); ``` ...and use StandardCharsets with getBytes
This commit is contained in:
committed by
Adam Saghy
parent
60bc3acaf1
commit
9f4f1d4f17
+1
-1
@@ -46,7 +46,7 @@ public class DateSerializer implements JsonSerializer<LocalDate> {
|
||||
public JsonElement serialize(LocalDate src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
DateTimeFormatter formatter;
|
||||
if (StringUtils.isNotEmpty(localeCode)) {
|
||||
formatter = DateTimeFormatter.ofPattern(dateFormat, new Locale(localeCode));
|
||||
formatter = DateTimeFormatter.ofPattern(dateFormat, Locale.of(localeCode));
|
||||
} else {
|
||||
formatter = DateTimeFormatter.ofPattern(dateFormat);
|
||||
}
|
||||
|
||||
+2
-2
@@ -890,7 +890,7 @@ public class LoanAssemblerImpl implements LoanAssembler {
|
||||
loan.setClosedOnDate(withdrawnOn);
|
||||
loan.setClosedBy(currentUser);
|
||||
|
||||
final Locale locale = new Locale(command.locale());
|
||||
final Locale locale = Locale.of(command.locale());
|
||||
final DateTimeFormatter fmt = DateTimeFormatter.ofPattern(command.dateFormat()).withLocale(locale);
|
||||
|
||||
actualChanges.put(Loan.PARAM_STATUS, LoanEnumerations.status(loan.getStatus()));
|
||||
@@ -912,7 +912,7 @@ public class LoanAssemblerImpl implements LoanAssembler {
|
||||
loan.setClosedOnDate(rejectedOn);
|
||||
loan.setClosedBy(currentUser);
|
||||
|
||||
final Locale locale = new Locale(command.locale());
|
||||
final Locale locale = Locale.of(command.locale());
|
||||
final DateTimeFormatter fmt = DateTimeFormatter.ofPattern(command.dateFormat()).withLocale(locale);
|
||||
|
||||
actualChanges.put(Loan.PARAM_STATUS, LoanEnumerations.status(loan.getStatus()));
|
||||
|
||||
+5
-4
@@ -26,6 +26,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
@@ -145,7 +146,7 @@ class SendAsynchronousEventsTaskletTest {
|
||||
createExternalEventView("aType", "aCategory", "aSchema", new byte[0], "aIdempotencyKey", 1L));
|
||||
// Dummy Message
|
||||
MessageV1 dummyMessage = new MessageV1(1L, "aSource", "aType", "nocategory", "aCreateDate", "aBusinessDate", "aTenantId",
|
||||
"anidempotencyKey", "aSchema", Mockito.mock(ByteBuffer.class));
|
||||
"anidempotencyKey", "aSchema", ByteBuffer.wrap("dummy".getBytes(StandardCharsets.UTF_8)));
|
||||
|
||||
when(repository.findByStatusOrderByBusinessDateAscIdAsc(Mockito.any(), Mockito.any())).thenReturn(events);
|
||||
when(messageFactory.createMessage(Mockito.any())).thenReturn(dummyMessage);
|
||||
@@ -167,7 +168,7 @@ class SendAsynchronousEventsTaskletTest {
|
||||
createExternalEventView("aType", "aCategory", "aSchema", new byte[0], "aIdempotencyKey", 1L),
|
||||
createExternalEventView("aType", "aCategory", "aSchema", new byte[0], "aIdempotencyKey", 1L));
|
||||
MessageV1 dummyMessage = new MessageV1(1L, "aSource", "aType", "nocategory", "aCreateDate", "aBusinessDate", "aTenantId",
|
||||
"anidempotencyKey", "aSchema", Mockito.mock(ByteBuffer.class));
|
||||
"anidempotencyKey", "aSchema", ByteBuffer.wrap("dummy".getBytes(StandardCharsets.UTF_8)));
|
||||
when(repository.findByStatusOrderByBusinessDateAscIdAsc(Mockito.any(), Mockito.any())).thenReturn(events);
|
||||
when(messageFactory.createMessage(Mockito.any())).thenReturn(dummyMessage);
|
||||
when(byteBufferConverter.convert(Mockito.any(ByteBuffer.class))).thenReturn(new byte[0]);
|
||||
@@ -186,7 +187,7 @@ class SendAsynchronousEventsTaskletTest {
|
||||
List<ExternalEventView> events = Arrays
|
||||
.asList(createExternalEventView("aType", "aCategory", "aSchema", new byte[0], "aIdempotencyKey", 1L));
|
||||
MessageV1 dummyMessage = new MessageV1(1L, "aSource", "aType", "nocategory", "aCreateDate", "aBusinessDate", "aTenantId",
|
||||
"anidempotencyKey", "aSchema", Mockito.mock(ByteBuffer.class));
|
||||
"anidempotencyKey", "aSchema", ByteBuffer.wrap("dummy".getBytes(StandardCharsets.UTF_8)));
|
||||
when(repository.findByStatusOrderByBusinessDateAscIdAsc(Mockito.any(), Mockito.any())).thenReturn(events);
|
||||
when(messageFactory.createMessage(Mockito.any())).thenReturn(dummyMessage);
|
||||
when(byteBufferConverter.convert(Mockito.any(ByteBuffer.class))).thenReturn(new byte[0]);
|
||||
@@ -207,7 +208,7 @@ class SendAsynchronousEventsTaskletTest {
|
||||
List<ExternalEventView> events = Arrays
|
||||
.asList(createExternalEventView("aType", "aCategory", "aSchema", new byte[0], "aIdempotencyKey", null));
|
||||
MessageV1 dummyMessage = new MessageV1(1L, "aSource", "aType", "nocategory", "aCreateDate", "aBusinessDate", "aTenantId",
|
||||
"anidempotencyKey", "aSchema", Mockito.mock(ByteBuffer.class));
|
||||
"anidempotencyKey", "aSchema", ByteBuffer.wrap("dummy".getBytes(StandardCharsets.UTF_8)));
|
||||
when(repository.findByStatusOrderByBusinessDateAscIdAsc(Mockito.any(), Mockito.any())).thenReturn(events);
|
||||
when(messageFactory.createMessage(Mockito.any())).thenReturn(dummyMessage);
|
||||
byte[] byteMsg = new byte[0];
|
||||
|
||||
Reference in New Issue
Block a user