/* © 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);
	}
}
