fixed unit tests

This commit is contained in:
jomu
2013-04-14 13:40:44 +00:00
parent bd2d7380e4
commit 923dba1c1b
5 changed files with 16 additions and 14 deletions

View File

@ -9,25 +9,28 @@ import java.io.InputStream;
* @author joern@muehlencord.de * @author joern@muehlencord.de
*/ */
public class DefaultTest { public class DefaultTest {
public String readContentFromFile(String name) throws IOException { public String readContentFromFile(String name) throws IOException {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
byte[] buffer = new byte[4096]; byte[] buffer = new byte[4096];
InputStream is = DefaultTest.class.getResourceAsStream(name);
if (is == null) { if (DefaultTest.class.getResourceAsStream(name) == null) {
throw new IOException("File " + name + " not found"); throw new IOException("File " + name + " not found");
} }
BufferedInputStream bis = new BufferedInputStream(is);
int bytesRead = 0; try (InputStream is = DefaultTest.class.getResourceAsStream(name);
while ((bytesRead = bis.read(buffer)) != -1) { BufferedInputStream bis = new BufferedInputStream(is);) {
sb.append(new String(buffer, 0, bytesRead)); int bytesRead = 0;
while (bytesRead != -1) {
bytesRead = bis.read(buffer);
if (bytesRead != -1) {
sb.append(new String(buffer, 0, bytesRead));
}
}
bis.close();
} }
bis.close();
is.close();
return sb.toString(); return sb.toString();
} }
} }

View File

@ -15,7 +15,7 @@ public class StringUtilTest extends DefaultTest {
@Test @Test
public void testGetValueBetweenKeywords() throws ParseException, IOException { public void testGetValueBetweenKeywords() throws ParseException, IOException {
String content = readContentFromFile("/test.txt"); String content = readContentFromFile("test.txt");
String ipAddress = StringUtil.getValueBetweenKeywords(content, "The IP", "has just"); String ipAddress = StringUtil.getValueBetweenKeywords(content, "The IP", "has just");
assertEquals ("ipAddress", "222.184.230.118", ipAddress); assertEquals ("ipAddress", "222.184.230.118", ipAddress);

View File

@ -26,8 +26,7 @@ public class FileUtilTest {
public void testGetFilesFromDirecotry() throws FileHandlingException, URISyntaxException { public void testGetFilesFromDirecotry() throws FileHandlingException, URISyntaxException {
System.out.println("testGetFilesFromDirectory"); System.out.println("testGetFilesFromDirectory");
URL url = getClass().getResource("testfile.txt");
URL url = getClass().getResource("/testfile.txt");
File testFile = new File(url.getFile()); File testFile = new File(url.getFile());
List<File> fileList = FileUtil.getFilesFromDirecotry(testFile.getParent(), ".*.java"); List<File> fileList = FileUtil.getFilesFromDirecotry(testFile.getParent(), ".*.java");