-
Notifications
You must be signed in to change notification settings - Fork 30
Implement ModelResolver.addRepository(Repository, boolean) correctly. #65
base: master
Are you sure you want to change the base?
Conversation
Can one of the admins verify this patch? |
} | ||
|
||
@Override | ||
public void addRepository(Repository repository, boolean replace) { | ||
addRepository(repository); | ||
if (repositories.contains(repository)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. The addRepositories(Repository repository, boolean replace)
is never called, so we skimped out on including the replace functionality.
Assuming it's not particularly annoying, can you add a simple test case?
There isn't any DefaultModelResolverTest
so you would need to create one, and mock the repositories.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
I also updated the repository store, since the previous implementation was relying on the internal implementation of Repository.equals, which is not documented as operating only on ID (even though it appears to be).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch on the equals.
Refactor repository registry to not rely on .equals implmentation of Repository.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. It looks good overall, barring a few nits.
} | ||
} else { | ||
repositories.add(repository); | ||
if (replace || !repositoriesById.containsKey(repository.getId())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can you add a simple comment for the boolean logic?
Although the new version is more concise, it took me a
second to remember the conditions.
mavenCentral.setName("default"); | ||
mavenCentral.setUrl(MAVEN_CENTRAL_URL); | ||
|
||
DEFAULT_REPOSITORIES = ImmutableMap.of(mavenCentral.getId(), mavenCentral); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 to this change
/** Test that addRepository doesn't replace existing repositories by default. */ | ||
@Test | ||
public void testAddRepository_defaultReplace() { | ||
Repository repoA1 = new Repository(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First thank you for the tests. One nit
Since each test is effectively doing the same thing, can you create the following utility functions
private Repository createRepository(String id, String url) {
Repository repo = new Repository();
repo.setId(id);
repo.setUrl(url);
}
private void assertThatContainsRepo(
DefaultModelResolver resolver, Repository repo) {...}
private void assertThatUrlNotChanged(
DefaultModelResolver resolver, Repository repo, String expectedUrl) {...}
This correctly honors the
replace
parameter. It was ignored before, which was making it effectively be treated asfalse
.Per the reference implementation, the single-argument
addRepository
should not replace (although it wasn't before).