Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Modified checkFileIsNotEmpty() method to use canonical file, which will resolve symbolic links, when possible. - Added 4 new unit tests to exercise the modified method. Two of the new unit tests are using new Java 7 IO API and JDK 7 or newer is required to compile them.
- Loading branch information
Showing
3 changed files
with
133 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ target | |
*.iws | ||
*.iml | ||
work | ||
/bin |
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
121 changes: 121 additions & 0 deletions
121
src/test/java/com/thalesgroup/hudson/plugins/xunit/service/XUnitValidationServiceTest.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,121 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2013 Thales Corporate Services SAS * | ||
* Author : Maciek Siemczyk * | ||
* * | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy * | ||
* of this software and associated documentation files (the "Software"), to deal* | ||
* in the Software without restriction, including without limitation the rights * | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * | ||
* copies of the Software, and to permit persons to whom the Software is * | ||
* furnished to do so, subject to the following conditions: * | ||
* * | ||
* The above copyright notice and this permission notice shall be included in * | ||
* all copies or substantial portions of the Software. * | ||
* * | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * | ||
* THE SOFTWARE. * | ||
*******************************************************************************/ | ||
|
||
package com.thalesgroup.hudson.plugins.xunit.service; | ||
|
||
import java.io.*; | ||
import java.nio.file.*; | ||
import java.nio.file.FileSystem; | ||
|
||
import org.junit.*; | ||
|
||
import com.thalesgroup.hudson.plugins.xunit.transformer.TempWorkspace; | ||
|
||
/** | ||
* Unit tests for XUnitValidationService class. | ||
* | ||
* @author Maciek Siemczyk | ||
*/ | ||
public class XUnitValidationServiceTest | ||
{ | ||
/** | ||
* Helper class for creating temporary workspace. | ||
*/ | ||
@Rule | ||
public TempWorkspace tempWorkspace = new TempWorkspace(); | ||
|
||
/** | ||
* System Under Test (SUT). | ||
*/ | ||
private XUnitValidationService xUnitValidationService = new XUnitValidationService(); | ||
|
||
@Test | ||
public void CheckFileIsNotEmpty_GivenEmptyFile_ReturnsFalse() | ||
{ | ||
File testFile = new File(tempWorkspace.getDir(), "empty.txt"); | ||
|
||
Assert.assertFalse( | ||
"CheckFileIsNotEmpty returned true.", | ||
xUnitValidationService.checkFileIsNotEmpty(testFile)); | ||
} | ||
|
||
@Test | ||
public void CheckFileIsNotEmpty_GivenNotEmptyFile_ReturnsTrue() throws Exception | ||
{ | ||
File testFile = CreateNotEmtyFile(); | ||
|
||
Assert.assertTrue( | ||
"CheckFileIsNotEmpty returned false.", | ||
xUnitValidationService.checkFileIsNotEmpty(testFile)); | ||
} | ||
|
||
@Test | ||
public void CheckFileIsNotEmpty_GivenLinkToEmptyFile_ReturnsFalse() throws Exception | ||
{ | ||
FileSystem filesystem = FileSystems.getDefault(); | ||
|
||
File targetFile = new File(tempWorkspace.getDir(), "empty.txt");; | ||
Path targetPath = filesystem.getPath(targetFile.getPath()); | ||
Path linkPath = filesystem.getPath(tempWorkspace.getDir().getPath(), "linkToNotEmpty.txt"); | ||
|
||
Files.createSymbolicLink(linkPath, targetPath); | ||
|
||
Assert.assertFalse( | ||
"CheckFileIsNotEmpty returned true.", | ||
xUnitValidationService.checkFileIsNotEmpty(linkPath.toFile())); | ||
} | ||
|
||
@Test | ||
public void CheckFileIsNotEmpty_GivenLinkToNotEmptyFile_ReturnsTrue() throws Exception | ||
{ | ||
FileSystem filesystem = FileSystems.getDefault(); | ||
|
||
File targetFile = CreateNotEmtyFile(); | ||
Path targetPath = filesystem.getPath(targetFile.getPath()); | ||
Path linkPath = filesystem.getPath(tempWorkspace.getDir().getPath(), "linkToNotEmpty.txt"); | ||
|
||
Files.createSymbolicLink(linkPath, targetPath); | ||
|
||
Assert.assertTrue( | ||
"CheckFileIsNotEmpty returned false.", | ||
xUnitValidationService.checkFileIsNotEmpty(linkPath.toFile())); | ||
} | ||
|
||
/** | ||
* Helper method that will create a file with some text in it. | ||
* | ||
* @return Created file. | ||
* | ||
* @throws Exception when there is a problem with writing to the file. | ||
*/ | ||
private File CreateNotEmtyFile() throws Exception | ||
{ | ||
File testFile = new File(tempWorkspace.getDir(), "notempty.txt"); | ||
|
||
FileOutputStream stream = new FileOutputStream(testFile); | ||
stream.write("This is just not empty test file!".getBytes()); | ||
stream.close(); | ||
|
||
return testFile; | ||
} | ||
} |