-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SHRINKRES-85] fixed MavenModelResolver copies content sharing
- Loading branch information
1 parent
07fd767
commit 6db49cc
Showing
2 changed files
with
65 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...-maven/src/test/java/org/jboss/shrinkwrap/resolver/impl/maven/MavenModelResolverTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.jboss.shrinkwrap.resolver.impl.maven; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.jboss.shrinkwrap.resolver.impl.maven.bootstrap.MavenRepositorySystem; | ||
import org.jboss.shrinkwrap.resolver.impl.maven.internal.MavenModelResolver; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.sonatype.aether.repository.RemoteRepository; | ||
|
||
/** | ||
* Test for {@link MavenModelResolver}. | ||
* | ||
* @author <a href="mailto:mmatloka@gmail.com">Michal Matloka</a> | ||
*/ | ||
public class MavenModelResolverTest { | ||
|
||
/** | ||
* Tests if newCopy() gives independent instances. | ||
* | ||
* @throws NoSuchFieldException | ||
* @throws IllegalAccessException | ||
*/ | ||
@Test | ||
public void shouldGiveNewIndependentRepositories() throws NoSuchFieldException, IllegalAccessException { | ||
// given | ||
final String initialId = "id"; | ||
final RemoteRepository remoteRepository = new RemoteRepository(initialId, "type", "url"); | ||
final MavenModelResolver mavenModelResolver = new MavenModelResolver(new MavenRepositorySystem(), null, | ||
Arrays.asList(remoteRepository)); | ||
|
||
// when | ||
final MavenModelResolver mavenModelResolverCopy = (MavenModelResolver) mavenModelResolver.newCopy(); | ||
remoteRepository.setId("otherId"); | ||
|
||
// then | ||
// simulate access to repositories field, internal functions uses this field, e.g. to resolve model | ||
final Field repositoriesField = MavenModelResolver.class.getDeclaredField("repositories"); | ||
repositoriesField.setAccessible(true); | ||
|
||
@SuppressWarnings("unchecked") | ||
final List<RemoteRepository> value = (List<RemoteRepository>) repositoriesField.get(mavenModelResolverCopy); | ||
Assert.assertEquals("Internal value in copy has changed!", initialId, value.get(0).getId()); | ||
} | ||
} |