What's the best way to test my mvp presenter? I've read a ton of tutorials and each one makes me even more confused. I'm just starting to learn about testing and I figured it'd be easier to start with the presenter.
My Presenter
public class HymnPresenter implements HymnPresenterContract, HymnRepository.HymnsCallback{
private HymnRepository hymnRepository;
private HymnsViewContract hymnViewContract;
public HymnPresenter(HymnRepository repository, HymnsViewContract viewContract) {
this.hymnViewContract = viewContract;
this.hymnRepository = repository.attach(this);
}
@Override
public void addHymns(ArrayList<Hymn> hymns){
hymnRepository.addHymns(hymns);
}
@Override
public void addHymn(Hymn hymn){
hymnRepository.addHymn(hymn);
}
@Override
public void handleSuccess() {
hymnViewContract.success();
}
@Override
public void handleError(String error) {
hymnViewContract.error(error);
}
}
My Repository I'm using the firebase firestore db to store the hymns
public class HymnRepository implements HymnPresenterContract{
private HymnsCallback hymnsCallback;
private CollectionReference collectionReference;
private FirebaseFirestore db;
public HymnRepository(FirebaseFirestore database, @HymnCollection CollectionReference collection) {
this.db = database;
this.collectionReference = collection;
}
public HymnRepository attach(@NonNull HymnsCallback callback){
this.hymnsCallback = callback;
return this;
}
@Override
public void addHymns(ArrayList<Hymn> hymns){
WriteBatch batch = db.batch();
for(int i = 0; i < hymns.size(); i++){
batch.set(collectionReference.document(), hymns.get(i));
}
batch.commit()
.addOnSuccessListener(documentReference -> hymnsCallback.handleSuccess())
.addOnFailureListener(e -> hymnsCallback.handleError(e.toString()));
}
@Override
public void addHymn(Hymn hymn) {
collectionReference.add(hymn)
.addOnSuccessListener(documentReference -> hymnsCallback.handleSuccess())
.addOnFailureListener(e -> hymnsCallback.handleError(e.toString()));
}
public interface HymnsCallback {
void handleSuccess();
void handleError(String error);
}
}
My presenter contract
public interface HymnPresenterContract {
void addHymns(ArrayList<Hymn> hymns);
void addHymn(Hymn hymn);
}
My view contract
public interface HymnsViewContract {
void success();
void error(String error);
}