I have an requirement in which, I will be having two classes for handling two repository, say Git and Svn. The operations on these two repository is going to be same:
- Get branches
- Get commit ids
- Get last commit file
- etc
I thought I can design an interface which cover these operations:
interface Repo{
public JSONObject getBranches()
public JSONObject getCommits()
. . . .
}
Now the class Git and Svn can implement Repo. All is good.
But the question comes, how we are going to test these interfaces? Because the connection to the repo is handled in respective classes Git, Svn (say for example in its constructors). So that it looks like
class Git implements Repo {
public Git(String url, String username, String password){
//connect to git url
}
. . .
}
Now is this an fair design with respect to interfaces (in terms of testing) or we need to move the logic of creating connections with repo to say other class like RepoFactory and inject them in method params? So that Repo interface looks like:
interface Repo{
public JSONObject getBranches(RepoFactory repo)
public JSONObject getCommits(RepoFactory repo)
. . . .
}
and we can inject mocking of RepoFactory for easy testing.
Which will be an better design? Or something else is better than these two?
Aucun commentaire:
Enregistrer un commentaire