From 4e211b64d74bd85adadc865a70d95d33624fd89f Mon Sep 17 00:00:00 2001 From: Haroon Khan Date: Fri, 26 Nov 2021 22:15:04 +0000 Subject: [PATCH] [JAVA-8353] Wait longer for the threads to finish --- .../IllegalMonitorStateExceptionUnitTest.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/illegalmonitorstate/IllegalMonitorStateExceptionUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/illegalmonitorstate/IllegalMonitorStateExceptionUnitTest.java index bef90e671f..857ab02c13 100644 --- a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/illegalmonitorstate/IllegalMonitorStateExceptionUnitTest.java +++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/illegalmonitorstate/IllegalMonitorStateExceptionUnitTest.java @@ -1,11 +1,12 @@ package com.baeldung.exceptions.illegalmonitorstate; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.junit.jupiter.api.Test; -import java.time.Duration; - -import static org.junit.jupiter.api.Assertions.*; - public class IllegalMonitorStateExceptionUnitTest { @Test @@ -20,11 +21,11 @@ public class IllegalMonitorStateExceptionUnitTest { Thread senderThread = new Thread(sender, "sender-thread"); senderThread.start(); - senderThread.join(1000); - receiverThread.join(1000); + // we need to wait for the sender and receiver threads to finish + senderThread.join(10_000); + receiverThread.join(10_000); - // we need to wait for enough time so that sender has had a chance to send the data - assertTimeout(Duration.ofSeconds(10), () -> assertEquals("test", receiver.getMessage())); + assertEquals("test", receiver.getMessage()); assertFalse(sender.hasIllegalMonitorStateExceptionOccurred()); assertFalse(receiver.hasIllegalMonitorStateExceptionOccurred()); }