From d8e45acc9773b6b8c9d70d39493795a1dbdffb3e Mon Sep 17 00:00:00 2001 From: Quadros de Souza Date: Sun, 11 Sep 2022 14:32:46 -0300 Subject: [PATCH 1/7] Defining proper configuration for sonarqube executions --- .github/workflows/maven.yml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index adc1f6c..eaf6a21 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -40,4 +40,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - run: mvn -P coverage -X -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=gherkin-by-example_java-cucumber + run: mvn -P coverage -X -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=loureqdsz_java-cucumber-lourenco-souza diff --git a/pom.xml b/pom.xml index 2491d93..4c4110f 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ 4.13.2 UTF-8 - gherkin-by-example + loureqdsz https://sonarcloud.io From 0af2b20f0343d6c46767fc895a5d149179a0356e Mon Sep 17 00:00:00 2001 From: Quadros de Souza Date: Sun, 11 Sep 2022 15:48:03 -0300 Subject: [PATCH 2/7] adding basic files and configurations --- .../br/masmangan/beecrowd/bee1060/Main.java | 52 +++++++++++++++++++ .../beecrowd/bee1060/RunCucumberTest.java | 31 +++++++++++ .../beecrowd/bee1060/bee1060Steps.java | 52 +++++++++++++++++++ .../beecrowd/bee1060/bee1060.feature | 18 +++++++ 4 files changed, 153 insertions(+) create mode 100644 src/main/java/br/masmangan/beecrowd/bee1060/Main.java create mode 100644 src/test/java/br/masmangan/beecrowd/bee1060/RunCucumberTest.java create mode 100644 src/test/java/br/masmangan/beecrowd/bee1060/bee1060Steps.java create mode 100644 src/test/resources/br/masmangan/beecrowd/bee1060/bee1060.feature diff --git a/src/main/java/br/masmangan/beecrowd/bee1060/Main.java b/src/main/java/br/masmangan/beecrowd/bee1060/Main.java new file mode 100644 index 0000000..8abff53 --- /dev/null +++ b/src/main/java/br/masmangan/beecrowd/bee1060/Main.java @@ -0,0 +1,52 @@ +package br.masmangan.beecrowd.bee1060; + +import java.util.ArrayList; +import java.util.Scanner; + +import static java.lang.System.in; +import static java.lang.System.out; + +public class Main { + public static ArrayList numbers = new ArrayList(); + + private Main() { + + } + + public static void main(String[] args) { + numbers = readNumbers(); + hasPositiveNumbers(numbers); + } + + private static ArrayList readNumbers () { + Scanner scanner = new Scanner(in); + + ArrayList inputedNumbers = new ArrayList(); + + out.println(" ---- Type six numbers to start the program, write one a one, typing the number and pressing enter. "); + + inputedNumbers.add(scanner.nextInt()); + inputedNumbers.add(scanner.nextInt()); + inputedNumbers.add(scanner.nextInt()); + inputedNumbers.add(scanner.nextInt()); + inputedNumbers.add(scanner.nextInt()); + inputedNumbers.add(scanner.nextInt()); + + scanner.close(); + + return inputedNumbers; + } + + private static void hasPositiveNumbers (ArrayList numbers) { + int count = 0; + + for (int i=0; i= 0) { + count++; + } + } + + out.printf("The list have %d positive numbers.%n", count); + } + +} diff --git a/src/test/java/br/masmangan/beecrowd/bee1060/RunCucumberTest.java b/src/test/java/br/masmangan/beecrowd/bee1060/RunCucumberTest.java new file mode 100644 index 0000000..b28422b --- /dev/null +++ b/src/test/java/br/masmangan/beecrowd/bee1060/RunCucumberTest.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2021, Gherkin By Example and/or its contributors. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this code. If not, see . + * + * Please visit Gherkin By Example at https://github.com/gherkin-by-example + * if you need additional information or have any questions. + */ +package br.masmangan.beecrowd.bee1060; + +import io.cucumber.junit.Cucumber; +import io.cucumber.junit.CucumberOptions; +import org.junit.runner.RunWith; + +@RunWith(Cucumber.class) +@CucumberOptions(plugin = {"pretty"}) +public class RunCucumberTest { + +} \ No newline at end of file diff --git a/src/test/java/br/masmangan/beecrowd/bee1060/bee1060Steps.java b/src/test/java/br/masmangan/beecrowd/bee1060/bee1060Steps.java new file mode 100644 index 0000000..527a0ca --- /dev/null +++ b/src/test/java/br/masmangan/beecrowd/bee1060/bee1060Steps.java @@ -0,0 +1,52 @@ +package br.masmangan.beecrowd.bee1060; + +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; + +import java.io.*; +import java.nio.charset.StandardCharsets; + +import static org.junit.Assert.assertEquals; + +public class bee1060Steps { + + private String input; + private String actual; + + @Given("input is") + public void input_is(String input) { + this.input = input; + } + + @When("program runs") + public void program_runs() throws IOException { + InputStream inputStream = new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)); + + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + + PrintStream outputStream = new PrintStream(byteArrayOutputStream); + + PrintStream previousOut = System.out; + InputStream previousIn = System.in; + + System.setIn(inputStream); + System.setOut(outputStream); + + Main.main(null); + + actual = byteArrayOutputStream.toString(); + + inputStream.close(); + outputStream.close(); + + System.setOut(previousOut); + System.setIn(previousIn); + } + + @Then("output should be") + public void output_should_be(String expected) { + assertEquals(expected, actual); + } + +} diff --git a/src/test/resources/br/masmangan/beecrowd/bee1060/bee1060.feature b/src/test/resources/br/masmangan/beecrowd/bee1060/bee1060.feature new file mode 100644 index 0000000..9f76a53 --- /dev/null +++ b/src/test/resources/br/masmangan/beecrowd/bee1060/bee1060.feature @@ -0,0 +1,18 @@ +Feature: Bee1060 + Scenario: Program Runs + Given input is + """ + 1 + 2 + 3 + 4 + 5 + 6 + """ + When Program Runs + Then The output should be + """ + The list have 6 positive numbers. + + """ + \ No newline at end of file From a0c3815fedc62fe9666493679cfd5e27e480e064 Mon Sep 17 00:00:00 2001 From: Quadros de Souza Date: Sun, 11 Sep 2022 15:54:39 -0300 Subject: [PATCH 3/7] change some code implementation --- .../br/masmangan/beecrowd/bee1060/Main.java | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/main/java/br/masmangan/beecrowd/bee1060/Main.java b/src/main/java/br/masmangan/beecrowd/bee1060/Main.java index 8abff53..6cd32e6 100644 --- a/src/main/java/br/masmangan/beecrowd/bee1060/Main.java +++ b/src/main/java/br/masmangan/beecrowd/bee1060/Main.java @@ -7,23 +7,15 @@ import static java.lang.System.out; public class Main { - public static ArrayList numbers = new ArrayList(); - private Main() { } public static void main(String[] args) { - numbers = readNumbers(); - hasPositiveNumbers(numbers); - } - - private static ArrayList readNumbers () { Scanner scanner = new Scanner(in); - ArrayList inputedNumbers = new ArrayList(); - out.println(" ---- Type six numbers to start the program, write one a one, typing the number and pressing enter. "); + out.printf("Type six numbers to start the program, write one a one, typing the number and pressing enter.%n"); inputedNumbers.add(scanner.nextInt()); inputedNumbers.add(scanner.nextInt()); @@ -34,19 +26,13 @@ private static ArrayList readNumbers () { scanner.close(); - return inputedNumbers; - } - - private static void hasPositiveNumbers (ArrayList numbers) { int count = 0; - - for (int i=0; i= 0) { + for (int i=0; i= 0) { count++; } } out.printf("The list have %d positive numbers.%n", count); - } - + } } From c1ec4c3a80b6a9a8b8b6ae7fc5001bbd535ea5a4 Mon Sep 17 00:00:00 2001 From: Quadros de Souza Date: Sun, 11 Sep 2022 15:59:04 -0300 Subject: [PATCH 4/7] changing steps spelling --- .../java/br/masmangan/beecrowd/bee1060/bee1060Steps.java | 6 +++--- .../resources/br/masmangan/beecrowd/bee1060/bee1060.feature | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/br/masmangan/beecrowd/bee1060/bee1060Steps.java b/src/test/java/br/masmangan/beecrowd/bee1060/bee1060Steps.java index 527a0ca..b502634 100644 --- a/src/test/java/br/masmangan/beecrowd/bee1060/bee1060Steps.java +++ b/src/test/java/br/masmangan/beecrowd/bee1060/bee1060Steps.java @@ -14,12 +14,12 @@ public class bee1060Steps { private String input; private String actual; - @Given("input is") + @Given("The input is") public void input_is(String input) { this.input = input; } - @When("program runs") + @When("Program runs") public void program_runs() throws IOException { InputStream inputStream = new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)); @@ -44,7 +44,7 @@ public void program_runs() throws IOException { System.setIn(previousIn); } - @Then("output should be") + @Then("The output should be") public void output_should_be(String expected) { assertEquals(expected, actual); } diff --git a/src/test/resources/br/masmangan/beecrowd/bee1060/bee1060.feature b/src/test/resources/br/masmangan/beecrowd/bee1060/bee1060.feature index 9f76a53..bc3855b 100644 --- a/src/test/resources/br/masmangan/beecrowd/bee1060/bee1060.feature +++ b/src/test/resources/br/masmangan/beecrowd/bee1060/bee1060.feature @@ -1,6 +1,6 @@ Feature: Bee1060 Scenario: Program Runs - Given input is + Given The input is """ 1 2 From a4c3bdae4d317e8f07a45447ffb871cdfe73a74c Mon Sep 17 00:00:00 2001 From: Quadros de Souza Date: Sun, 11 Sep 2022 16:08:21 -0300 Subject: [PATCH 5/7] changing some feature code --- .../beecrowd/bee1060/bee1060.feature | 61 +++++++++++++------ 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/src/test/resources/br/masmangan/beecrowd/bee1060/bee1060.feature b/src/test/resources/br/masmangan/beecrowd/bee1060/bee1060.feature index bc3855b..d3e0d77 100644 --- a/src/test/resources/br/masmangan/beecrowd/bee1060/bee1060.feature +++ b/src/test/resources/br/masmangan/beecrowd/bee1060/bee1060.feature @@ -1,18 +1,45 @@ -Feature: Bee1060 - Scenario: Program Runs - Given The input is - """ - 1 - 2 - 3 - 4 - 5 - 6 - """ - When Program Runs - Then The output should be - """ - The list have 6 positive numbers. +# +# Copyright (C) 2021, Gherkin By Example and/or its contributors. All rights reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# This software is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This code is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this code. If not, see . +# +# Please visit Gherkin By Example at https://github.com/gherkin-by-example +# if you need additional information or have any questions. +@system +Feature: Bee1060 CLI - """ - \ No newline at end of file + Narrative: + + In order to verify the amount of positive numbers + inserted at the beginning of the program, we create this program + to check how many positive numbers there are in the inserted list. + + Scenario: Run program with input 6, 1, -1, 19, 9, 5 (pos, pos) + + Given The input is +""" +6 +1 +-1 +19 +9 +5 +""" + When Program runs + Then The output should be +""" +The list have 5 positive numbers. + +""" \ No newline at end of file From f6242324c49c70850b578ddee4a38e33ff61fa5b Mon Sep 17 00:00:00 2001 From: Quadros de Souza Date: Sun, 11 Sep 2022 16:11:09 -0300 Subject: [PATCH 6/7] remove useless print information --- src/main/java/br/masmangan/beecrowd/bee1060/Main.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/br/masmangan/beecrowd/bee1060/Main.java b/src/main/java/br/masmangan/beecrowd/bee1060/Main.java index 6cd32e6..2a2858a 100644 --- a/src/main/java/br/masmangan/beecrowd/bee1060/Main.java +++ b/src/main/java/br/masmangan/beecrowd/bee1060/Main.java @@ -15,8 +15,6 @@ public static void main(String[] args) { Scanner scanner = new Scanner(in); ArrayList inputedNumbers = new ArrayList(); - out.printf("Type six numbers to start the program, write one a one, typing the number and pressing enter.%n"); - inputedNumbers.add(scanner.nextInt()); inputedNumbers.add(scanner.nextInt()); inputedNumbers.add(scanner.nextInt()); From 67da114d52f2459565af1366e0de8953d938646b Mon Sep 17 00:00:00 2001 From: Quadros de Souza Date: Mon, 12 Sep 2022 19:52:47 -0300 Subject: [PATCH 7/7] solving some syntax problems --- .../br/masmangan/beecrowd/bee1060/Main.java | 18 +++++++++--------- .../masmangan/beecrowd/bee1060/bee1060.feature | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/br/masmangan/beecrowd/bee1060/Main.java b/src/main/java/br/masmangan/beecrowd/bee1060/Main.java index 2a2858a..71482be 100644 --- a/src/main/java/br/masmangan/beecrowd/bee1060/Main.java +++ b/src/main/java/br/masmangan/beecrowd/bee1060/Main.java @@ -13,24 +13,24 @@ private Main() { public static void main(String[] args) { Scanner scanner = new Scanner(in); - ArrayList inputedNumbers = new ArrayList(); + ArrayList inputedNumbers = new ArrayList(); - inputedNumbers.add(scanner.nextInt()); - inputedNumbers.add(scanner.nextInt()); - inputedNumbers.add(scanner.nextInt()); - inputedNumbers.add(scanner.nextInt()); - inputedNumbers.add(scanner.nextInt()); - inputedNumbers.add(scanner.nextInt()); + inputedNumbers.add(scanner.nextDouble()); + inputedNumbers.add(scanner.nextDouble()); + inputedNumbers.add(scanner.nextDouble()); + inputedNumbers.add(scanner.nextDouble()); + inputedNumbers.add(scanner.nextDouble()); + inputedNumbers.add(scanner.nextDouble()); scanner.close(); int count = 0; for (int i=0; i= 0) { + if (inputedNumbers.get(i) > 0) { count++; } } - out.printf("The list have %d positive numbers.%n", count); + out.printf("%d valores positivos%n", count); } } diff --git a/src/test/resources/br/masmangan/beecrowd/bee1060/bee1060.feature b/src/test/resources/br/masmangan/beecrowd/bee1060/bee1060.feature index d3e0d77..348bee1 100644 --- a/src/test/resources/br/masmangan/beecrowd/bee1060/bee1060.feature +++ b/src/test/resources/br/masmangan/beecrowd/bee1060/bee1060.feature @@ -30,16 +30,16 @@ Feature: Bee1060 CLI Given The input is """ +7 +-5 6 -1 --1 -19 -9 -5 +-3.4 +4.6 +12 """ When Program runs Then The output should be """ -The list have 5 positive numbers. +4 valores positivos """ \ No newline at end of file