ru.yandex.qatools.allure.data.io.TestSuiteReader Maven / Gradle / Ivy
package ru.yandex.qatools.allure.data.io;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.yandex.qatools.allure.commons.AllureFileUtils;
import ru.yandex.qatools.allure.model.TestSuiteResult;
import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import static ru.yandex.qatools.allure.commons.AllureFileUtils.unmarshal;
/**
* eroshenkoam
* 02/02/15
*/
public class TestSuiteReader implements Reader {
private static final Logger LOGGER = LoggerFactory.getLogger(TestSuiteReader.class);
private final Iterator testSuiteResultFiles;
@Inject
public TestSuiteReader(@ResultDirectories File... resultDirectories) {
testSuiteResultFiles = AllureFileUtils.listTestSuiteFiles(resultDirectories).iterator();
}
@Override
public Iterator iterator() {
return new TestSuiteResultIterator();
}
private class TestSuiteResultIterator implements Iterator {
@Override
public boolean hasNext() {
return testSuiteResultFiles.hasNext();
}
@Override
public TestSuiteResult next() {
if (!hasNext()) {
return null;
}
File next = testSuiteResultFiles.next();
try {
return unmarshal(next);
} catch (IOException e) {
LOGGER.warn(String.format("Could not read <%s> file", next.getAbsoluteFile()), e);
return next();
}
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy