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="VM_PARAMETERS" value="-ea" />
|
||||
<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="PASS_PARENT_ENVS" value="true" />
|
||||
<option name="TEST_SEARCH_SCOPE">
|
||||
|
||||
@@ -34,7 +34,7 @@ dependencies {
|
||||
testCompile 'junit:junit:4.12'
|
||||
testCompile 'info.cukes:cucumber-java: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:recyclerview-v7:25.0.1'
|
||||
|
||||
@@ -35,7 +35,12 @@ public class RandomBookGenerator {
|
||||
"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<>();
|
||||
|
||||
for (int i = 0; i < howMany; i++) {
|
||||
@@ -45,6 +50,9 @@ public class RandomBookGenerator {
|
||||
return books;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random book.
|
||||
*/
|
||||
public static Book randomBook() {
|
||||
String title = randomTitle();
|
||||
String author = randomAuthor();
|
||||
@@ -57,14 +65,14 @@ public class RandomBookGenerator {
|
||||
String subject = RandomUtils.randomFromArray(SUBJECTS);
|
||||
String secondWord = RandomUtils.randomFromArray(SECOND_WORDS);
|
||||
|
||||
return subject + " " + secondWord;
|
||||
return String.format("%s %s", subject, secondWord);
|
||||
}
|
||||
|
||||
private static String randomAuthor() {
|
||||
String firstName = RandomUtils.randomFromArray(FIRST_NAMES);
|
||||
String lastName = RandomUtils.randomFromArray(LAST_NAMES);
|
||||
|
||||
return firstName + " " + lastName;
|
||||
return String.format("%s %s", firstName, lastName);
|
||||
}
|
||||
|
||||
private static Date randomDate() {
|
||||
|
||||
@@ -13,7 +13,6 @@ import com.codemate.booklibrary.R;
|
||||
import java.util.List;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements MainView, SearchView.OnQueryTextListener {
|
||||
|
||||
private MainPresenter presenter;
|
||||
private BookAdapter bookAdapter;
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public class MainPresenter {
|
||||
// Populate the library with fake dummy data. In a real app
|
||||
// we would have an interactor that would fetch the books from
|
||||
// a real API.
|
||||
List<Book> books = RandomBookGenerator.randomBooks(45);
|
||||
List<Book> books = RandomBookGenerator.generate(45);
|
||||
library.addBooks(books);
|
||||
|
||||
loadBooks(library.getAllBooks());
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.List;
|
||||
public class LibraryTest {
|
||||
@Test
|
||||
public void addMultipleBooks_PersistsThemInLibrary() {
|
||||
List<Book> books = RandomBookGenerator.randomBooks(3);
|
||||
List<Book> books = RandomBookGenerator.generate(3);
|
||||
Library library = new Library();
|
||||
library.addBooks(books);
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import static org.junit.Assert.assertNotNull;
|
||||
public class RandomBookGeneratorTest {
|
||||
@Test
|
||||
public void generatingRandomBooks_ReturnsNonEmptyBookList() {
|
||||
List<Book> books = RandomBookGenerator.randomBooks(15);
|
||||
List<Book> books = RandomBookGenerator.generate(15);
|
||||
|
||||
assertEquals(15, books.size());
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ import static org.mockito.Mockito.when;
|
||||
* Created by ironman on 02/09/16.
|
||||
*/
|
||||
public class MainPresenterTest {
|
||||
|
||||
@Mock
|
||||
private MainView mainView;
|
||||
|
||||
@@ -32,14 +31,14 @@ public class MainPresenterTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
presenter = new MainPresenter(mainView, library);
|
||||
randomBooks = RandomBookGenerator.randomBooks(5);
|
||||
randomBooks = RandomBookGenerator.generate(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void searchForBooks_ShowsThemInUI() {
|
||||
when(library.search(anyString()))
|
||||
.thenReturn(randomBooks);
|
||||
when(library.search(anyString())).thenReturn(randomBooks);
|
||||
presenter.searchForBooks("test_search");
|
||||
|
||||
verify(mainView).showBooks(randomBooks);
|
||||
@@ -47,8 +46,7 @@ public class MainPresenterTest {
|
||||
|
||||
@Test
|
||||
public void loadAllBooks_ShowsThemInUI() {
|
||||
when(library.getAllBooks())
|
||||
.thenReturn(randomBooks);
|
||||
when(library.getAllBooks()).thenReturn(randomBooks);
|
||||
presenter.loadAllBooks();
|
||||
|
||||
verify(mainView).showBooks(randomBooks);
|
||||
|
||||
Reference in New Issue
Block a user