Skip to content

Commit

Permalink
ROASTER-21: Added test for default methods in interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jul 14, 2014
1 parent 3bd7cbe commit a360942
Showing 1 changed file with 49 additions and 28 deletions.
Expand Up @@ -9,45 +9,66 @@
import org.jboss.forge.roaster.Roaster;
import org.jboss.forge.roaster.model.JavaType;
import org.jboss.forge.roaster.model.source.JavaClassSource;
import org.jboss.forge.roaster.model.source.JavaInterfaceSource;
import org.junit.Assert;
import org.junit.Test;

public class JavaSourceCompatibilityTest {

@Test
public void testSupportsGenericsSource() throws Exception {
JavaType<?> source = Roaster.parse("public class Test{public void test() {java.util.List<String> s = new java.util.ArrayList<String>(); for (String item : s){}}}");
Assert.assertFalse(source.hasSyntaxErrors());
}

@Test
public void testSupportsGenericsSourceFromConstructor() throws Exception {
JavaType<?> source = Roaster.parse("public class Test{public Test() {java.util.List<String> s = new java.util.ArrayList<String>(); for (String item : s){}}}");
Assert.assertFalse(source.hasSyntaxErrors());
}

@Test
public void testSupportsGenericsSourceFromMethod() throws Exception {
JavaClassSource source = Roaster.parse(JavaClassSource.class, "public class Test{}");
source.addMethod("public void test() {java.util.List<String> s = new java.util.ArrayList<String>(); for (String item : s){}}");
Assert.assertFalse(source.hasSyntaxErrors());
}

@Test
public void testSupportsGenericsSourceFromAddedConstructor() throws Exception {
public class JavaSourceCompatibilityTest
{

@Test
public void testSupportsGenericsSource() throws Exception
{
JavaType<?> source = Roaster
.parse("public class Test{public void test() {java.util.List<String> s = new java.util.ArrayList<String>(); for (String item : s){}}}");
Assert.assertFalse(source.hasSyntaxErrors());
}

@Test
public void testSupportsGenericsSourceFromConstructor() throws Exception
{
JavaType<?> source = Roaster
.parse("public class Test{public Test() {java.util.List<String> s = new java.util.ArrayList<String>(); for (String item : s){}}}");
Assert.assertFalse(source.hasSyntaxErrors());
}

@Test
public void testSupportsGenericsSourceFromMethod() throws Exception
{
JavaClassSource source = Roaster.parse(JavaClassSource.class, "public class Test{}");
source.addMethod("public void test() {java.util.List<String> s = new java.util.ArrayList<String>(); for (String item : s){}}");
Assert.assertFalse(source.hasSyntaxErrors());
}

@Test
public void testSupportsGenericsSourceFromAddedConstructor() throws Exception
{
JavaClassSource source = Roaster.parse(JavaClassSource.class, "public class Test{}");
// Add a new method to get JDT to recognize the new ASTs
source.addMethod().setConstructor(true).setBody("java.util.List<String> s = new java.util.ArrayList<String>(); for (String item : s){}");
source.addMethod().setConstructor(true)
.setBody("java.util.List<String> s = new java.util.ArrayList<String>(); for (String item : s){}");
// Forces a rewrite to happen via AbstractJavaSource
source.toString();
Assert.assertFalse(source.hasSyntaxErrors());
}

@Test
public void testSupportsGenericsSourceFromAddedMethod() throws Exception {

@Test
public void testSupportsGenericsSourceFromAddedMethod() throws Exception
{
JavaClassSource source = Roaster.parse(JavaClassSource.class, "public class Test{}");
// Add a new method to get JDT to recognize the new ASTs
source.addMethod().setName("test").setBody("java.util.List<String> s = new java.util.ArrayList<String>(); for (String item : s){}");
source.addMethod().setName("test")
.setBody("java.util.List<String> s = new java.util.ArrayList<String>(); for (String item : s){}");
// Forces a rewrite to happen via AbstractJavaSource
source.toString();
Assert.assertFalse(source.hasSyntaxErrors());
}

@Test
public void testSupportsDefaultMethods() throws Exception
{
JavaInterfaceSource source = Roaster.parse(JavaInterfaceSource.class,
"public interface Test{ public default String blah() {return null;}}");
// Forces a rewrite to happen via AbstractJavaSource
source.toString();
Assert.assertFalse(source.hasSyntaxErrors());
Expand Down

0 comments on commit a360942

Please sign in to comment.