Skip to content

Commit

Permalink
first hello world test
Browse files Browse the repository at this point in the history
  • Loading branch information
lordlothar99 committed May 5, 2016
1 parent b785890 commit 57a9b03
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/com/github/lothar/hsystem/InstructionProcessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.github.lothar.hsystem;

import org.springframework.stereotype.Component;

@Component
public class InstructionProcessor {

public void process(String instruction) {
System.out.println("Hello world !");
}

}
6 changes: 6 additions & 0 deletions src/test/features/simple-instruction.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Execute a simple instruction locally

@done
Scenario: Prints something in the console when user asks so
When I say "Print \"Hello world !\" in the console"
Then "Hello world !" is printed in the console
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.github.lothar.hsystem.cucumber;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(plugin = "pretty",
monochrome = true,
features = "src/test/features",
glue = { "com.github.lothar.hsystem.cucumber", "cucumber.api.spring" },
tags = { "~@ignore", "@done" })
public class CucumberTests {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.github.lothar.hsystem.cucumber;

import static org.mockito.Mockito.verify;

import java.io.PrintStream;

import javax.annotation.Resource;

import org.mockito.Mockito;
import org.springframework.boot.test.SpringApplicationContextLoader;
import org.springframework.test.context.ContextConfiguration;

import com.github.lothar.hsystem.HSystemApplication;
import com.github.lothar.hsystem.InstructionProcessor;

import cucumber.api.java.Before;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

@ContextConfiguration(classes = HSystemApplication.class, loader = SpringApplicationContextLoader.class)
public class SimplePrintStepDefs {

@Resource
private InstructionProcessor processor;
private PrintStream sysoutMock = Mockito.mock(PrintStream.class);

@Before
public void before() {
System.setOut(sysoutMock);
}

public void after() {
System.setOut(System.out);
}

@When("^I say \"Print (.*) in the console\"$")
public void i_say_print_in_the_console(String instruction) {
processor.process("Print " + instruction + " in the console");
}

@Then("^\"([^\"]*)\" is printed in the console$")
public void is_printed_in_the_console(String expectedOutput) {
verify(sysoutMock).println(expectedOutput);
}
}

0 comments on commit 57a9b03

Please sign in to comment.