mirror of
https://github.com/hmalik144/Android-Cucumber-BDD-Sample.git
synced 2025-12-09 23:45:19 +00:00
Renamed the randomBooks() method to generate() & added some javadocs for the public methods.
This commit is contained in:
2
.idea/runConfigurations/All_Unit_Tests.xml
generated
2
.idea/runConfigurations/All_Unit_Tests.xml
generated
@@ -15,7 +15,7 @@
|
|||||||
<option name="TEST_OBJECT" value="directory" />
|
<option name="TEST_OBJECT" value="directory" />
|
||||||
<option name="VM_PARAMETERS" value="-ea" />
|
<option name="VM_PARAMETERS" value="-ea" />
|
||||||
<option name="PARAMETERS" value="" />
|
<option name="PARAMETERS" value="" />
|
||||||
<option name="WORKING_DIRECTORY" value="file://$MODULE_DIR$" />
|
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/app" />
|
||||||
<option name="ENV_VARIABLES" />
|
<option name="ENV_VARIABLES" />
|
||||||
<option name="PASS_PARENT_ENVS" value="true" />
|
<option name="PASS_PARENT_ENVS" value="true" />
|
||||||
<option name="TEST_SEARCH_SCOPE">
|
<option name="TEST_SEARCH_SCOPE">
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ dependencies {
|
|||||||
testCompile 'junit:junit:4.12'
|
testCompile 'junit:junit:4.12'
|
||||||
testCompile 'info.cukes:cucumber-java:1.2.4'
|
testCompile 'info.cukes:cucumber-java:1.2.4'
|
||||||
testCompile 'info.cukes:cucumber-junit:1.2.4'
|
testCompile 'info.cukes:cucumber-junit:1.2.4'
|
||||||
testCompile 'org.mockito:mockito-core:1.+'
|
testCompile 'org.mockito:mockito-core:2.5.5'
|
||||||
|
|
||||||
compile 'com.android.support:appcompat-v7:25.0.1'
|
compile 'com.android.support:appcompat-v7:25.0.1'
|
||||||
compile 'com.android.support:recyclerview-v7:25.0.1'
|
compile 'com.android.support:recyclerview-v7:25.0.1'
|
||||||
|
|||||||
@@ -35,7 +35,12 @@ public class RandomBookGenerator {
|
|||||||
"Johnson", "Springsteen", "Kauffman", "Schmidt", "Jokinen"
|
"Johnson", "Springsteen", "Kauffman", "Schmidt", "Jokinen"
|
||||||
};
|
};
|
||||||
|
|
||||||
public static List<Book> randomBooks(int howMany) {
|
/**
|
||||||
|
* Generates multiple random books.
|
||||||
|
* @param howMany how many random books should the generator generate.
|
||||||
|
* @return a list that has as many books as the parameter howMany specifies.
|
||||||
|
*/
|
||||||
|
public static List<Book> generate(int howMany) {
|
||||||
List<Book> books = new ArrayList<>();
|
List<Book> books = new ArrayList<>();
|
||||||
|
|
||||||
for (int i = 0; i < howMany; i++) {
|
for (int i = 0; i < howMany; i++) {
|
||||||
@@ -45,6 +50,9 @@ public class RandomBookGenerator {
|
|||||||
return books;
|
return books;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a random book.
|
||||||
|
*/
|
||||||
public static Book randomBook() {
|
public static Book randomBook() {
|
||||||
String title = randomTitle();
|
String title = randomTitle();
|
||||||
String author = randomAuthor();
|
String author = randomAuthor();
|
||||||
@@ -57,14 +65,14 @@ public class RandomBookGenerator {
|
|||||||
String subject = RandomUtils.randomFromArray(SUBJECTS);
|
String subject = RandomUtils.randomFromArray(SUBJECTS);
|
||||||
String secondWord = RandomUtils.randomFromArray(SECOND_WORDS);
|
String secondWord = RandomUtils.randomFromArray(SECOND_WORDS);
|
||||||
|
|
||||||
return subject + " " + secondWord;
|
return String.format("%s %s", subject, secondWord);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String randomAuthor() {
|
private static String randomAuthor() {
|
||||||
String firstName = RandomUtils.randomFromArray(FIRST_NAMES);
|
String firstName = RandomUtils.randomFromArray(FIRST_NAMES);
|
||||||
String lastName = RandomUtils.randomFromArray(LAST_NAMES);
|
String lastName = RandomUtils.randomFromArray(LAST_NAMES);
|
||||||
|
|
||||||
return firstName + " " + lastName;
|
return String.format("%s %s", firstName, lastName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Date randomDate() {
|
private static Date randomDate() {
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import com.codemate.booklibrary.R;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity implements MainView, SearchView.OnQueryTextListener {
|
public class MainActivity extends AppCompatActivity implements MainView, SearchView.OnQueryTextListener {
|
||||||
|
|
||||||
private MainPresenter presenter;
|
private MainPresenter presenter;
|
||||||
private BookAdapter bookAdapter;
|
private BookAdapter bookAdapter;
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class MainPresenter {
|
|||||||
// Populate the library with fake dummy data. In a real app
|
// Populate the library with fake dummy data. In a real app
|
||||||
// we would have an interactor that would fetch the books from
|
// we would have an interactor that would fetch the books from
|
||||||
// a real API.
|
// a real API.
|
||||||
List<Book> books = RandomBookGenerator.randomBooks(45);
|
List<Book> books = RandomBookGenerator.generate(45);
|
||||||
library.addBooks(books);
|
library.addBooks(books);
|
||||||
|
|
||||||
loadBooks(library.getAllBooks());
|
loadBooks(library.getAllBooks());
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import java.util.List;
|
|||||||
public class LibraryTest {
|
public class LibraryTest {
|
||||||
@Test
|
@Test
|
||||||
public void addMultipleBooks_PersistsThemInLibrary() {
|
public void addMultipleBooks_PersistsThemInLibrary() {
|
||||||
List<Book> books = RandomBookGenerator.randomBooks(3);
|
List<Book> books = RandomBookGenerator.generate(3);
|
||||||
Library library = new Library();
|
Library library = new Library();
|
||||||
library.addBooks(books);
|
library.addBooks(books);
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import static org.junit.Assert.assertNotNull;
|
|||||||
public class RandomBookGeneratorTest {
|
public class RandomBookGeneratorTest {
|
||||||
@Test
|
@Test
|
||||||
public void generatingRandomBooks_ReturnsNonEmptyBookList() {
|
public void generatingRandomBooks_ReturnsNonEmptyBookList() {
|
||||||
List<Book> books = RandomBookGenerator.randomBooks(15);
|
List<Book> books = RandomBookGenerator.generate(15);
|
||||||
|
|
||||||
assertEquals(15, books.size());
|
assertEquals(15, books.size());
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import static org.mockito.Mockito.when;
|
|||||||
* Created by ironman on 02/09/16.
|
* Created by ironman on 02/09/16.
|
||||||
*/
|
*/
|
||||||
public class MainPresenterTest {
|
public class MainPresenterTest {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private MainView mainView;
|
private MainView mainView;
|
||||||
|
|
||||||
@@ -32,14 +31,14 @@ public class MainPresenterTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
presenter = new MainPresenter(mainView, library);
|
presenter = new MainPresenter(mainView, library);
|
||||||
randomBooks = RandomBookGenerator.randomBooks(5);
|
randomBooks = RandomBookGenerator.generate(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void searchForBooks_ShowsThemInUI() {
|
public void searchForBooks_ShowsThemInUI() {
|
||||||
when(library.search(anyString()))
|
when(library.search(anyString())).thenReturn(randomBooks);
|
||||||
.thenReturn(randomBooks);
|
|
||||||
presenter.searchForBooks("test_search");
|
presenter.searchForBooks("test_search");
|
||||||
|
|
||||||
verify(mainView).showBooks(randomBooks);
|
verify(mainView).showBooks(randomBooks);
|
||||||
@@ -47,8 +46,7 @@ public class MainPresenterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void loadAllBooks_ShowsThemInUI() {
|
public void loadAllBooks_ShowsThemInUI() {
|
||||||
when(library.getAllBooks())
|
when(library.getAllBooks()).thenReturn(randomBooks);
|
||||||
.thenReturn(randomBooks);
|
|
||||||
presenter.loadAllBooks();
|
presenter.loadAllBooks();
|
||||||
|
|
||||||
verify(mainView).showBooks(randomBooks);
|
verify(mainView).showBooks(randomBooks);
|
||||||
|
|||||||
Reference in New Issue
Block a user