org.assertj.core.api.AbstractFileAssert类的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(11.9k)|赞(0)|评价(0)|浏览(128)

本文整理了Java中org.assertj.core.api.AbstractFileAssert类的一些代码示例,展示了AbstractFileAssert类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AbstractFileAssert类的具体详情如下:
包路径:org.assertj.core.api.AbstractFileAssert
类名称:AbstractFileAssert

AbstractFileAssert介绍

[英]Base class for all implementations of assertions for Files.
[中]用于文件断言的所有实现的基类。

代码示例

代码示例来源:origin: SonarSource/sonarqube

@Test
public void cleaningRootModuleShouldNotDeleteChildrenWorkDir() throws IOException {
 DefaultInputModule moduleA = mock(DefaultInputModule.class);
 when(hierarchy.children(root)).thenReturn(Arrays.asList(moduleA));
 File moduleAWorkdir = new File(rootWorkDir, "moduleA");
 when(moduleA.getWorkDir()).thenReturn(moduleAWorkdir.toPath());
 moduleAWorkdir.mkdir();
 new File(moduleAWorkdir, "fooA.txt").createNewFile();
 initializer.execute();
 assertThat(rootWorkDir).exists();
 assertThat(lock).exists();
 assertThat(rootWorkDir.list()).containsOnly(DirectoryLock.LOCK_FILE_NAME, "moduleA");
 assertThat(moduleAWorkdir).exists();
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void test_file_system_information() throws IOException {
 File home = temp.newFolder();
 when(fs.getHomeDir()).thenReturn(home);
 assertThat(underTest.getRootDir()).isEqualTo(home);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void deleteQuietly_does_not_fail_if_file_does_not_exist() throws IOException {
 File file = new File(temporaryFolder.newFolder(), "blablabl");
 assertThat(file).doesNotExist();
 FileUtils2.deleteQuietly(file);
}

代码示例来源:origin: SonarSource/sonarqube

private static void verifySameContent(File file1, FileAndMd5 file2) {
 assertThat(file1).isFile().exists();
 assertThat(file2.file).isFile().exists();
 assertThat(file1).hasSameContentAs(file2.file);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void reset_creates_dirs_if_they_don_t_exist() throws Exception {
 assertThat(dataDir).doesNotExist();
 underTest.reset();
 assertThat(dataDir).exists().isDirectory();
 assertThat(logsDir).exists().isDirectory();
 assertThat(tempDir).exists().isDirectory();
 assertThat(webDir).exists().isDirectory();
 underTest.reset();
 assertThat(dataDir).exists().isDirectory();
 assertThat(logsDir).exists().isDirectory();
 assertThat(tempDir).exists().isDirectory();
 assertThat(webDir).exists().isDirectory();
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testWithFile() {
 final File file = Converters.create(File.class, "foo/hello.txt");
 assertThat(file).hasName("hello.txt")
   .doesNotExist();
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void existing_temp_dir() throws Exception {
 ServerFileSystem fs = mock(ServerFileSystem.class);
 File tmpDir = temp.newFolder();
 when(fs.getTempDir()).thenReturn(tmpDir);
 TempFolder folder = underTest.provide(fs);
 assertThat(folder).isNotNull();
 File newDir = folder.newDir();
 assertThat(newDir).exists().isDirectory();
 assertThat(newDir.getParentFile().getCanonicalPath()).startsWith(tmpDir.getCanonicalPath());
}

代码示例来源:origin: palantir/gradle-baseline

@Test
public void doesNothingIfTaskSkipped() throws IOException, TransformerException {
  Project project = ProjectBuilder.builder().withName("fooproject").withProjectDir(projectDir.getRoot()).build();
  Checkstyle checkstyle = createCheckstyleTask(project);
  checkstyle.setDidWork(false);
  TaskTimer timer = mock(TaskTimer.class);
  when(timer.getTaskTimeNanos(checkstyle)).thenReturn(FAILED_CHECKSTYLE_TIME_NANOS);
  File targetFile = new File(projectDir.getRoot(), "reports/report.xml");
  CircleStyleFinalizer finalizer = (CircleStyleFinalizer) project
      .task(ImmutableMap.of("type", CircleStyleFinalizer.class), "checkstyleTestCircleFinalizer");
  finalizer.setStyleTask(checkstyle);
  finalizer.setTaskTimer(timer);
  finalizer.setFailuresSupplier(XmlReportFailuresSupplier.create(checkstyle, new CheckstyleReportHandler()));
  finalizer.setTargetFile(targetFile);
  finalizer.createCircleReport();
  assertThat(targetFile).doesNotExist();
  assertThat(finalizer.getDidWork()).isFalse();
}

代码示例来源:origin: SonarSource/sonarqube

@Test
 public void copy_all_classloader_files_to_dedicated_directory() throws Exception {
  File deployDir = temp.newFolder();
  when(fs.getDeployedPluginsDir()).thenReturn(deployDir);
  File sourceJar = TestProjectUtils.jarOf("test-libs-plugin");
  PluginInfo info = PluginInfo.create(sourceJar);

  ExplodedPlugin exploded = underTest.explode(info);

  // all the files loaded by classloaders (JAR + META-INF/libs/*.jar) are copied to the dedicated directory
  // web/deploy/{pluginKey}
  File pluginDeployDir = new File(deployDir, "testlibs");

  assertThat(exploded.getKey()).isEqualTo("testlibs");
  assertThat(exploded.getMain()).isFile().exists().hasParent(pluginDeployDir);
  assertThat(exploded.getLibs()).extracting("name").containsOnly("commons-daemon-1.0.15.jar", "commons-email-20030310.165926.jar");
  for (File lib : exploded.getLibs()) {
   assertThat(lib).exists().isFile();
   assertThat(lib.getCanonicalPath()).startsWith(pluginDeployDir.getCanonicalPath());
  }
  File targetJar = new File(fs.getDeployedPluginsDir(), "testlibs/test-libs-plugin-0.1-SNAPSHOT.jar");
  verify(pluginFileSystem).addInstalledPlugin(info, targetJar);
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void download_from_url() {
 Plugin test = Plugin.factory("test");
 Release test10 = new Release(test, "1.0").setDownloadUrl("http://server/test-1.0.jar");
 test.addRelease(test10);
 when(updateCenter.findInstallablePlugins("foo", create("1.0"))).thenReturn(newArrayList(test10));
 pluginDownloader.start();
 pluginDownloader.download("foo", create("1.0"));
 // SONAR-4523: do not corrupt JAR files when restarting the server while a plugin is being downloaded.
 // The JAR file is downloaded in a temp file
 verify(httpDownloader).download(any(URI.class), argThat(new HasFileName("test-1.0.jar.tmp")));
 assertThat(new File(downloadDir, "test-1.0.jar")).exists();
 assertThat(new File(downloadDir, "test-1.0.jar.tmp")).doesNotExist();
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void shouldOnlyDumpPluginsByDefault() throws Exception {
 when(pluginRepo.getPluginInfos()).thenReturn(singletonList(new PluginInfo("xoo").setName("Xoo").setVersion(Version.create("1.0"))));
 ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder());
 DefaultInputModule rootModule = new DefaultInputModule(ProjectDefinition.create()
  .setBaseDir(temp.newFolder())
  .setWorkDir(temp.newFolder()));
 when(store.allModules()).thenReturn(singletonList(rootModule));
 when(hierarchy.root()).thenReturn(rootModule);
 publisher.init(writer);
 assertThat(writer.getFileStructure().analysisLog()).exists();
 assertThat(FileUtils.readFileToString(writer.getFileStructure().analysisLog(), StandardCharsets.UTF_8)).contains("Xoo 1.0 (xoo)");
 verifyZeroInteractions(system2);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void download_installed_plugins() throws IOException {
 WsTestUtil.mockReader(wsClient, "api/plugins/installed", new InputStreamReader(getClass().getResourceAsStream("ScannerPluginInstallerTest/installed-plugins-ws.json")));
 enqueueDownload("scmgit", "abc");
 enqueueDownload("java", "def");
 when(pluginPredicate.apply(any())).thenReturn(true);
 Map<String, ScannerPlugin> result = underTest.installRemotes();
 assertThat(result.keySet()).containsExactlyInAnyOrder("scmgit", "java");
 ScannerPlugin gitPlugin = result.get("scmgit");
 assertThat(gitPlugin.getKey()).isEqualTo("scmgit");
 assertThat(gitPlugin.getInfo().getNonNullJarFile()).exists().isFile();
 assertThat(gitPlugin.getUpdatedAt()).isEqualTo(100L);
 ScannerPlugin javaPlugin = result.get("java");
 assertThat(javaPlugin.getKey()).isEqualTo("java");
 assertThat(javaPlugin.getInfo().getNonNullJarFile()).exists().isFile();
 assertThat(javaPlugin.getUpdatedAt()).isEqualTo(200L);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void create_uninstall_dir() {
 File dir = new File(testFolder.getRoot(), "dir");
 when(fs.getUninstalledPluginsDir()).thenReturn(dir);
 underTest = new PluginUninstaller(serverPluginRepository, fs);
 underTest.start();
 assertThat(dir).isDirectory();
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void shouldNotDumpInIssuesMode() throws Exception {
 when(analysisMode.isIssues()).thenReturn(true);
 ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder());
 publisher.init(writer);
 assertThat(writer.getFileStructure().analysisLog()).doesNotExist();
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void dumpAsCsv_creates_csv_dump_of_score_matrix_if_property_is_true() throws IOException {
 String taskUuid = "acme";
 when(ceTask.getUuid()).thenReturn(taskUuid);
 settings.setProperty("sonar.filemove.dumpCsv", "true");
 underTest.dumpAsCsv(A_SCORE_MATRIX);
 Collection<File> files = listDumpFilesForTaskUuid(taskUuid);
 assertThat(files).hasSize(1);
 assertThat(files.iterator().next()).hasContent(A_SCORE_MATRIX.toCsv(';'));
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void shouldInitRootWorkDirWithCustomAbsoluteFolder() {
 Map<String, String> props = Maps.<String, String>newHashMap();
 props.put("sonar.working.directory", new File("src").getAbsolutePath());
 ProjectReactorBuilder builder = new ProjectReactorBuilder(new ScannerProperties(props), mock(AnalysisWarnings.class));
 File baseDir = new File("target/tmp/baseDir");
 File workDir = builder.initRootProjectWorkDir(baseDir, props);
 assertThat(workDir).isEqualTo(new File("src").getAbsoluteFile());
}

代码示例来源:origin: arquillian/arquillian-cube

@Test
public void should_move_recording_video() throws IOException, NoSuchMethodException {
  final File destination = temporaryFolder.newFolder("destination");
  final File video = temporaryFolder.newFile("file.flv");
  Files.write(video.toPath(), "Hello".getBytes());
  when(seleniumContainers.getVideoRecordingFile()).thenReturn(video.toPath());
  when(after.getTestClass()).thenReturn(new TestClass(VncRecorderLifecycleManagerTest.class));
  when(after.getTestMethod()).thenReturn(
    VncRecorderLifecycleManagerTest.class.getMethod("should_move_recording_video"));
  Map<String, String> conf = new HashMap<>();
  conf.put("videoOutput", destination.getAbsolutePath());
  TestResult testResult = TestResult.passed();
  VncRecorderLifecycleManager vncRecorderLifecycleManager = new VncRecorderLifecycleManager();
  vncRecorderLifecycleManager.vnc = cube;
  vncRecorderLifecycleManager.afterVideoRecordedEvent = event;
  vncRecorderLifecycleManager.stopRecording(after,
    testResult,
    CubeDroneConfiguration.fromMap(conf),
    seleniumContainers
  );
  assertThat(new File(destination,
    "org_arquillian_cube_docker_drone_VncRecorderLifecycleManagerTest_should_move_recording_video.flv"))
    .exists()
    .hasContent("Hello");
}

代码示例来源:origin: zanata/zanata-platform

@Test
public void willDownloadProjectConfigFromServer() throws IOException {
  when(clientFactory.getProjectIterationClient("gcc", "master")).thenReturn(projectIterationClient);
  when(projectIterationClient.sampleConfiguration()).thenReturn(
      readFromClasspath("serverresponse/projectConfig.xml"));
  File configFileDest = new File(tempFolder.getRoot(), "zanata.xml");
  command.downloadZanataXml("gcc", "master", configFileDest);
  assertThat(configFileDest.exists()).isTrue();
  List<String> lines = FileUtils.readLines(configFileDest, Charsets.UTF_8);
  String content = Joiner.on("\n").join(lines);
  assertThat(content).contains("<project>");
  assertThat(opts.getProjectConfig()).isEqualTo(configFileDest);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void create_dir_and_configure_static_directory() throws Exception {
 File dir = temp.newFolder();
 dir.delete();
 underTest.addStaticDir(tomcat, "/deploy", dir);
 assertThat(dir).isDirectory().exists();
 verify(tomcat).addWebapp("/deploy", dir.getAbsolutePath());
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void getLogsDir() throws IOException {
 File dir = temp.newFolder();
 settings.setProperty(PATH_LOGS.getKey(), dir.getAbsolutePath());
 assertThat(underTest.getLogsDir()).isEqualTo(dir);
}

相关文章