fixed unit tests
This commit is contained in:
@ -10,24 +10,27 @@ import java.io.InputStream;
|
|||||||
*/
|
*/
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
@ -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");
|
||||||
|
|||||||
Reference in New Issue
Block a user