/
rgd045
/
crypt-file
Обзор
Документация
Войти
/
rgd045
/
crypt-file
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/test/java/org/cryptomator/ipc/HandleLaunchArgsMessageTest.java
46 строк
2 KB
Sebastian Stenzel
Use UNIX Sockets for IPC
13 июл 2021, 19:18
Не верифицирован
13 июл 2021, 19:18
755eb70
Код
Авторство
О чём код?
package org.cryptomator.ipc; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import java.io.IOException; import java.nio.channels.FileChannel; import java.nio.file.Path; import java.nio.file.StandardOpenOption; import java.util.List; public class HandleLaunchArgsMessageTest { @Test public void testSendAndReceive(@TempDir Path tmpDir) throws IOException { var message = new HandleLaunchArgsMessage(List.of("hello world", "foo bar")); var file = tmpDir.resolve("tmp.file"); try (var ch = FileChannel.open(file, StandardOpenOption.CREATE_NEW, StandardOpenOption.READ, StandardOpenOption.WRITE)) { message.send(ch); ch.position(0); if (IpcMessage.receive(ch) instanceof HandleLaunchArgsMessage received) { Assertions.assertArrayEquals(message.args().toArray(), received.args().toArray()); } else { Assertions.fail("Received message of unexpected class"); } } } @Test public void testSendAndReceiveEmpty(@TempDir Path tmpDir) throws IOException { var message = new HandleLaunchArgsMessage(List.of()); var file = tmpDir.resolve("tmp.file"); try (var ch = FileChannel.open(file, StandardOpenOption.CREATE_NEW, StandardOpenOption.READ, StandardOpenOption.WRITE)) { message.send(ch); ch.position(0); if (IpcMessage.receive(ch) instanceof HandleLaunchArgsMessage received) { Assertions.assertArrayEquals(message.args().toArray(), received.args().toArray()); } else { Assertions.fail("Received message of unexpected class"); } } } }