aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.report.test/src/org/jacoco/report/DirectorySourceFileLocatorTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'org.jacoco.report.test/src/org/jacoco/report/DirectorySourceFileLocatorTest.java')
-rw-r--r--org.jacoco.report.test/src/org/jacoco/report/DirectorySourceFileLocatorTest.java32
1 files changed, 22 insertions, 10 deletions
diff --git a/org.jacoco.report.test/src/org/jacoco/report/DirectorySourceFileLocatorTest.java b/org.jacoco.report.test/src/org/jacoco/report/DirectorySourceFileLocatorTest.java
index a93e5c3a..b8eea850 100644
--- a/org.jacoco.report.test/src/org/jacoco/report/DirectorySourceFileLocatorTest.java
+++ b/org.jacoco.report.test/src/org/jacoco/report/DirectorySourceFileLocatorTest.java
@@ -1,13 +1,14 @@
/*******************************************************************************
- * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
+ * Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors
+ * This program and the accompanying materials are made available under
+ * the terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Marc R. Hoffmann - initial API and implementation
- *
+ *
*******************************************************************************/
package org.jacoco.report;
@@ -45,13 +46,24 @@ public class DirectorySourceFileLocatorTest {
}
@Test
- public void testGetSourceFileNegative() throws IOException {
+ public void getSourceFile_should_return_null_when_source_does_not_exist()
+ throws IOException {
assertNull(locator.getSourceFile("org/jacoco/example",
"DoesNotExist.java"));
}
@Test
- public void testGetSourceFile() throws IOException {
+ public void getSourceFile_should_return_null_when_source_is_folder()
+ throws IOException {
+ final File file = new File(sourceFolder.getRoot(),
+ "org/jacoco/example");
+ file.mkdirs();
+ assertNull(locator.getSourceFile("org/jacoco", "example"));
+ }
+
+ @Test
+ public void getSourceFile_should_return_content_when_file_exists()
+ throws IOException {
createFile("org/jacoco/example/Test.java");
final Reader source = locator.getSourceFile("org/jacoco/example",
"Test.java");
@@ -61,8 +73,8 @@ public class DirectorySourceFileLocatorTest {
private void createFile(String path) throws IOException {
final File file = new File(sourceFolder.getRoot(), path);
file.getParentFile().mkdirs();
- final Writer writer = new OutputStreamWriter(
- new FileOutputStream(file), "UTF-8");
+ final Writer writer = new OutputStreamWriter(new FileOutputStream(file),
+ "UTF-8");
writer.write("Source");
writer.close();
}