Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CucumberTest #12

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions src/test/java/cofre/CofreCucumberTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@

package cofre;

import cucumber.api.PendingException;
import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class CofreCucumberTest extends CofrePMTest {

public CofreCucumberTest() {
sensorMock = mock(SensorPorta.class);
memoriaMock = mock(Memoria.class);
cofrePM = new CofrePM(sensorMock, memoriaMock);
}

@Given("^que liguei o cofre$")
public void que_liguei_o_cofre() throws Exception {
when(sensorMock.fechada())
.thenReturn(Boolean.FALSE);
}

@Then("^a mensagem de senha \"([^\"]*)\" deve aparecer$")
public void a_mensagem_de_senha_deve_aparecer(String arg1) throws Exception {
assertEquals(arg1, cofrePM.getDisplay());
verify(sensorMock).destravar();
}

@Given("^que limpo o display$")
public void que_limpo_o_display() throws Exception {
cofrePM.clear();
}

@Then("^a tela limpa \"([^\"]*)\" deve aparecer$")
public void a_tela_limpa_deve_aparecer(String arg1) throws Exception {
assertEquals(arg1, cofrePM.getDisplay());
}

@Given("^que a porta esta aberta$")
public void que_a_porta_esta_aberta() throws Exception {
when(sensorMock.fechada())
.thenReturn(Boolean.FALSE);
}

@When("^eu digitar qualquer coisa como (\\d+) na senha$")
public void eu_digitar_qualquer_coisa_como_na_senha(int arg1) throws Exception {
cofrePM.pressButton(arg1);
}

@Then("^a mensagem \"([^\"]*)\"$")
public void a_mensagem(String arg1) throws Exception {
assertEquals(arg1, cofrePM.getDisplay());
cofrePM.clear();
cofrePM.ok();
}

@Given("^que digito a senha com a porta fechada$")
public void que_digito_a_senha_com_a_porta_fechada() throws Exception {
when(sensorMock.fechada())
.thenReturn(Boolean.TRUE);
}

@When("^eu digitar (\\d+)$")
public void eu_digitar(int arg1) throws Exception {
cofrePM.pressButton(arg1);
}

@Then("^a senha \"([^\"]*)\" aparece no display$")
public void a_senha_aparece_no_display(String arg1) throws Exception {
assertEquals(arg1, cofrePM.getDisplay());
}

@When("^aperto Ok$")
public void aperto_Ok() throws Exception {
cofrePM.ok();
}

@Then("^o display \"([^\"]*)\" deve aparecer$")
public void o_display_deve_aparecer(String arg1) throws Exception {
assertEquals(arg1, cofrePM.getDisplay());
verify(sensorMock).travar();
verify(memoriaMock).salvarSenha("193566");
}

@Given("^que digito a senha$")
public void que_digito_a_senha() throws Exception {
when(sensorMock.fechada())
.thenReturn(Boolean.TRUE);
when(sensorMock.travada())
.thenReturn(Boolean.TRUE);
when(memoriaMock.getSenha())
.thenReturn("123466");
}

@Then("^a senha valida \"([^\"]*)\" aparece no display$")
public void a_senha_valida_aparece_no_display(String arg1) throws Exception {
assertEquals(arg1, cofrePM.getDisplay());
}

@Then("^o display de \"([^\"]*)\" deve aparecer$")
public void o_display_de_deve_aparecer(String arg1) throws Exception {
assertEquals("senha correta. Cofre aberto", cofrePM.getDisplay());

verify(sensorMock, times(2)).destravar(); //destravar eh chamado pelo construtor tb
}

}
6 changes: 3 additions & 3 deletions src/test/java/cofre/CofrePMTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @author andreendo
*/
public class CofrePMTest {
SensorPorta sensorMock;
Memoria memoriaMock;
CofrePM cofrePM;
public SensorPorta sensorMock;
public Memoria memoriaMock;
public CofrePM cofrePM;
}
22 changes: 22 additions & 0 deletions src/test/java/cofre/Cucumber01Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cofre;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.runner.RunWith;

/**
*
* @author utfpr
*/
@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"pretty", "html:target/cucumber"})
public class Cucumber01Test {


@Test
public void test01() {

}
}
39 changes: 21 additions & 18 deletions src/test/java/cofre/TravadoCofrePMTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package cofre;

import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
Expand All @@ -10,71 +14,70 @@
* @author andreendo
*/
public class TravadoCofrePMTest extends CofrePMTest {

@Before
public void before() {
sensorMock = mock(SensorPorta.class);
memoriaMock = mock(Memoria.class);
cofrePM = new CofrePM(sensorMock, memoriaMock);
cofrePM = new CofrePM(sensorMock, memoriaMock);

when(sensorMock.fechada())
.thenReturn(Boolean.TRUE);
when(sensorMock.travada())
.thenReturn(Boolean.TRUE);
.thenReturn(Boolean.TRUE);
}

@Test
public void testDigitarSenhaInvalida() {
when(memoriaMock.getSenha())
.thenReturn("123456");

cofrePM.pressButton(1);
cofrePM.pressButton(2);
cofrePM.pressButton(3);
cofrePM.pressButton(4);
cofrePM.pressButton(6);
cofrePM.pressButton(6);
assertEquals("123466", cofrePM.getDisplay());

cofrePM.ok();
assertEquals("senha errada. Tente novamente", cofrePM.getDisplay());
}

@Test
public void testDigitarSenhaComMenosDeSeis() {
when(memoriaMock.getSenha())
.thenReturn("123456");

cofrePM.pressButton(1);
assertEquals("1", cofrePM.getDisplay());

cofrePM.ok();
assertEquals("senha errada. Tente novamente", cofrePM.getDisplay());

cofrePM.pressButton(1);
cofrePM.pressButton(1);
assertEquals("11", cofrePM.getDisplay());

cofrePM.ok();
assertEquals("senha errada. Tente novamente", cofrePM.getDisplay());
}
assertEquals("senha errada. Tente novamente", cofrePM.getDisplay());
}

@Test
public void testDigitarSenhaValida() {
when(memoriaMock.getSenha())
.thenReturn("123466");

cofrePM.pressButton(1);
cofrePM.pressButton(2);
cofrePM.pressButton(3);
cofrePM.pressButton(4);
cofrePM.pressButton(6);
cofrePM.pressButton(6);
assertEquals("123466", cofrePM.getDisplay());

cofrePM.ok();
assertEquals("senha correta. Cofre aberto", cofrePM.getDisplay());

verify(sensorMock, times(2)).destravar(); //destravar eh chamado pelo construtor tb
}
}
}
36 changes: 20 additions & 16 deletions src/test/java/cofre/ValidacaoHelperTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package cofre;

import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import org.junit.Test;
import static org.junit.Assert.*;

Expand All @@ -8,28 +12,28 @@
* @author andreendo
*/
public class ValidacaoHelperTest {

public ValidacaoHelperTest() {
}

@Test
public void testEhNumero() {
assertTrue( ValidacaoHelper.ehNumero("123") );
assertTrue( ValidacaoHelper.ehNumero("1234444") );
assertFalse( ValidacaoHelper.ehNumero("") );
assertFalse( ValidacaoHelper.ehNumero("123aaaa") );

assertTrue(ValidacaoHelper.ehNumero("123"));
assertTrue(ValidacaoHelper.ehNumero("1234444"));

assertFalse(ValidacaoHelper.ehNumero(""));
assertFalse(ValidacaoHelper.ehNumero("123aaaa"));
}

@Test
public void testEhSenhaValida() {
assertFalse( ValidacaoHelper.ehSenhaValida("123") );
assertFalse( ValidacaoHelper.ehSenhaValida("1") );
assertFalse( ValidacaoHelper.ehSenhaValida("12345") );
assertFalse( ValidacaoHelper.ehSenhaValida("12345a") );
assertTrue( ValidacaoHelper.ehSenhaValida("123999") );
}

assertFalse(ValidacaoHelper.ehSenhaValida("123"));
assertFalse(ValidacaoHelper.ehSenhaValida("1"));
assertFalse(ValidacaoHelper.ehSenhaValida("12345"));
assertFalse(ValidacaoHelper.ehSenhaValida("12345a"));

assertTrue(ValidacaoHelper.ehSenhaValida("123999"));
}
}
48 changes: 48 additions & 0 deletions src/test/resources/cofre/TravadoCofrePMTest.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# language: en
Feature: Destravar o cofre
Como um usuário eu devo
inserir uma senha valida
e o sistema deve retornar uma mensagem
de senha correta. Cofre aberto

Scenario: CofreInicial
Given que liguei o cofre
Then a mensagem de senha "Entre com a senha 6 digitos" deve aparecer

Scenario: CofreLimpo
Given que limpo o display
Then a tela limpa "" deve aparecer

Scenario: PortaAberta
Given que a porta esta aberta
When eu digitar qualquer coisa como 5 na senha
Then a mensagem "Feche a porta antes de digitar a senha"

Scenario: PortaFechadaGravarSenha
Given que digito a senha com a porta fechada
When eu digitar 1
Then a senha "1" aparece no display
When eu digitar 9
Then a senha "19" aparece no display
When eu digitar 3
Then a senha "193" aparece no display
When eu digitar 5
Then a senha "1935" aparece no display
When eu digitar 6
Then a senha "19356" aparece no display
When eu digitar 6
Then a senha "193566" aparece no display
When aperto Ok
Then o display "Senha salva. Cofre trancado" deve aparecer

Scenario: DigitarSenhaValida
Given que digito a senha
When eu digitar 1
And eu digitar 2
And eu digitar 3
And eu digitar 4
And eu digitar 6
And eu digitar 6
Then a senha valida "123466" aparece no display
When aperto Ok
Then o display de "senha correta. Cofre aberto" deve aparecer
Empty file.
Loading