@Override public void setUp() throws IOException { rootDir = Jimfs.newFileSystem(Configuration.unix()).getPath("/tmp"); Files.createDirectory(rootDir); }
private ErrorProneInMemoryFileManager(Optional<Class<?>> clazz) { super(new Context(), /* register= */ false, UTF_8); this.fileSystem = Jimfs.newFileSystem(Configuration.unix()); this.clazz = clazz; }
/** * Returns a default configuration appropriate to the current operating system. * * <p>More specifically, if the operating system is Windows, {@link Configuration#windows()} is * returned; if the operating system is Mac OS X, {@link Configuration#osX()} is returned; * otherwise, {@link Configuration#unix()} is returned. * * <p>This is the configuration used by the {@code Jimfs.newFileSystem} methods that do not take * a {@code Configuration} parameter. * * @since 1.1 */ public static Configuration forCurrentPlatform() { String os = System.getProperty("os.name"); if (os.contains("Windows")) { return windows(); } else if (os.contains("OS X")) { return osX(); } else { return unix(); } }
public void testByteSource_size_ofSymlinkToRegularFile() throws IOException { try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { Path file = fs.getPath("file"); Files.write(file, new byte[10]); Path link = fs.getPath("link"); Files.createSymbolicLink(link, file); ByteSource source = MoreFiles.asByteSource(link); assertEquals(10L, (long) source.sizeIfKnown().get()); assertEquals(10L, source.size()); } }
public void testByteSource_size_ofDirectory() throws IOException { try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { Path dir = fs.getPath("dir"); Files.createDirectory(dir); ByteSource source = MoreFiles.asByteSource(dir); assertThat(source.sizeIfKnown()).isAbsent(); try { source.size(); fail(); } catch (IOException expected) { } } }
FileSystem fs = Jimfs.newFileSystem( Configuration.unix() .toBuilder() .setSupportedFeatures(ObjectArrays.concat(SYMBOLIC_LINKS, supportedFeatures))
public void testByteSource_size_ofSymlinkToDirectory() throws IOException { try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { Path dir = fs.getPath("dir"); Files.createDirectory(dir); Path link = fs.getPath("link"); Files.createSymbolicLink(link, dir); ByteSource source = MoreFiles.asByteSource(link); assertThat(source.sizeIfKnown()).isAbsent(); try { source.size(); fail(); } catch (IOException expected) { } } }
public void testByteSource_size_ofSymlinkToRegularFile_nofollowLinks() throws IOException { try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { Path file = fs.getPath("file"); Files.write(file, new byte[10]); Path link = fs.getPath("link"); Files.createSymbolicLink(link, file); ByteSource source = MoreFiles.asByteSource(link, NOFOLLOW_LINKS); assertThat(source.sizeIfKnown()).isAbsent(); try { source.size(); fail(); } catch (IOException expected) { } } }
public void testEqual_links() throws IOException { try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { Path fooPath = fs.getPath("foo"); MoreFiles.asCharSink(fooPath, UTF_8).write("foo"); Path fooSymlink = fs.getPath("symlink"); Files.createSymbolicLink(fooSymlink, fooPath); Path fooHardlink = fs.getPath("hardlink"); Files.createLink(fooHardlink, fooPath); assertThat(MoreFiles.equal(fooPath, fooSymlink)).isTrue(); assertThat(MoreFiles.equal(fooPath, fooHardlink)).isTrue(); assertThat(MoreFiles.equal(fooSymlink, fooHardlink)).isTrue(); } }
public void testEqual() throws IOException { try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) { Path fooPath = fs.getPath("foo"); Path barPath = fs.getPath("bar"); MoreFiles.asCharSink(fooPath, UTF_8).write("foo"); MoreFiles.asCharSink(barPath, UTF_8).write("barbar"); assertThat(MoreFiles.equal(fooPath, barPath)).isFalse(); assertThat(MoreFiles.equal(fooPath, fooPath)).isTrue(); assertThat(MoreFiles.asByteSource(fooPath).contentEquals(MoreFiles.asByteSource(fooPath))) .isTrue(); Path fooCopy = Files.copy(fooPath, fs.getPath("fooCopy")); assertThat(Files.isSameFile(fooPath, fooCopy)).isFalse(); assertThat(MoreFiles.equal(fooPath, fooCopy)).isTrue(); MoreFiles.asCharSink(fooCopy, UTF_8).write("boo"); assertThat(MoreFiles.asByteSource(fooPath).size()) .isEqualTo(MoreFiles.asByteSource(fooCopy).size()); assertThat(MoreFiles.equal(fooPath, fooCopy)).isFalse(); // should also assert that a Path that erroneously reports a size 0 can still be compared, // not sure how to do that with the Path API } }
@Test public void profileInZip() throws IOException { FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix()); Files.createDirectories(fileSystem.getPath("/source")); Path zip = fileSystem.getPath("/source/protos.zip"); ZipOutputStream zipOutputStream = new ZipOutputStream(Files.newOutputStream(zip)); writeFile(zipOutputStream, "a/b/message.proto", "" + "package a.b;\n" + "message Message {" + "}"); writeFile(zipOutputStream, "a/b/android.wire", "" + "syntax = \"wire2\";\n" + "package a.b;\n" + "import \"a/b/message.proto\";\n" + "type a.b.Message {\n" + " target java.lang.Object using com.example.Message#ADAPTER;\n" + "}"); zipOutputStream.close(); Schema schema = new SchemaLoader() .addSource(zip) .load(); Profile profile = new ProfileLoader(fileSystem, "android") .schema(schema) .load(); ProtoType message = ProtoType.get("a.b.Message"); assertThat(profile.getTarget(message)).isEqualTo(ClassName.OBJECT); assertThat(profile.getAdapter(message)).isEqualTo( new AdapterConstant("com.example.Message#ADAPTER")); }
@Parameters(name = "os = {0}") public static Collection<Object[]> data() { return Arrays.asList( new Object[][] { {"Unix", Configuration.unix(), "/usr/home/android/sdk", ""}, {"Windows", Configuration.windows(), "C:\\android\\sdk", ".exe"}, {"OS X", Configuration.osX(), "/Users/home/android/sdk", ""} }); }
public static FileSystem get() { if (fileSystemThreadLocal.get() == null) { fileSystemThreadLocal.set(Jimfs.newFileSystem(Configuration.unix())); } return fileSystemThreadLocal.get(); }
@Test public void testInMemoryNioFileDoesExist() throws IOException{ FileSystem fs = Jimfs.newFileSystem(Configuration.unix()); Path file = fs.getPath("/file"); Files.createFile(file); tstExists(file.toUri().toString(), true); }
@Test( dataProvider = "getFiles") public void testCheckTerminationForPaths(File compressedFile, BlockCompressedInputStream.FileTermination expected) throws IOException { try(FileSystem fs = Jimfs.newFileSystem("test", Configuration.unix())){ final Path compressedFileInJimfs = Files.copy(compressedFile.toPath(), fs.getPath("something")); Assert.assertEquals(BlockCompressedInputStream.checkTermination(compressedFileInJimfs), expected); } }
@Before public void setUp() throws IOException { fileSystem = Jimfs.newFileSystem(Configuration.unix()); tmpDir = Files.createDirectory(fileSystem.getPath("tmp")); }
@Before public void setUp() throws Exception { fileSystem = Jimfs.newFileSystem(Configuration.unix()); platformConfig = new InMemoryPlatformConfig(fileSystem); MapModuleConfig moduleConfig = platformConfig.createModuleConfig("limit-violation-default-filter"); moduleConfig.setStringListProperty("violationTypes", Arrays.asList("CURRENT", "LOW_VOLTAGE")); moduleConfig.setStringProperty("minBaseVoltage", "150"); moduleConfig.setStringListProperty("countries", Arrays.asList("FR", "BE")); }
@Override @Before public void setup() throws IOException { super.setup(); NodeInfo rootFolderInfo = storage.createRootNodeIfNotExists("root", Folder.PSEUDO_CLASS); storage.createNode(rootFolderInfo.getId(), "network", Case.PSEUDO_CLASS, "Test format", Case.VERSION, new NodeGenericMetadata().setString("format", TestImporter.FORMAT)); fileSystem = Jimfs.newFileSystem(Configuration.unix()); Files.createFile(fileSystem.getPath("/work/network.tst")); }
@Before public void setUp() throws IOException { fileSystem = Jimfs.newFileSystem(Configuration.unix()); InMemoryPlatformConfig platformConfig = new InMemoryPlatformConfig(fileSystem); moduleConfig = platformConfig.createModuleConfig("componentDefaultConfig"); config = new ComponentDefaultConfig.Impl(moduleConfig); }