Files
Umbrella/messages/src/test/java/TriggerTest.java
2025-07-08 00:06:35 +02:00

31 lines
702 B
Java

/* © SRSoftware 2025 */
import static java.lang.Thread.sleep;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class TriggerTest {
@Test
public void testSynchronization() throws InterruptedException {
StringBuffer sb = new StringBuffer();
new Thread(() -> writeTo(sb,"A")).start();
sleep(100);
new Thread(() -> writeTo(sb,"B")).start();
sleep(100);
new Thread(() -> writeTo(sb,"C")).start();
sleep(1000);
assertEquals("AABBCC",sb.toString());
}
private synchronized void writeTo(StringBuffer sb, String mark) {
sb.append(mark);
try {
sleep(200);
} catch (InterruptedException ignored) {}
sb.append(mark);
}
}