<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import static org.junit.Assert.*;
public class LibrarySteps {
private String book;
private boolean isAvailable;
@Given("^the book \"([^\"]*)\" is available in the library$")
public void theBookIsAvailableInTheLibrary(String book) {
this.book = book;
this.isAvailable = true;
}
@When("^I check the availability of the book$")
public void iCheckTheAvailabilityOfTheBook() {
// Perform the logic to check the availability of the book
// For the sake of example, we assume that the book is always available
this.isAvailable = true;
}
@Then("^the book should be available$")
public void theBookShouldBeAvailable() {
assertTrue(isAvailable);
}
@Then("^the book should not be available$")
public void theBookShouldNotBeAvailable() {
assertFalse(isAvailable);
}
}
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
public class LibraryTest {
}
gherkin
Feature: Library availability
Scenario: Check availability of a book
Given the book "Harry Potter" is available in the library
When I check the availability of the book
Then the book should be available
bash
mvn test