Search in sources :

Example 86 with Scanner

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]);
}
Also used : Scanner(java.util.Scanner) ArrayList(java.util.ArrayList) File(java.io.File)

Example 87 with Scanner

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();
        }
    }
}
Also used : Scanner(java.util.Scanner) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) ContainerResponse(org.everrest.core.impl.ContainerResponse) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) MoveOptions(org.eclipse.che.api.project.shared.dto.MoveOptions) Test(org.testng.annotations.Test)

Example 88 with Scanner

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);
}
Also used : Scanner(java.util.Scanner) File(java.io.File) Test(org.junit.Test)

Example 89 with Scanner

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);
}
Also used : Scanner(java.util.Scanner) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 90 with Scanner

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();
}
Also used : Scanner(java.util.Scanner) File(java.io.File) FileInputStream(java.io.FileInputStream) Result(gherkin.formatter.model.Result)

Aggregations

Scanner (java.util.Scanner)862 File (java.io.File)135 ArrayList (java.util.ArrayList)77 IOException (java.io.IOException)72 Test (org.junit.Test)70 NoSuchElementException (java.util.NoSuchElementException)59 InputStream (java.io.InputStream)54 ServiceBuilder (com.github.scribejava.core.builder.ServiceBuilder)49 OAuthRequest (com.github.scribejava.core.model.OAuthRequest)49 Response (com.github.scribejava.core.model.Response)49 FileNotFoundException (java.io.FileNotFoundException)47 InputMismatchException (java.util.InputMismatchException)47 HashMap (java.util.HashMap)35 FileInputStream (java.io.FileInputStream)33 OAuth20Service (com.github.scribejava.core.oauth.OAuth20Service)31 OAuth2AccessToken (com.github.scribejava.core.model.OAuth2AccessToken)29 Locale (java.util.Locale)24 BigInteger (java.math.BigInteger)23 List (java.util.List)22 OAuth1AccessToken (com.github.scribejava.core.model.OAuth1AccessToken)18