Skip to content

Commit

Permalink
Added additional tests. Fixed validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Jan 7, 2016
1 parent 11bb6c2 commit 582e7cd
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,7 @@ public int hashCode() {
@Override
public String toString() {
return "TypeDescription.Generic.Visitor.Assigner.Dispatcher.ForParameterizedType.ParameterAssigner.ContravariantBinding{" +
"typeDescription=" + lowerBound +
"lowerBound=" + lowerBound +
'}';
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ public TypeDescription validated() {
}
} else if (!methodDescription.getReturnType().accept(Generic.Visitor.Validator.METHOD_RETURN)) {
throw new IllegalStateException("Illegal return type " + methodDescription.getReturnType() + " for " + methodDescription);
} else if (isValidIdentifier(methodDescription.getInternalName())) {
} else if (!isValidIdentifier(methodDescription.getInternalName())) {
throw new IllegalStateException("Illegal method name for: " + methodDescription);
}
Set<String> parameterNames = new HashSet<String>();
Expand Down Expand Up @@ -918,6 +918,8 @@ private static boolean isValidIdentifier(String[] name) {
private static boolean isValidIdentifier(String name) {
if (name.isEmpty() || !Character.isJavaIdentifierStart(name.charAt(0))) {
return false;
} else if (name.equals(PackageDescription.PACKAGE_CLASS_NAME)) {
return true;
}
for (int index = 1; index < name.length(); index++) {
if (!Character.isJavaIdentifierPart(name.charAt(index))) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package net.bytebuddy.description.type;

import net.bytebuddy.test.utility.MockitoRule;
import net.bytebuddy.test.utility.ObjectPropertyAssertion;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.mockito.Mock;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class TypeDescriptionGenericVisitorValidatorTest {

@Rule
public TestRule mockitoRule = new MockitoRule(this);

@Mock
private TypeDescription.Generic typeDescription;

@Test
public void testWildcardNotValidated() throws Exception {
assertThat(TypeDescription.Generic.Visitor.Validator.SUPER_CLASS.onWildcard(typeDescription), is(false));
assertThat(TypeDescription.Generic.Visitor.Validator.INTERFACE.onWildcard(typeDescription), is(false));
assertThat(TypeDescription.Generic.Visitor.Validator.TYPE_VARIABLE.onWildcard(typeDescription), is(false));
assertThat(TypeDescription.Generic.Visitor.Validator.FIELD.onWildcard(typeDescription), is(false));
assertThat(TypeDescription.Generic.Visitor.Validator.METHOD_RETURN.onWildcard(typeDescription), is(false));
assertThat(TypeDescription.Generic.Visitor.Validator.METHOD_PARAMETER.onWildcard(typeDescription), is(false));
assertThat(TypeDescription.Generic.Visitor.Validator.EXCEPTION.onWildcard(typeDescription), is(false));
}

@Test
public void testObjectProperties() throws Exception {
ObjectPropertyAssertion.of(TypeDescription.Generic.Visitor.Validator.class).apply();
}
}

0 comments on commit 582e7cd

Please sign in to comment.