JavaVariable { public String getType() { return type; } JavaVariable(String type, String name); String getType(); String getTypeAsNonPrimitiveType(); String getName(); boolean hasType(); static JavaVariable parse(String s); static List<JavaVariable> parseList(String s); static String parseToken(String s, int offset); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); static final public Map<String,Class> PRIMITIVES; }
@Test public void type_shouldBeParsedWithLeastWhitespacesAsPossible() { final String unimportant = "foos"; final JavaVariable genericCollectionOfExtensions = new JavaVariable("Collection<? extends Foo>", unimportant); final JavaVariable genericCollectionOfExtensionsWithLootsOfWhitespaces = new JavaVariable( " Collection\t < ?\t extends Foo > ", unimportant ); final JavaVariable genericCollectionOfAncestorsWithLootsOfWhitespaces = new JavaVariable( " Collection\t < ?\t super Foo > ", unimportant ); final JavaVariable complexFunctionWithLootsOfWhitespaces = new JavaVariable( " Function <\t ? extends Foo, ? super \tBar > ", unimportant ); final JavaVariable genericCollectionOfExtensionsWithFullyQualifiedClassNameAndLootsOfWhitespaces = new JavaVariable( " Collection < ? extends some . fancy. \t package .Foo > \n ", unimportant ); final JavaVariable genericCollectionOfFoosWithLootsOfWhitespaces = new JavaVariable( " Collection < \tFoo > ", unimportant ); final JavaVariable fooTypeWithLootsOfWhitespaces = new JavaVariable(" \t Foo \t ", unimportant); final JavaVariable arrayOfFooWithLootsOfWhitespaces = new JavaVariable(" Foo [ \t ] ", unimportant); final JavaVariable arrayOfSimpleIntTypeWithLootsOfWhitespaces = new JavaVariable(" \t int [ ] \t ", unimportant); Assert.assertEquals("Collection<? extends Foo>", genericCollectionOfExtensions.getType()); Assert.assertEquals("Collection<? extends Foo>", genericCollectionOfExtensionsWithLootsOfWhitespaces.getType()); Assert.assertEquals("Collection<? super Foo>", genericCollectionOfAncestorsWithLootsOfWhitespaces.getType()); Assert.assertEquals("Function<? extends Foo,? super Bar>", complexFunctionWithLootsOfWhitespaces.getType()); Assert.assertEquals( "Collection<? extends some.fancy.package.Foo>", genericCollectionOfExtensionsWithFullyQualifiedClassNameAndLootsOfWhitespaces.getType() ); Assert.assertEquals("Collection<Foo>", genericCollectionOfFoosWithLootsOfWhitespaces.getType()); Assert.assertEquals("Foo", fooTypeWithLootsOfWhitespaces.getType()); Assert.assertEquals("Foo[]", arrayOfFooWithLootsOfWhitespaces.getType()); Assert.assertEquals("int[]", arrayOfSimpleIntTypeWithLootsOfWhitespaces.getType()); }