Skip to content

Commit

Permalink
ROASTER-110: Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Sep 5, 2016
1 parent 65ecc57 commit 3b9ab3e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ public class Types
"SafeVarargs",
"SuppressWarnings");

private Types() {}
private Types()
{
}

public static boolean areEquivalent(String left, String right)
{
Expand Down Expand Up @@ -230,7 +232,7 @@ public static String toSimpleName(final String type)
final String generics = new StringBuilder("<>").insert(1, Strings.join(simpleParameters, ",")).toString();
if (isArray(result))
{
result = new StringBuilder(result).insert(result.indexOf("["), generics).toString();
result = new StringBuilder(result).insert(result.indexOf("["), generics).toString();
}
else
{
Expand Down Expand Up @@ -637,7 +639,7 @@ public static String getDefaultValue(String type)
*/
public static String[] splitGenerics(String typeName)
{
typeName = typeName.replaceAll("\\s","");
typeName = typeName.replaceAll("\\s", "");
int begin = typeName.indexOf('<');
int end = typeName.indexOf('>');
if (begin == -1 || end == -1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*/
package org.jboss.forge.test.roaster.model;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;

import java.util.List;
import java.util.Map;

Expand All @@ -15,11 +18,9 @@
import org.jboss.forge.roaster.model.source.JavaInterfaceSource;
import org.jboss.forge.roaster.model.source.MethodSource;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
Expand Down Expand Up @@ -342,9 +343,21 @@ public void testSpaceInTwoGenericTypesShouldNotThrowException() throws Exception
.setName("tstMethod")
.setPublic();
newMethod.setReturnType(
"java.util.TreeMap<java.util.String, java.util.Object>"); // Counts space as part of the second type's name
"java.util.TreeMap<java.util.String, java.util.Object>"); // Counts space as part of the second type's
// name
newMethod.setBody("return new TreeMap<String, Object>();");
Assert.assertThat(classSource.toString(), containsString("public TreeMap<String, Object> tstMethod()"));
}

@Test
@Ignore("ROASTER-110")
public void testNestedTypedParametersShouldNotThrowException() throws Exception
{
final JavaClassSource javaClass = Roaster.create(JavaClassSource.class).setPackage("com.scratch")
.setName("Example");
final MethodSource<JavaClassSource> method = javaClass.addMethod().setName("createMap")
.setReturnType("java.util.Map<String,java.util.Map<String,String>>");
Assert.assertEquals("java.util.Map<String,java.util.Map<String,String>>",
method.getReturnType().getQualifiedNameWithGenerics());
}
}

0 comments on commit 3b9ab3e

Please sign in to comment.