package io.github.hcoona.utils;

import org.junit.Assert;
import org.junit.Test;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

public class NamedMutexTest {

  @Test
  public void testCannotWaitOne() throws Exception {
    final String name = "test_named-mutex_cannot-wait-one";
    try (NamedMutex ignored = NamedMutex.newInstance(true, name)) {
      ExecutorService executor = Executors.newSingleThreadExecutor();

      Future<Boolean> waitOneFuture = executor.submit(() -> {
        try (NamedMutex mutex2 = NamedMutex.newInstance(true, name)) {
          return mutex2.waitOne(500, TimeUnit.MILLISECONDS);
        }
      });

      Assert.assertFalse(waitOneFuture.get());
    }
  }

  @Test
  public void testCanWaitOne() throws Exception {
    final String name = "test_named-mutex_can-wait-one";
    try (NamedMutex mutex_owned = NamedMutex.newInstance(true, name)) {
      mutex_owned.release();
      ExecutorService executor = Executors.newSingleThreadExecutor();

      Future<Boolean> waitOneFuture = executor.submit(() -> {
        try (NamedMutex mutex2 = NamedMutex.newInstance(true, name)) {
          return mutex2.waitOne(5, TimeUnit.SECONDS);
        }
      });

      Assert.assertTrue(waitOneFuture.get());
    }
  }

}

@@ -39,24 +39,111 @@
 ort 
-org.junit.Assert
+com.sun.jna.Platform;%0D%0Aimport org.junit.Assert;%0D%0Aimport org.junit.Assume;%0D%0Aimport org.junit.BeforeClass
 ;%0D%0Ai
@@ -331,16 +331,16 @@
 nit;%0D%0A%0D%0A
-
 public c
@@ -360,24 +360,148 @@
 exTest %7B%0D%0A%0D%0A
+  @BeforeClass%0D%0A  public static void beforeClass() throws Exception %7B%0D%0A    Assume.assumeTrue(Platform.isWindows());%0D%0A  %7D%0D%0A%0D%0A
   @Test%0D%0A  p

Mark it Windows only before Linux implement ready.