fixed unit tests
This commit is contained in:
@ -9,25 +9,28 @@ import java.io.InputStream;
|
||||
* @author joern@muehlencord.de
|
||||
*/
|
||||
public class DefaultTest {
|
||||
|
||||
public String readContentFromFile(String name) throws IOException {
|
||||
|
||||
public String readContentFromFile(String name) throws IOException {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
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");
|
||||
}
|
||||
BufferedInputStream bis = new BufferedInputStream(is);
|
||||
|
||||
int bytesRead = 0;
|
||||
while ((bytesRead = bis.read(buffer)) != -1) {
|
||||
sb.append(new String(buffer, 0, bytesRead));
|
||||
try (InputStream is = DefaultTest.class.getResourceAsStream(name);
|
||||
BufferedInputStream bis = new BufferedInputStream(is);) {
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ public class StringUtilTest extends DefaultTest {
|
||||
|
||||
@Test
|
||||
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");
|
||||
assertEquals ("ipAddress", "222.184.230.118", ipAddress);
|
||||
|
||||
@ -26,8 +26,7 @@ public class FileUtilTest {
|
||||
public void testGetFilesFromDirecotry() throws FileHandlingException, URISyntaxException {
|
||||
System.out.println("testGetFilesFromDirectory");
|
||||
|
||||
|
||||
URL url = getClass().getResource("/testfile.txt");
|
||||
URL url = getClass().getResource("testfile.txt");
|
||||
File testFile = new File(url.getFile());
|
||||
|
||||
List<File> fileList = FileUtil.getFilesFromDirecotry(testFile.getParent(), ".*.java");
|
||||
|
||||
Reference in New Issue
Block a user