Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue: #79 ------------------------------------------------------------------------ On behalf of the community, the JUnit Lambda Team thanks Samuraism, Inc. (http://samuraism.com/) for supporting the JUnit crowdfunding campaign! ------------------------------------------------------------------------
- Loading branch information
1 parent
5df9d78
commit 2df8323
Showing
6 changed files
with
195 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
junit-tests/src/test/java/org/junit/gen5/engine/FileSystemSourceTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2015-2016 the original author or authors. | ||
* | ||
* 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 | ||
*/ | ||
|
||
package org.junit.gen5.engine; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.gen5.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
import java.io.File; | ||
|
||
import org.junit.gen5.api.Test; | ||
import org.junit.gen5.engine.FileSystemSource.FilePosition; | ||
|
||
class FileSystemSourceTests { | ||
|
||
@Test | ||
void nullSourceFileOrDirectoryYieldsException() { | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
new FileSystemSource(null); | ||
}); | ||
} | ||
|
||
@Test | ||
void directory() { | ||
File directory = new File("."); | ||
FileSystemSource source = new FileSystemSource(directory); | ||
|
||
assertTrue(source.isDirectory()); | ||
assertFalse(source.isFile()); | ||
assertFalse(source.isFilePosition()); | ||
assertFalse(source.isJavaClass()); | ||
assertFalse(source.isJavaMethod()); | ||
|
||
assertEquals(directory, source.getFile()); | ||
assertThat(source.getPosition()).isEmpty(); | ||
|
||
assertEquals(directory.getAbsolutePath(), source.toString()); | ||
} | ||
|
||
@Test | ||
void fileWithoutPosition() throws Exception { | ||
File file = spy(new File("test.txt")); | ||
when(file.isDirectory()).thenReturn(false); | ||
when(file.isFile()).thenReturn(true); | ||
|
||
FileSystemSource source = new FileSystemSource(file); | ||
|
||
assertFalse(source.isDirectory()); | ||
assertTrue(source.isFile()); | ||
assertFalse(source.isFilePosition()); | ||
assertFalse(source.isJavaClass()); | ||
assertFalse(source.isJavaMethod()); | ||
|
||
assertEquals(file, source.getFile()); | ||
assertThat(source.getPosition()).isEmpty(); | ||
|
||
assertEquals(file.getAbsolutePath(), source.toString()); | ||
} | ||
|
||
@Test | ||
void fileWithPosition() throws Exception { | ||
File file = new File("test.txt"); | ||
FilePosition position = new FilePosition(42, 23); | ||
|
||
FileSystemSource source = new FileSystemSource(file, position); | ||
|
||
assertTrue(source.isFilePosition()); | ||
assertEquals(file, source.getFile()); | ||
assertThat(source.getPosition()).hasValue(position); | ||
assertEquals(file.getAbsolutePath() + " [42:23]", source.toString()); | ||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
junit-tests/src/test/java/org/junit/gen5/engine/JavaSourceTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2015-2016 the original author or authors. | ||
* | ||
* 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 | ||
*/ | ||
|
||
package org.junit.gen5.engine; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.gen5.api.Assertions.*; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import org.junit.gen5.api.Test; | ||
import org.junit.gen5.api.TestName; | ||
|
||
class JavaSourceTests { | ||
|
||
@Test | ||
void classSource() { | ||
Class<JavaSourceTests> testClass = JavaSourceTests.class; | ||
JavaSource source = new JavaSource(testClass); | ||
|
||
assertTrue(source.isJavaClass()); | ||
assertFalse(source.isJavaMethod()); | ||
assertFalse(source.isDirectory()); | ||
assertFalse(source.isFile()); | ||
assertFalse(source.isFilePosition()); | ||
|
||
assertThat(source.getJavaClass()).hasValue(testClass); | ||
assertThat(source.getJavaMethodName()).isEmpty(); | ||
assertThat(source.getJavaMethodParameterTypes()).isEmpty(); | ||
|
||
assertEquals(testClass.getName(), source.toString()); | ||
} | ||
|
||
@Test | ||
void methodSource(@TestName String testName) throws Exception { | ||
Class<JavaSourceTests> testClass = JavaSourceTests.class; | ||
Method testMethod = testClass.getDeclaredMethod(testName, String.class); | ||
JavaSource source = new JavaSource(testMethod); | ||
|
||
assertTrue(source.isJavaMethod()); | ||
assertFalse(source.isJavaClass()); | ||
assertFalse(source.isDirectory()); | ||
assertFalse(source.isFile()); | ||
assertFalse(source.isFilePosition()); | ||
|
||
assertThat(source.getJavaClass()).hasValue(testClass); | ||
assertThat(source.getJavaMethodName()).hasValue(testName); | ||
assertThat(source.getJavaMethodParameterTypes().get()).containsExactly(String.class); | ||
|
||
assertEquals(testClass.getName() + "#" + testName + "(" + String.class.getName() + ")", source.toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters