1
몇 가지 테스트를 작성하고 싶지만 상위 레벨에서 각각의 파일에 디렉토리 구조를 채워야합니다. 이 경우 각각을 최소한 테스트 해 보겠습니다.JUnit 테스트 검색 폴더 클래스
필터를 통과하는 파일이있는 단일 폴더.
필터를 통과하지 않는 파일이있는 단일 폴더입니다.
각각에 파일이있는 중첩 폴더입니다.
코드 :
class FolderScan implements Runnable {
private String path;
private BlockingQueue<File> queue;
private CountDownLatch latch;
private File endOfWorkFile;
private List<Checker> checkers;
FolderScan(String path, BlockingQueue<File> queue, CountDownLatch latch,
File endOfWorkFile) {
this.path = path;
this.queue = queue;
this.latch = latch;
this.endOfWorkFile = endOfWorkFile;
checkers = new ArrayList<Checker>(Arrays.asList(new ExtentionsCheker(),
new ProbeContentTypeCheker(), new CharsetDetector()));
}
public FolderScan() {
}
@Override
public void run() {
findFiles(path);
queue.add(endOfWorkFile);
latch.countDown();
}
private void findFiles(String path) {
boolean checksPassed = true;
File root;
try {
root = new File(path);
File[] list = root.listFiles();
for (File currentFile : list) {
if (currentFile.isDirectory()) {
findFiles(currentFile.getAbsolutePath());
} else {
for (Checker currentChecker : checkers) {
if (!currentChecker.check(currentFile)) {
checksPassed = false;
break;
}
}
if (checksPassed)
queue.put(currentFile);
}
}
} catch (InterruptedException | RuntimeException e) {
System.out.println("Wrong input !!!");
e.printStackTrace();
}
}
}
질문 :
- 어떻게 각각의 폴더에 파일을 만들 수?
- 큐에 이 포함되어 있음을 증명하려면 원하는 File 개체를 사용 하시겠습니까?
- 대기열의 마지막 요소는 '트리거'파일입니까?
새로운 AllwaysPassesBlocker()는 무엇을 의미합니까? '예상'유형은 무엇입니까? –
"차단기"를 새 생성자로 전달하고 항상 통과하는 새로운 "차단기"를 생성한다는 의미입니다. 예상되는 BlockingQueue입니다. –
쓸 수 있습니까? 나는 잡히지 않았다. –