Skip to content

Commit

Permalink
added a few tests in JvmModelGeneratorTest
Browse files Browse the repository at this point in the history
using the new API classToExtend, interfacesToImplement/Extend
  • Loading branch information
LorenzoBettini committed Dec 23, 2023
1 parent 08c9989 commit f620b2a
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
package org.eclipse.xtext.xbase.tests.compiler;

import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
Expand Down Expand Up @@ -184,6 +185,17 @@ public void testImplements() throws Exception {
Assert.assertTrue(Iterable.class.isAssignableFrom(compiled));
}

@Test
public void testImplementsWithInterfacesToImplement() throws Exception {
XExpression expression = expression("null", false);
JvmGenericType clazz = builder.toClass(expression, "my.test.Foo", (JvmGenericType it) -> {
it.setAbstract(true);
it.getInterfacesToImplement().add(typeRef(expression, Iterable.class, String.class));
});
Class<?> compiled = compile(expression.eResource(), clazz);
Assert.assertTrue(Iterable.class.isAssignableFrom(compiled));
}

@Test
public void testExtends() throws Exception {
XExpression expression = expression("null", false);
Expand All @@ -196,6 +208,30 @@ public void testExtends() throws Exception {
Assert.assertTrue(AbstractList.class.isAssignableFrom(compiled));
}

@Test
public void testExtendsWithClassToExtend() throws Exception {
XExpression expression = expression("null", false);
JvmGenericType clazz = builder.toClass(expression, "my.test.Foo", (JvmGenericType it) -> {
it.setAbstract(true);
it.setClassToExtend(typeRef(expression, AbstractList.class, String.class));
});
Class<?> compiled = compile(expression.eResource(), clazz);
Assert.assertTrue(Iterable.class.isAssignableFrom(compiled));
Assert.assertTrue(AbstractList.class.isAssignableFrom(compiled));
}

@Test
public void testInterfaceExtendsWithInterfacesToImplement() throws Exception {
XExpression expression = expression("null", false);
JvmGenericType clazz = builder.toInterface(expression, "my.test.Foo", (JvmGenericType it) -> {
it.getInterfacesToExtend().add(typeRef(expression, Iterable.class, String.class));
it.getInterfacesToExtend().add(typeRef(expression, Serializable.class));
});
Class<?> compiled = compile(expression.eResource(), clazz);
Assert.assertTrue(Iterable.class.isAssignableFrom(compiled));
Assert.assertTrue(Serializable.class.isAssignableFrom(compiled));
}

@Test
public void testCompilationStrategy() throws Exception {
XExpression expression = expression("null", false);
Expand Down

0 comments on commit f620b2a

Please sign in to comment.