Added a license and removed the default file template boilerplate.

This commit is contained in:
Iiro Krankka
2017-01-09 12:06:42 +02:00
parent b79e1230a9
commit f558906eb0
13 changed files with 7 additions and 46 deletions

View File

@@ -1,14 +1,12 @@
# Behavior-Driven Development with Cucumber # Behavior-Driven Development with Cucumber
This is a sample Android app that has tests mostly written using the Cucumber framework. The app acts like a library book search, allowing you to search for books by title, author or year. **The test coverage is 97%**. This is a sample Android app that has tests mostly written using the Cucumber framework. The app acts like a library book search, allowing you to search for books by title, author or year.
[Cucumber](https://cucumber.io/) is a BDD testing framework that allows people without programming background write specifications **that can be translated to unit tests almost automatically**. [Cucumber](https://cucumber.io/) is a BDD testing framework that allows people without programming background write specifications **that can be translated to unit test requirements almost automatically**.
Writing tests turns more fun and it's no more a pain in the ass to write them first. It's also easier to specify the requirements.
## An example ## An example
The Oulu City Library has an application for book management. The Springfield City Library has an application for book management.
The application is working fine, but they don't have a search feature. For the first version of the search feature, there's only one thing to implement: The application is working fine, but they don't have a search feature. For the first version of the search feature, there's only one thing to implement:
@@ -20,14 +18,13 @@ This translates to the following **Gherkin** syntax, which could be even written
```gherkin ```gherkin
Feature: Book Search Feature: Book Search
Scenario: Search books by author Scenario: Search books by author
Given there's a book called "Tips for horrible hangovers" written by "John Smith" Given there's a book called "Tips for job interviews" written by "John Smith"
And there's a book called "Bananas and their many colors" written by "James Brown" And there's a book called "Bananas and their many colors" written by "James Doe"
And there's a book called "Mama look I'm a rock star" written by "John Smith" And there's a book called "Mama look I'm a rock star" written by "John Smith"
When an employee searches by author "John Smith" When an employee searches by author "John Smith"
Then 2 books should be found Then 2 books should be found
And Book 1 has the title "Tips for horrible hangovers" And Book 1 has the title "Tips for job interviews"
And Book 2 has the title "Mama look I'm a rock star" And Book 2 has the title "Mama look I'm a rock star"
``` ```

View File

@@ -2,9 +2,6 @@ package com.codemate.booklibrary.data;
import java.util.Date; import java.util.Date;
/**
* Created by ironman on 01/09/16.
*/
public class Book { public class Book {
private final String title; private final String title;
private final String author; private final String author;

View File

@@ -4,9 +4,6 @@ import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
/**
* Created by ironman on 01/09/16.
*/
public class Library { public class Library {
private List<Book> inventory = new ArrayList<>(); private List<Book> inventory = new ArrayList<>();

View File

@@ -5,9 +5,6 @@ import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
/**
* Created by ironman on 02/09/16.
*/
public class RandomBookGenerator { public class RandomBookGenerator {
private static final String[] SUBJECTS = { private static final String[] SUBJECTS = {
"Chicken", "Pig", "Hippo", "Dinosaur", "Giraffe", "Orangutan", "Chicken", "Pig", "Hippo", "Dinosaur", "Giraffe", "Orangutan",

View File

@@ -2,9 +2,6 @@ package com.codemate.booklibrary.data;
import java.util.Random; import java.util.Random;
/**
* Created by ironman on 02/09/16.
*/
public class RandomUtils { public class RandomUtils {
private RandomUtils() {} private RandomUtils() {}

View File

@@ -14,9 +14,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
/**
* Created by ironman on 02/09/16.
*/
public class BookAdapter extends RecyclerView.Adapter<BookAdapter.ViewHolder> { public class BookAdapter extends RecyclerView.Adapter<BookAdapter.ViewHolder> {
private final SimpleDateFormat dateFormat; private final SimpleDateFormat dateFormat;
private List<Book> items = new ArrayList<>(); private List<Book> items = new ArrayList<>();

View File

@@ -8,9 +8,6 @@ import com.codemate.booklibrary.data.RandomBookGenerator;
import java.util.List; import java.util.List;
/**
* Created by ironman on 02/09/16.
*/
public class MainPresenter { public class MainPresenter {
private final MainView mainView; private final MainView mainView;
private final Library library; private final Library library;

View File

@@ -4,9 +4,6 @@ import com.codemate.booklibrary.data.Book;
import java.util.List; import java.util.List;
/**
* Created by ironman on 02/09/16.
*/
public interface MainView { public interface MainView {
void showBooks(List<Book> books); void showBooks(List<Book> books);
} }

View File

@@ -7,9 +7,6 @@ import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions; import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber; import cucumber.api.junit.Cucumber;
/**
* Created by ironman on 01/09/16.
*/
@RunWith(Cucumber.class) @RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources") @CucumberOptions(features = "src/test/resources")
public class CucumberTests extends TestCase { public class CucumberTests extends TestCase {

View File

@@ -5,9 +5,6 @@ import org.junit.Test;
import java.util.List; import java.util.List;
/**
* Created by ironman on 02/09/16.
*/
public class LibraryTest { public class LibraryTest {
@Test @Test
public void addMultipleBooks_PersistsThemInLibrary() { public void addMultipleBooks_PersistsThemInLibrary() {

View File

@@ -8,9 +8,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
/**
* Created by ironman on 02/09/16.
*/
public class RandomBookGeneratorTest { public class RandomBookGeneratorTest {
@Test @Test
public void generatingRandomBooks_ReturnsNonEmptyBookList() { public void generatingRandomBooks_ReturnsNonEmptyBookList() {

View File

@@ -25,9 +25,6 @@ import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
/**
* Created by ironman on 01/09/16.
*/
public class BookSearchSteps { public class BookSearchSteps {
private Library library = new Library(); private Library library = new Library();
private List<Book> results = new ArrayList<>(); private List<Book> results = new ArrayList<>();
@@ -75,7 +72,7 @@ public class BookSearchSteps {
@And("^Book (\\d+) should have the title \"([^\"]*)\"$") @And("^Book (\\d+) should have the title \"([^\"]*)\"$")
public void verifyBookAtPosition(int position, String title) throws Throwable { public void verifyBookAtPosition(int position, String title) throws Throwable {
int realPosition = position - 1; int realPosition = position - 1;
Assert.assertEquals(title, results.get(realPosition).getTitle()); assertEquals(title, results.get(realPosition).getTitle());
} }
@And("^Books should be (.+)$") @And("^Books should be (.+)$")

View File

@@ -18,9 +18,6 @@ import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
/**
* Created by ironman on 02/09/16.
*/
public class MainPresenterTest { public class MainPresenterTest {
private static final List<Book> DUMMY_BOOKS = Arrays.asList( private static final List<Book> DUMMY_BOOKS = Arrays.asList(
new Book("Sample book one", "John Doe", Date.valueOf("2000-10-25")), new Book("Sample book one", "John Doe", Date.valueOf("2000-10-25")),