Upgrade to JUnit 5

This commit is contained in:
Sebastian Stenzel
2019-02-18 15:28:11 +01:00
parent ffd3981f36
commit 1e80f4bba4
14 changed files with 154 additions and 170 deletions
@@ -5,6 +5,10 @@
*******************************************************************************/
package org.cryptomator.launcher;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.io.IOException;
import java.nio.file.FileSystem;
import java.nio.file.InvalidPathException;
@@ -14,10 +18,6 @@ import java.nio.file.spi.FileSystemProvider;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
public class FileOpenRequestHandlerTest {
@Test
@@ -37,8 +37,8 @@ public class FileOpenRequestHandlerTest {
FileOpenRequestHandler handler = new FileOpenRequestHandler(queue);
handler.handleLaunchArgs(fs, new String[] {"foo", "bar"});
Assert.assertEquals(p1, queue.poll());
Assert.assertEquals(p2, queue.poll());
Assertions.assertEquals(p1, queue.poll());
Assertions.assertEquals(p2, queue.poll());
}
@Test
@@ -5,6 +5,11 @@
*******************************************************************************/
package org.cryptomator.launcher;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SeekableByteChannel;
@@ -15,11 +20,6 @@ import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.spi.FileSystemProvider;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
public class InterProcessCommunicatorTest {
Path portFilePath = Mockito.mock(Path.class);
@@ -30,7 +30,7 @@ public class InterProcessCommunicatorTest {
SeekableByteChannel portFileChannel = Mockito.mock(SeekableByteChannel.class);
AtomicInteger port = new AtomicInteger(-1);
@Before
@BeforeEach
public void setup() throws IOException {
Mockito.when(portFilePath.getFileSystem()).thenReturn(fs);
Mockito.when(portFilePath.toAbsolutePath()).thenReturn(portFilePath);
@@ -53,15 +53,17 @@ public class InterProcessCommunicatorTest {
});
}
@Test(expected = UnsupportedOperationException.class)
@Test
public void testStartWithDummyPort1() throws IOException {
port.set(0);
InterProcessCommunicationProtocol protocol = Mockito.mock(InterProcessCommunicationProtocol.class);
try (InterProcessCommunicator result = InterProcessCommunicator.start(portFilePath, protocol)) {
Assert.assertTrue(result.isServer());
Assertions.assertTrue(result.isServer());
Mockito.verify(provider).createDirectory(portFileParentPath);
Mockito.verifyZeroInteractions(protocol);
result.handleLaunchArgs(new String[] {"foo"});
Assertions.assertThrows(UnsupportedOperationException.class, () -> {
result.handleLaunchArgs(new String[] {"foo"});
});
}
}
@@ -71,7 +73,7 @@ public class InterProcessCommunicatorTest {
InterProcessCommunicationProtocol protocol = Mockito.mock(InterProcessCommunicationProtocol.class);
try (InterProcessCommunicator result = InterProcessCommunicator.start(portFilePath, protocol)) {
Assert.assertTrue(result.isServer());
Assertions.assertTrue(result.isServer());
Mockito.verify(provider).createDirectory(portFileParentPath);
Mockito.verifyZeroInteractions(protocol);
}
@@ -82,14 +84,14 @@ public class InterProcessCommunicatorTest {
port.set(-1);
InterProcessCommunicationProtocol protocol = Mockito.mock(InterProcessCommunicationProtocol.class);
try (InterProcessCommunicator result1 = InterProcessCommunicator.start(portFilePath, protocol)) {
Assert.assertTrue(result1.isServer());
Assertions.assertTrue(result1.isServer());
Mockito.verify(provider, Mockito.times(1)).createDirectory(portFileParentPath);
Mockito.verifyZeroInteractions(protocol);
try (InterProcessCommunicator result2 = InterProcessCommunicator.start(portFilePath, null)) {
Assert.assertFalse(result2.isServer());
Assertions.assertFalse(result2.isServer());
Mockito.verify(provider, Mockito.times(1)).createDirectory(portFileParentPath);
Assert.assertNotSame(result1, result2);
Assertions.assertNotSame(result1, result2);
result2.handleLaunchArgs(new String[] {"foo"});
Mockito.verify(protocol).handleLaunchArgs(new String[] {"foo"});
@@ -5,12 +5,12 @@
*******************************************************************************/
package org.cryptomator.logging;
import java.io.File;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.io.File;
public class LaunchBasedTriggeringPolicyTest {
@Test
@@ -21,15 +21,15 @@ public class LaunchBasedTriggeringPolicyTest {
// 1st invocation
boolean triggered = policy.isTriggeringEvent(activeFile, event);
Assert.assertTrue(triggered);
Assertions.assertTrue(triggered);
// 2nd invocation
triggered = policy.isTriggeringEvent(activeFile, event);
Assert.assertFalse(triggered);
Assertions.assertFalse(triggered);
// 3rd invocation
triggered = policy.isTriggeringEvent(activeFile, event);
Assert.assertFalse(triggered);
Assertions.assertFalse(triggered);
Mockito.verifyZeroInteractions(activeFile);
Mockito.verifyZeroInteractions(event);