-
-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
640 additions
and
311 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
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
113 changes: 113 additions & 0 deletions
113
byte-buddy-dep/src/test/java/net/bytebuddy/build/PluginEngineSourceCompoundTest.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,113 @@ | ||
package net.bytebuddy.build; | ||
|
||
import net.bytebuddy.dynamic.ClassFileLocator; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.MethodRule; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.invocation.InvocationOnMock; | ||
import org.mockito.junit.MockitoJUnit; | ||
import org.mockito.stubbing.Answer; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.Iterator; | ||
import java.util.jar.Manifest; | ||
|
||
import static org.hamcrest.CoreMatchers.*; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class PluginEngineSourceCompoundTest { | ||
|
||
private static final String FOO = "foo"; | ||
|
||
@Rule | ||
public MethodRule mockitoRule = MockitoJUnit.rule().silent(); | ||
|
||
@Mock | ||
private Plugin.Engine.Source left; | ||
|
||
@Mock | ||
private Plugin.Engine.Source right; | ||
|
||
@Mock | ||
private Plugin.Engine.Source.Origin leftOrigin; | ||
|
||
@Mock | ||
private Plugin.Engine.Source.Origin rightOrigin; | ||
|
||
@Mock | ||
private ClassFileLocator leftLocator; | ||
|
||
@Mock | ||
private ClassFileLocator rightLocator; | ||
|
||
@Mock | ||
private Plugin.Engine.Source.Element leftElement; | ||
|
||
@Mock | ||
private Plugin.Engine.Source.Element rightElement; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
when(left.read()).thenReturn(leftOrigin); | ||
when(right.read()).thenReturn(rightOrigin); | ||
when(leftOrigin.getClassFileLocator()).thenReturn(leftLocator); | ||
when(rightOrigin.getClassFileLocator()).thenReturn(rightLocator); | ||
when(leftLocator.locate(Mockito.any(String.class))).thenReturn(new ClassFileLocator.Resolution.Illegal(FOO)); | ||
when(rightLocator.locate(Mockito.any(String.class))).thenReturn(new ClassFileLocator.Resolution.Illegal(FOO)); | ||
when(leftOrigin.iterator()).then(new Answer<Iterator<Plugin.Engine.Source.Element>>() { | ||
@Override | ||
public Iterator<Plugin.Engine.Source.Element> answer(InvocationOnMock invocation) { | ||
return Collections.singleton(leftElement).iterator(); | ||
} | ||
}); | ||
when(rightOrigin.iterator()).then(new Answer<Iterator<Plugin.Engine.Source.Element>>() { | ||
@Override | ||
public Iterator<Plugin.Engine.Source.Element> answer(InvocationOnMock invocation) { | ||
return Collections.singleton(rightElement).iterator(); | ||
} | ||
}); | ||
} | ||
|
||
@Test | ||
public void testEmptyCompound() throws Exception { | ||
assertThat(new Plugin.Engine.Source.Compound(Collections.emptyList()).read(), sameInstance((Plugin.Engine.Source.Origin) Plugin.Engine.Source.Empty.INSTANCE)); | ||
} | ||
|
||
@Test | ||
public void testClassFileLocator() throws Exception { | ||
assertThat(new Plugin.Engine.Source.Compound(Arrays.asList(left, right)).read().getClassFileLocator().locate(FOO).isResolved(), is(false)); | ||
verify(leftLocator).locate(FOO); | ||
verify(rightLocator).locate(FOO); | ||
} | ||
|
||
@Test | ||
public void testManifest() throws Exception { | ||
assertThat(new Plugin.Engine.Source.Compound(Arrays.asList(left, right)).read().getManifest(), nullValue(Manifest.class)); | ||
verify(leftOrigin).getManifest(); | ||
verify(rightOrigin).getManifest(); | ||
} | ||
|
||
@Test | ||
public void testIteration() throws Exception { | ||
Iterator<Plugin.Engine.Source.Element> iterator = new Plugin.Engine.Source.Compound(Arrays.asList(left, right)).read().iterator(); | ||
assertThat(iterator.hasNext(), is(true)); | ||
assertThat(iterator.next(), is(leftElement)); | ||
assertThat(iterator.hasNext(), is(true)); | ||
assertThat(iterator.next(), is(rightElement)); | ||
assertThat(iterator.hasNext(), is(false)); | ||
|
||
} | ||
|
||
@Test | ||
public void testClose() throws Exception { | ||
new Plugin.Engine.Source.Compound(Arrays.asList(left, right)).read().close(); | ||
verify(leftOrigin).close(); | ||
verify(rightOrigin).close(); | ||
} | ||
} |
Oops, something went wrong.