Here you can find the source of listSteps(Path scenarioDirectory)
Parameter | Description |
---|---|
scenarioDirectory | the directory to scan |
public static Iterable<Path> listSteps(Path scenarioDirectory)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileFilter; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import static java.util.Arrays.sort; public class Main { private static final FileFilter STEP_FILTER = new FileFilter() { @Override/*from ww w.ja va2 s . co m*/ public boolean accept(File pathname) { return pathname.isFile() && pathname.canRead() && pathname.getName().matches("\\d+_.*"); } }; /** * Lists all scenario steps within the given directory path. * * @param scenarioDirectory the directory to scan * @return all steps sorted in lexicographical order */ public static Iterable<Path> listSteps(Path scenarioDirectory) { if (!Files.isDirectory(scenarioDirectory)) { throw new IllegalArgumentException( String.format("Path '%s' is not a directory.", scenarioDirectory.toAbsolutePath())); } File[] list = scenarioDirectory.toFile().listFiles(STEP_FILTER); if (list == null || list.length == 0) { throw new IllegalStateException( String.format("No test steps found in directory: '%s'", scenarioDirectory.toAbsolutePath())); } sort(list); return toPaths(list); } /** * Converts the given files to a sequence of paths. * * @param files the files * @return the paths */ private static Iterable<Path> toPaths(File... files) { List<Path> paths = new ArrayList<>(files.length); for (File file : files) { paths.add(file.toPath()); } return paths; } }