use of java.util.Scanner in project learning-spark by databricks.
the class ChapterSixExample method loadCallSignTable.
static String[] loadCallSignTable() throws FileNotFoundException {
Scanner callSignTbl = new Scanner(new File("./files/callsign_tbl_sorted"));
ArrayList<String> callSignList = new ArrayList<String>();
while (callSignTbl.hasNextLine()) {
callSignList.add(callSignTbl.nextLine());
}
return callSignList.toArray(new String[0]);
}
use of java.util.Scanner in project che by eclipse.
the class ProjectServiceTest method testMoveFileWithRenameAndOverwrite.
@Test
public void testMoveFileWithRenameAndOverwrite() throws Exception {
RegisteredProject myProject = pm.getProject("my_project");
myProject.getBaseFolder().createFolder("a/b/c");
// File names
String originFileName = "test.txt";
String destinationFileName = "overwriteMe.txt";
// File contents
String originContent = "to be or not no be";
String overwrittenContent = "that is the question";
((FolderEntry) myProject.getBaseFolder().getChild("a/b")).createFile(originFileName, originContent.getBytes(Charset.defaultCharset()));
((FolderEntry) myProject.getBaseFolder().getChild("a/b/c")).createFile(destinationFileName, overwrittenContent.getBytes(Charset.defaultCharset()));
Map<String, List<String>> headers = new HashMap<>();
headers.put(CONTENT_TYPE, singletonList(APPLICATION_JSON));
MoveOptions descriptor = DtoFactory.getInstance().createDto(MoveOptions.class);
descriptor.setName(destinationFileName);
descriptor.setOverWrite(true);
ContainerResponse response = launcher.service(POST, "http://localhost:8080/api/project/move/my_project/a/b/" + originFileName + "?to=/my_project/a/b/c", "http://localhost:8080/api", headers, DtoFactory.getInstance().toJson(descriptor).getBytes(Charset.defaultCharset()), null);
assertEquals(response.getStatus(), 201, "Error: " + response.getEntity());
assertEquals(response.getHttpHeaders().getFirst("Location"), URI.create("http://localhost:8080/api/project/file/my_project/a/b/c/" + destinationFileName));
// new
assertNotNull(myProject.getBaseFolder().getChild("a/b/c/" + destinationFileName));
Scanner inputStreamScanner = null;
String theFirstLineFromDestinationFile;
try {
inputStreamScanner = new Scanner(myProject.getBaseFolder().getChild("a/b/c/" + destinationFileName).getVirtualFile().getContent());
theFirstLineFromDestinationFile = inputStreamScanner.nextLine();
// destination should contain original file's content
assertEquals(theFirstLineFromDestinationFile, originContent);
} catch (ForbiddenException | ServerException e) {
Assert.fail(e.getMessage());
} finally {
if (inputStreamScanner != null) {
inputStreamScanner.close();
}
}
}
use of java.util.Scanner in project cucumber-jvm by cucumber.
the class JSONPrettyFormatterTest method featureWithOutlineTest.
@Test
public void featureWithOutlineTest() throws Exception {
File report = runFeaturesWithJSONPrettyFormatter(asList("cucumber/runtime/formatter/JSONPrettyFormatterTest.feature"));
String expected = new Scanner(getClass().getResourceAsStream("JSONPrettyFormatterTest.json"), "UTF-8").useDelimiter("\\A").next();
String actual = new Scanner(report, "UTF-8").useDelimiter("\\A").next();
assertPrettyJsonEquals(expected, actual);
}
use of java.util.Scanner in project cucumber-jvm by cucumber.
the class JUnitFormatterTest method should_format_scenario_outlines_with_the_junit_runner.
@Test
public void should_format_scenario_outlines_with_the_junit_runner() throws Exception {
final File report = File.createTempFile("cucumber-jvm-junit", ".xml");
final JUnitFormatter junitFormatter = createJUnitFormatter(report);
// The JUnit runner will not call scenarioOutline() and examples() before executing the examples scenarios
junitFormatter.uri(uri());
junitFormatter.feature(feature("feature name"));
junitFormatter.scenario(scenario("Scenario Outline", "outline name"));
junitFormatter.step(step("keyword ", "step name \"arg1\""));
junitFormatter.match(match());
junitFormatter.result(result("passed"));
junitFormatter.scenario(scenario("Scenario Outline", "outline name"));
junitFormatter.step(step("keyword ", "step name \"arg2\""));
junitFormatter.match(match());
junitFormatter.result(result("passed"));
junitFormatter.eof();
junitFormatter.done();
junitFormatter.close();
String actual = new Scanner(new FileInputStream(report), "UTF-8").useDelimiter("\\A").next();
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<testsuite failures=\"0\" tests=\"2\" name=\"cucumber.runtime.formatter.JUnitFormatter\" skipped=\"0\" time=\"0\">\n" + " <testcase classname=\"feature name\" name=\"outline name\" time=\"0\">\n" + " <system-out><![CDATA[" + "keyword step name \"arg1\"....................................................passed\n" + "]]></system-out>\n" + " </testcase>\n" + " <testcase classname=\"feature name\" name=\"outline name 2\" time=\"0\">\n" + " <system-out><![CDATA[" + "keyword step name \"arg2\"....................................................passed\n" + "]]></system-out>\n" + " </testcase>\n" + "</testsuite>\n";
assertXmlEqual(expected, actual);
}
use of java.util.Scanner in project cucumber-jvm by cucumber.
the class TestNGFormatterTest method runFeatureWithStrictTestNGFormatter.
private String runFeatureWithStrictTestNGFormatter(CucumberFeature feature, Map<String, Result> stepsToResult, long stepDuration) throws IOException, Throwable, FileNotFoundException {
final File tempFile = File.createTempFile("cucumber-jvm-testng", ".xml");
final TestNGFormatter formatter = new TestNGFormatter(toURL(tempFile.getAbsolutePath()));
formatter.setStrict(true);
TestHelper.runFeatureWithFormatter(feature, stepsToResult, Collections.<SimpleEntry<String, Result>>emptyList(), stepDuration, formatter, formatter);
return new Scanner(new FileInputStream(tempFile), "UTF-8").useDelimiter("\\A").next();
}
Aggregations