-
-
Notifications
You must be signed in to change notification settings - Fork 778
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added methods for reducing tokens to signature tokens.
- Loading branch information
Rafael Winterhalter
committed
Feb 5, 2016
1 parent
147fcac
commit fd54541
Showing
6 changed files
with
250 additions
and
2 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
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
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
103 changes: 103 additions & 0 deletions
103
...c/test/java/net/bytebuddy/description/type/TypeDescriptionGenericVisitorReducingTest.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,103 @@ | ||
package net.bytebuddy.description.type; | ||
|
||
import net.bytebuddy.test.utility.MockitoRule; | ||
import net.bytebuddy.test.utility.ObjectPropertyAssertion; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TestRule; | ||
import org.mockito.Mock; | ||
|
||
import java.util.Collections; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class TypeDescriptionGenericVisitorReducingTest { | ||
|
||
private static final String FOO = "foo", BAR = "bar"; | ||
|
||
@Rule | ||
public TestRule mockitoRule = new MockitoRule(this); | ||
|
||
@Mock | ||
private TypeDescription.Generic typeDescription, bound, genericTypeDescription; | ||
|
||
@Mock | ||
private TypeDescription declaringType, rawTypeDescription; | ||
|
||
@Mock | ||
private TypeVariableToken typeVariableToken; | ||
|
||
private TypeDescription.Generic.Visitor<TypeDescription> visitor; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
when(bound.asGenericType()).thenReturn(bound); | ||
visitor = new TypeDescription.Generic.Visitor.Reducing(declaringType, Collections.singletonList(typeVariableToken)); | ||
} | ||
|
||
@Test(expected = IllegalStateException.class) | ||
public void testWildcardThrowsException() throws Exception { | ||
visitor.onWildcard(typeDescription); | ||
} | ||
|
||
@Test | ||
public void testGenericArray() throws Exception { | ||
when(typeDescription.asErasure()).thenReturn(rawTypeDescription); | ||
assertThat(visitor.onGenericArray(typeDescription), is(rawTypeDescription)); | ||
verify(typeDescription).asErasure(); | ||
verifyNoMoreInteractions(typeDescription); | ||
} | ||
|
||
@Test | ||
public void testParameterizedType() throws Exception { | ||
when(typeDescription.asErasure()).thenReturn(rawTypeDescription); | ||
assertThat(visitor.onParameterizedType(typeDescription), is(rawTypeDescription)); | ||
verify(typeDescription).asErasure(); | ||
verifyNoMoreInteractions(typeDescription); | ||
} | ||
|
||
@Test | ||
public void testNonGenericType() throws Exception { | ||
when(typeDescription.asErasure()).thenReturn(rawTypeDescription); | ||
assertThat(visitor.onNonGenericType(typeDescription), is(rawTypeDescription)); | ||
verify(typeDescription).asErasure(); | ||
verifyNoMoreInteractions(typeDescription); | ||
} | ||
|
||
@Test | ||
public void testTypeVariableSelfDeclared() throws Exception { | ||
when(typeDescription.getSymbol()).thenReturn(FOO); | ||
when(typeVariableToken.getSymbol()).thenReturn(FOO); | ||
when(typeVariableToken.getBounds()).thenReturn(new TypeList.Generic.Explicit(bound)); | ||
when(bound.accept(visitor)).thenReturn(rawTypeDescription); | ||
assertThat(visitor.onTypeVariable(typeDescription), is(rawTypeDescription)); | ||
verify(typeDescription).getSymbol(); | ||
verifyNoMoreInteractions(typeDescription); | ||
verify(typeVariableToken).getSymbol(); | ||
verify(typeVariableToken).getBounds(); | ||
verifyNoMoreInteractions(typeVariableToken); | ||
} | ||
|
||
@Test | ||
public void testTypeVariableContextDeclared() throws Exception { | ||
when(typeDescription.getSymbol()).thenReturn(FOO); | ||
when(typeVariableToken.getSymbol()).thenReturn(BAR); | ||
when(declaringType.findVariable(FOO)).thenReturn(genericTypeDescription); | ||
when(genericTypeDescription.asErasure()).thenReturn(rawTypeDescription); | ||
assertThat(visitor.onTypeVariable(typeDescription), is(rawTypeDescription)); | ||
verify(typeDescription, times(2)).getSymbol(); | ||
verifyNoMoreInteractions(typeDescription); | ||
verify(typeVariableToken).getSymbol(); | ||
verifyNoMoreInteractions(typeVariableToken); | ||
verify(declaringType).findVariable(FOO); | ||
verifyNoMoreInteractions(declaringType); | ||
} | ||
|
||
@Test | ||
public void testObjectProperties() throws Exception { | ||
ObjectPropertyAssertion.of(TypeDescription.Generic.Visitor.Reducing.class).apply(); | ||
} | ||
} |