If you do not use them in your code for testing, you can add them using the constructor:
public LoginPresenter(FireBaseAuth firebaseAuth, FirebaseDatabase database){ this.firebaseAuth = firebaseAuth; this.database = database; }
and you enter null for them, remember that this is very bad using null . It is best to use a library like Mockito or use interfaces / wrapper etc.
eg. use interface
public interface IDatabase { public List<String> getData(); }
LoginPresenter :
public LoginPresenter(FireBaseAuth firebaseAuth, IDatabase database){ this.firebaseAuth = firebaseAuth; this.database = database; }
Normal implementation of IDatabase :
public class MyDatabase implements IDatabase { private FirebaseDatabase database; public MyDatabase(FirebaseDatabase database) { this.database = database; } public List<String> getDate() {
And now itβs very easy to mock a database using IDatabase :
public class DatabaseMock implements IDatabase { public List<String> getData() {
Call it from the test, for example:
presenter = new LoginPresenter(FirebaseAuth.getInstance(), new DatabaseMock());
source share