Skip to content

Commit

Permalink
Include various filesystem-related tests when we test under an Androi…
Browse files Browse the repository at this point in the history
…d emulator.

PiperOrigin-RevId: 526118501
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Apr 21, 2023
1 parent 58eaef7 commit edabd32
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public void testCopyChannel() throws IOException {
assertThat(out.toByteArray()).isEqualTo(expected);
}

@AndroidIncompatible // Android forbids much filesystem access. Maybe we could make it work?

public void testCopyFileChannel() throws IOException {
final int chunkSize = 14407; // Random prime, unlikely to match any internal chunk size
Expand Down Expand Up @@ -381,7 +380,7 @@ public void testNewDataOutput_writeChars() {
assertThat(out.toByteArray()).isEqualTo(expected);
}

@AndroidIncompatible // https://code.google.com/p/android/issues/detail?id=196848
@AndroidIncompatible // https://issuetracker.google.com/issues/37074504
public void testUtf16Expected() {
byte[] hardcodedExpected = utf16ExpectedWithBom;
byte[] computedExpected = "r\u00C9sum\u00C9".getBytes(Charsets.UTF_16);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
*
* @author Chris Nokleberg
*/
@AndroidIncompatible // Android forbids much filesystem access. Maybe we could make it work?
public class FileBackedOutputStreamTest extends IoTestCase {


Expand Down Expand Up @@ -80,6 +79,7 @@ private void testThreshold(
}


@AndroidIncompatible // Finalization probably just doesn't happen fast enough?
public void testFinalizeDeletesFile() throws Exception {
byte[] data = newPreFilledByteArray(100);
FileBackedOutputStream out = new FileBackedOutputStream(0, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,50 +22,20 @@
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import junit.framework.TestCase;

/**
* Tests for {@link Files#fileTraverser()}.
*
* @author Jens Nyman
*/

@AndroidIncompatible // Android forbids much filesystem access. Maybe we could make it work?
public class FilesFileTraverserTest extends TestCase {
public class FilesFileTraverserTest extends IoTestCase {

private File rootDir;

@Override
public void setUp() throws IOException {
rootDir = Files.createTempDir();
}

@Override
public void tearDown() throws IOException {
// delete rootDir and its contents
java.nio.file.Files.walkFileTree(
rootDir.toPath(),
new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
throws IOException {
java.nio.file.Files.deleteIfExists(file);
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
if (exc != null) {
return FileVisitResult.TERMINATE;
}
java.nio.file.Files.deleteIfExists(dir);
return FileVisitResult.CONTINUE;
}
});
rootDir = createTempDir();
}

public void testFileTraverser_emptyDirectory() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
* @author Chris Nokleberg
*/

@AndroidIncompatible // Android forbids much filesystem access. Maybe we could make it work?
public class FilesTest extends IoTestCase {

@AndroidIncompatible // suites, ByteSourceTester (b/230620681)
public static TestSuite suite() {
TestSuite suite = new TestSuite();
suite.addTest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ public void testGetResource_relativePath() {
assertNotNull(Resources.getResource(getClass(), "testdata/i18n.txt"));
}

@AndroidIncompatible // Android prevents most access to files
public void testGetResource_contextClassLoader() throws IOException {
// Check that we can find a resource if it is visible to the context class
// loader, even if it is not visible to the loader of the Resources class.
Expand Down
3 changes: 1 addition & 2 deletions guava-tests/test/com/google/common/io/ByteStreamsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public void testCopyChannel() throws IOException {
assertThat(out.toByteArray()).isEqualTo(expected);
}

@AndroidIncompatible // Android forbids much filesystem access. Maybe we could make it work?

public void testCopyFileChannel() throws IOException {
final int chunkSize = 14407; // Random prime, unlikely to match any internal chunk size
Expand Down Expand Up @@ -381,7 +380,7 @@ public void testNewDataOutput_writeChars() {
assertThat(out.toByteArray()).isEqualTo(expected);
}

@AndroidIncompatible // https://code.google.com/p/android/issues/detail?id=196848
@AndroidIncompatible // https://issuetracker.google.com/issues/37074504
public void testUtf16Expected() {
byte[] hardcodedExpected = utf16ExpectedWithBom;
byte[] computedExpected = "r\u00C9sum\u00C9".getBytes(Charsets.UTF_16);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
*
* @author Chris Nokleberg
*/
@AndroidIncompatible // Android forbids much filesystem access. Maybe we could make it work?
public class FileBackedOutputStreamTest extends IoTestCase {


Expand Down Expand Up @@ -80,6 +79,7 @@ private void testThreshold(
}


@AndroidIncompatible // Finalization probably just doesn't happen fast enough?
public void testFinalizeDeletesFile() throws Exception {
byte[] data = newPreFilledByteArray(100);
FileBackedOutputStream out = new FileBackedOutputStream(0, true);
Expand Down
34 changes: 2 additions & 32 deletions guava-tests/test/com/google/common/io/FilesFileTraverserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,50 +22,20 @@
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import junit.framework.TestCase;

/**
* Tests for {@link Files#fileTraverser()}.
*
* @author Jens Nyman
*/

@AndroidIncompatible // Android forbids much filesystem access. Maybe we could make it work?
public class FilesFileTraverserTest extends TestCase {
public class FilesFileTraverserTest extends IoTestCase {

private File rootDir;

@Override
public void setUp() throws IOException {
rootDir = Files.createTempDir();
}

@Override
public void tearDown() throws IOException {
// delete rootDir and its contents
java.nio.file.Files.walkFileTree(
rootDir.toPath(),
new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
throws IOException {
java.nio.file.Files.deleteIfExists(file);
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
if (exc != null) {
return FileVisitResult.TERMINATE;
}
java.nio.file.Files.deleteIfExists(dir);
return FileVisitResult.CONTINUE;
}
});
rootDir = createTempDir();
}

public void testFileTraverser_emptyDirectory() throws Exception {
Expand Down
2 changes: 1 addition & 1 deletion guava-tests/test/com/google/common/io/FilesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
* @author Chris Nokleberg
*/

@AndroidIncompatible // Android forbids much filesystem access. Maybe we could make it work?
public class FilesTest extends IoTestCase {

@AndroidIncompatible // suites, ByteSourceTester (b/230620681)
public static TestSuite suite() {
TestSuite suite = new TestSuite();
suite.addTest(
Expand Down
1 change: 0 additions & 1 deletion guava-tests/test/com/google/common/io/ResourcesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ public void testGetResource_relativePath() {
assertNotNull(Resources.getResource(getClass(), "testdata/i18n.txt"));
}

@AndroidIncompatible // Android prevents most access to files
public void testGetResource_contextClassLoader() throws IOException {
// Check that we can find a resource if it is visible to the context class
// loader, even if it is not visible to the loader of the Resources class.
Expand Down

0 comments on commit edabd32

Please sign in to comment.