Skip to content

Commit

Permalink
Fixed MockitoPresenterTests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ansel-Hong committed Aug 9, 2021
1 parent 9d040eb commit b7f190b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 38 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/com/example/b07project/Presenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public void login(){
view.displayMessage("email cannot be empty");
else if(password.equals(""))
view.displayMessage("password cannot be empty");
else if(!Patterns.EMAIL_ADDRESS.matcher(email).matches())
view.displayMessage("Please enter a valid email!");
else if(password.length() < 6)
view.displayMessage("The minimum password length is 6 characters");
else if(model.userIsFound(email, password) == true) {
view.displayMessage("trying to login");
view.userLogin(email, password);
}
else if(!Patterns.EMAIL_ADDRESS.matcher(email).matches())
view.displayMessage("Please enter a valid email!");
else
view.displayMessage("invalid login");
}
Expand Down
61 changes: 25 additions & 36 deletions app/src/test/java/com/example/b07project/MockitoPresenterTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,50 +24,39 @@
*/
@RunWith(MockitoJUnitRunner.class)
public class MockitoPresenterTests {
// @Mock
// MainActivity view;
//
// @Mock
// LoginPage loginView;

// @Test
// public void testMainNavigation(){
// when(loginView.navigateToPatientSignup()).getMock();
// }

// @Mock
// PatientActivity patView;
// @Mock
// FirebaseUser patient;
// @Mock
// DatabaseReference ref;
// @Mock
// private String userID;


@Mock
LoginPage loginView;

LoginPage view;
@Mock
Model model;

@Test
public void presenterTest(){
when(loginView.getEmail()).thenReturn("[email protected]");
when(loginView.getPassword()).thenReturn("abc");
when(model.userIsFound("[email protected]", "abc")).thenReturn(true);
Presenter presenter = new Presenter(model, loginView);
when(view.getEmail()).thenReturn("[email protected]");
when(view.getPassword()).thenReturn("abcdef");
when(model.userIsFound("[email protected]", "abcdef")).thenReturn(true);

Presenter presenter = new Presenter(model, view);
presenter.login();
verify(loginView).displayMessage("trying to login");
verify(view).displayMessage("trying to login");
}

// @Mock
// DoctorActivity docView;

// @Mock
// MainActivity view;
//
// @Mock
// LoginPage loginView;

// @Test
// public void testMainNavigation(){
// when(loginView.navigateToPatientSignup()).getMock();
// }

// @Mock
// PatientActivity patView;
// @Mock
// FirebaseUser patient;
// @Mock
// DatabaseReference ref;
// @Mock
// private String userID;

// @Test
// public void addition_isCorrect() {
// assertEquals(4, 2 + 2);
// }
}

0 comments on commit b7f190b

Please sign in to comment.