本文整理匯總了Java中com.google.common.jimfs.Jimfs類的典型用法代碼示例。如果您正苦於以下問題:Java Jimfs類的具體用法?Java Jimfs怎麽用?Java Jimfs使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Jimfs類屬於com.google.common.jimfs包,在下文中一共展示了Jimfs類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testEqual
import com.google.common.jimfs.Jimfs; //導入依賴的package包/類
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
}
}
示例2: setUp
import com.google.common.jimfs.Jimfs; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
fileSystem = Jimfs.newFileSystem(Configuration.unix());
Path rootDir = fileSystem.getPath("/cases");
Files.createDirectories(rootDir);
path1 = rootDir.resolve("n.tst");
path2 = rootDir.resolve("n2.tst");
Files.createFile(path1);
Files.createFile(path2);
ComputationManager computationManager = Mockito.mock(ComputationManager.class);
Network network = Mockito.mock(Network.class);
List<LocalFileScanner> fileExtensions
= Collections.singletonList(new LocalCaseScanner(new ImportConfig(),
new ImportersLoaderList(Collections.singletonList(new TestImporter(network)),
Collections.emptyList())));
storage = new LocalAppStorage(rootDir, "mem", fileExtensions, Collections.emptyList(), computationManager);
}
示例3: testByteSource_size_ofSymlinkToDirectory
import com.google.common.jimfs.Jimfs; //導入依賴的package包/類
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) {
}
}
}
示例4: testConfig
import com.google.common.jimfs.Jimfs; //導入依賴的package包/類
@Test
public void testConfig() throws IOException {
TableFormatterConfig config = new TableFormatterConfig();
testConfig(config, Locale.getDefault(), ';', "inv", true, true);
try (FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix())) {
InMemoryPlatformConfig platformConfig = new InMemoryPlatformConfig(fileSystem);
MapModuleConfig moduleConfig = platformConfig.createModuleConfig("table-formatter");
moduleConfig.setStringProperty("language", "en-US");
moduleConfig.setStringProperty("separator", "\t");
moduleConfig.setStringProperty("invalid-string", "NaN");
moduleConfig.setStringProperty("print-header", "false");
moduleConfig.setStringProperty("print-title", "false");
config = TableFormatterConfig.load(platformConfig);
testConfig(config, Locale.US, '\t', "NaN", false, false);
}
}
示例5: testEqual_links
import com.google.common.jimfs.Jimfs; //導入依賴的package包/類
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();
}
}
示例6: testByteSource_size_ofSymlinkToRegularFile_nofollowLinks
import com.google.common.jimfs.Jimfs; //導入依賴的package包/類
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) {
}
}
}
示例7: test
import com.google.common.jimfs.Jimfs; //導入依賴的package包/類
@Test
public void test() throws IOException {
try (FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix())) {
InMemoryPlatformConfig platformConfig = new InMemoryPlatformConfig(fileSystem);
MapModuleConfig moduleConfig = platformConfig.createModuleConfig("load-flow-action-simulator");
moduleConfig.setClassProperty("load-flow-factory", LoadFlowFactoryMock.class);
moduleConfig.setStringProperty("max-iterations", "15");
moduleConfig.setStringProperty("ignore-pre-contingency-violations", "true");
LoadFlowActionSimulatorConfig config = LoadFlowActionSimulatorConfig.load(platformConfig);
assertEquals(LoadFlowFactoryMock.class, config.getLoadFlowFactoryClass());
config.setLoadFlowFactoryClass(AnotherLoadFlowFactoryMock.class);
assertEquals(AnotherLoadFlowFactoryMock.class, config.getLoadFlowFactoryClass());
assertEquals(15, config.getMaxIterations());
config.setMaxIterations(10);
assertEquals(10, config.getMaxIterations());
assertTrue(config.isIgnorePreContingencyViolations());
config.setIgnorePreContingencyViolations(false);
assertFalse(config.isIgnorePreContingencyViolations());
}
}
示例8: testByteSource_size_ofDirectory
import com.google.common.jimfs.Jimfs; //導入依賴的package包/類
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) {
}
}
}
示例9: testFileIgnoreDetection
import com.google.common.jimfs.Jimfs; //導入依賴的package包/類
@Test
public void testFileIgnoreDetection() throws IOException {
try (FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix())) {
Files.createDirectory(fileSystem.getPath("/data"));
Files.createDirectory(fileSystem.getPath("/data/ok"));
Files.createDirectory(fileSystem.getPath("/data/bad"));
// Create ok file
Files.createFile(fileSystem.getPath("/data/ok/toto"));
// Create ignore file
Files.createFile(fileSystem.getPath("/data/bad/.photatoignore"));
Assert.assertFalse(FileHelper.folderContainsIgnoreFile(fileSystem.getPath("/data/ok")));
Assert.assertTrue(FileHelper.folderContainsIgnoreFile(fileSystem.getPath("/data/bad")));
}
}
示例10: completes
import com.google.common.jimfs.Jimfs; //導入依賴的package包/類
@Test
public void completes() throws Exception {
final FileSystem fs = Jimfs.newFileSystem();
final CountDownLatch latch = new CountDownLatch(1);
DownloadTask.download(
new URI("http://www.google.com"),
fs.getPath("test.txt").toAbsolutePath())
.subscribe(
next -> {
},
error -> {
},
() -> {
assertTrue(true);
latch.countDown();
});
latch.await(5000L, TimeUnit.MILLISECONDS);
}
示例11: downloadRemoteFileCompletes
import com.google.common.jimfs.Jimfs; //導入依賴的package包/類
@Test
public void downloadRemoteFileCompletes() throws Exception {
final FileSystem fs = Jimfs.newFileSystem();
final RemoteFile remoteFile = RemoteFile.of(
new URI("https://raw.githubusercontent.com/nikhedonia/googletest/665327f0141d4a4fc4f2496e781dce436d742645/BUCK"),
HashCode.fromString("d976069f5b47fd8fc57201f47026a70dee4e47b3141ac23567b8a0c56bf9288c"));
final SettableFuture<Boolean> future = SettableFuture.create();
CommonTasks.downloadRemoteFile(fs, remoteFile, fs.getPath("test.txt").toAbsolutePath())
.subscribe(
next -> {
},
error -> {
future.set(false);
},
() -> {
future.set(true);
});
assertTrue(future.get(30, TimeUnit.SECONDS));
}
示例12: log
import com.google.common.jimfs.Jimfs; //導入依賴的package包/類
@Test
public void log() throws Exception {
final FileSystem fs = Jimfs.newFileSystem();
final Observable<Event> task = LoggingTasks.log(fs, "integration test");
final CountDownLatch latch = new CountDownLatch(1);
task.subscribe(
result -> {
latch.countDown();
}, error -> {
error.printStackTrace();
});
latch.await(5000L, TimeUnit.MILLISECONDS);
}
示例13: downloadUsingCacheFailsWhenTheHashIsIncorrect
import com.google.common.jimfs.Jimfs; //導入依賴的package包/類
@Test
public void downloadUsingCacheFailsWhenTheHashIsIncorrect() throws Exception {
final FileSystem fs = Jimfs.newFileSystem();
final RemoteFile remoteFile = RemoteFile.of(
new URI("https://raw.githubusercontent.com/njlr/test-lib-a/3af013452fe6b448b1cb33bb81bb19da690ec764/BUCK"),
HashCode.fromString("aaaaaaaaaaaaaa4f244296b0fba7a70166dea49c9e8d3eacda58d67a"));
final Path cachePath = CacheTasks.getCachePath(fs, remoteFile);
final SettableFuture<Throwable> futureException = SettableFuture.create();
CacheTasks.downloadToCache(fs, remoteFile).subscribe(
next -> {},
error -> {
futureException.set(error);
},
() -> {});
final Throwable exception = futureException.get(5000L, TimeUnit.MILLISECONDS);
assertTrue(exception instanceof DownloadFileException);
assertTrue(exception.getCause() instanceof HashMismatchException);
}
示例14: resolverWorksWithGitHub1
import com.google.common.jimfs.Jimfs; //導入依賴的package包/類
@Test
public void resolverWorksWithGitHub1() throws Exception {
final FileSystem fs = Jimfs.newFileSystem();
final RecipeSource recipeSource = GitProviderRecipeSource.of(
fs,
GitHubGitProvider.of());
final Single<ResolvedDependencies> task = AsyncDependencyResolver.resolve(
recipeSource,
ImmutableList.of(Dependency.of(
RecipeIdentifier.of("github", "njlr", "test-lib-a"),
AnySemanticVersion.of())))
.result();
final ResolvedDependencies resolved =
task.timeout(120, TimeUnit.SECONDS).blockingGet();
assertTrue(resolved.dependencies.containsKey(RecipeIdentifier.of("github", "njlr", "test-lib-a")));
assertTrue(resolved.dependencies.containsKey(RecipeIdentifier.of("github", "njlr", "test-lib-b")));
assertTrue(resolved.dependencies.containsKey(RecipeIdentifier.of("github", "njlr", "test-lib-c")));
}
示例15: resolverWorksWithGitHub2
import com.google.common.jimfs.Jimfs; //導入依賴的package包/類
@Test
public void resolverWorksWithGitHub2() throws Exception {
final FileSystem fs = Jimfs.newFileSystem();
final RecipeSource recipeSource = GitProviderRecipeSource.of(
fs,
GitHubGitProvider.of());
final Single<ResolvedDependencies> task = AsyncDependencyResolver.resolve(
recipeSource,
ImmutableList.of(Dependency.of(
RecipeIdentifier.of("github", "njlr", "test-lib-e"),
AnySemanticVersion.of())))
.result();
final ResolvedDependencies resolved =
task.timeout(120, TimeUnit.SECONDS).blockingGet();
assertTrue(resolved.dependencies.containsKey(
RecipeIdentifier.of("github", "njlr", "test-lib-e")));
}