From 74320381ba4855b80da0cad7c98eebd03b279809 Mon Sep 17 00:00:00 2001 From: abilan Date: Mon, 9 Jan 2023 16:27:06 -0500 Subject: [PATCH] Some tweaks for SimpleMessageGroupTests **Cherry-pick to `5.5.x`** --- .../store/SimpleMessageGroupTests.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/spring-integration-core/src/test/java/org/springframework/integration/store/SimpleMessageGroupTests.java b/spring-integration-core/src/test/java/org/springframework/integration/store/SimpleMessageGroupTests.java index 1187a29e1e..6e554fd812 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/store/SimpleMessageGroupTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/store/SimpleMessageGroupTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2022 the original author or authors. + * Copyright 2009-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; @@ -45,17 +45,16 @@ public class SimpleMessageGroupTests { private final Object key = new Object(); - private final SimpleMessageGroup group = new SimpleMessageGroup(new ArrayList>(), key); + private final SimpleMessageGroup group = new SimpleMessageGroup(new ArrayList<>(), key); private MessageGroup sequenceAwareGroup; - @SuppressWarnings("unchecked") public void prepareForSequenceAwareMessageGroup() throws Exception { - Class clazz = - (Class) Class.forName("org.springframework.integration.aggregator.AbstractCorrelatingMessageHandler$SequenceAwareMessageGroup"); - Constructor ctr = clazz.getDeclaredConstructor(MessageGroup.class); + Class clazz = + Class.forName("org.springframework.integration.aggregator.AbstractCorrelatingMessageHandler$SequenceAwareMessageGroup"); + Constructor ctr = clazz.getDeclaredConstructor(MessageGroup.class); ctr.setAccessible(true); - this.sequenceAwareGroup = ctr.newInstance(this.group); + this.sequenceAwareGroup = (MessageGroup) ctr.newInstance(this.group); } @Test @@ -83,13 +82,13 @@ public class SimpleMessageGroupTests { } @SuppressWarnings("unchecked") - @Test // should not fail with NPE (see INT-2666) - public void shouldIgnoreNullValuesWhenInitializedWithCollectionContainingNulls() throws Exception { + @Test + public void shouldIgnoreNullValuesWhenInitializedWithCollectionContainingNulls() { Message m1 = mock(Message.class); willReturn(new MessageHeaders(mock(Map.class))).given(m1).getHeaders(); Message m2 = mock(Message.class); willReturn(new MessageHeaders(mock(Map.class))).given(m2).getHeaders(); - final List> messages = new ArrayList>(); + final List> messages = new ArrayList<>(); messages.add(m1); messages.add(null); messages.add(m2); @@ -99,7 +98,7 @@ public class SimpleMessageGroupTests { @Test // This test used to take 2 min and half to run; now ~200 milliseconds. - public void testPerformance_INT3846() { + public void testPerformance() { Collection> messages = new ArrayList<>(); for (int i = 0; i < 100000; i++) { messages.add(new GenericMessage("foo")); @@ -108,10 +107,10 @@ public class SimpleMessageGroupTests { StopWatch watch = new StopWatch(); watch.start(); for (Message message : messages) { - group.getMessages().contains(message); + assertThat(group.getMessages().contains(message)).isTrue(); } watch.stop(); - assertThat(watch.getTotalTimeMillis() < 5000).isTrue(); + assertThat(watch.getTotalTimeMillis()).isLessThan(5000); } }