diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/user/CpApplyListener.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/user/CpApplyListener.java index d97acfc3..eba27308 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/user/CpApplyListener.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/user/CpApplyListener.java @@ -61,8 +61,10 @@ public class CpApplyListener implements MessageListener { } private void expire(CpApply cpApply) { - sendExpiredNotice(cpApply); - cpApplyService.changeStatusById(cpApply.getId(), CpApplyStatus.EXPIRE); + boolean changed = cpApplyService.changeStatusById(cpApply.getId(), CpApplyStatus.EXPIRE); + if (changed) { + sendExpiredNotice(cpApply); + } } private void sendExpiredNotice(CpApply cpApply) { diff --git a/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/listener/user/CpApplyListenerTest.java b/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/listener/user/CpApplyListenerTest.java index a421907b..0bda6de2 100644 --- a/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/listener/user/CpApplyListenerTest.java +++ b/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/listener/user/CpApplyListenerTest.java @@ -4,8 +4,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.red.circle.common.business.core.enums.SysOriginPlatformEnum; @@ -27,6 +27,7 @@ import java.util.Map; import java.util.function.Consumer; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; +import org.mockito.InOrder; class CpApplyListenerTest { @@ -66,10 +67,11 @@ class CpApplyListenerTest { ArgumentCaptor captor = ArgumentCaptor.forClass( CustomC2cMsgBodyCmd.class); - verify(imMessageClient).sendCustomMessage(captor.capture()); + InOrder inOrder = inOrder(cpApplyService, imMessageClient); + inOrder.verify(cpApplyService).changeStatusById(3001L, CpApplyStatus.EXPIRE); + inOrder.verify(imMessageClient).sendCustomMessage(captor.capture()); List messages = captor.getAllValues(); assertExpiredMessage(messages.get(0), "1001", "2001"); - verify(cpApplyService).changeStatusById(3001L, CpApplyStatus.EXPIRE); } @SuppressWarnings("unchecked")