Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Added a test of DataChannelRewriter#794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletionssrc/test/java/ev3dev/utils/DataChannelRewriterTest.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
package ev3dev.utils;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import static org.junit.Assert.assertEquals;

/**
* Some tests of DataChannelRewriter.
*
* @author David Walend
*/
public class DataChannelRewriterTest {

static Path tempDirectory;
static Path testPath;
static final String startString = "Original String";
static final String differentString = "Written String";

@BeforeClass
public static void createFiles() throws IOException {
tempDirectory = Files.createTempDirectory("DataChannelRewriterTest");
testPath = Files.createFile(Path.of(tempDirectory.toString(),"testFile"));
Files.write(testPath, startString.getBytes());
}

@Before
public void writeFile() throws IOException {
Files.write(testPath, startString.getBytes());
}

@AfterClass
public static void cleanupFiles() throws IOException {
Files.delete(testPath);
Files.delete(tempDirectory);
}


@Test
public void testOpenClose() throws IOException {
DataChannelRewriter rewriter = new DataChannelRewriter(testPath,32);
rewriter.close();

assertEquals(startString,Files.readString(testPath));
}

@Test
public void testOpenReadClose() throws IOException {
DataChannelRewriter rewriter = new DataChannelRewriter(testPath,32);
rewriter.writeString(differentString);
rewriter.close();

assertEquals(differentString+"\n",Files.readString(testPath));
}

@Test
public void testClosable() throws IOException {
try(DataChannelRewriter rewriter = new DataChannelRewriter(testPath,32)){
rewriter.writeString(differentString);
}
assertEquals(differentString+"\n",Files.readString(testPath));
}

@Test
public void testOpenWriteTwoThingsClose() throws IOException {
DataChannelRewriter rewriter = new DataChannelRewriter(testPath,32);
rewriter.writeString(differentString);
assertEquals(differentString+"\n",Files.readString(testPath));

String anotherString = "Another String";
rewriter.writeString(anotherString);

assertEquals(anotherString+"\n",Files.readString(testPath));

rewriter.close();
}

@Test(expected = RuntimeException.class)
public void testOpenNonexistentFile() throws IOException {
Path badPath = Path.of("/does/not/exist");

DataChannelRewriter rewriter = new DataChannelRewriter(badPath,32);
rewriter.writeString(differentString);
rewriter.close();
}
}

[8]ページ先頭

©2009-2025 Movatter.jp