Skip to content

[wip] Refactor: move test resources to testclasses directories #2147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import spoon.reflect.code.CtExpression;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtField;
import spoon.support.compiler.jdt.testclasses.ExtendedStringLiteralTestClass;

public class ExtendedStringLiteralTest {

Expand Down Expand Up @@ -59,7 +60,7 @@ this.jdtCompiler.requestor, getProblemFactory(), this.out,
comp.build();

CtClass<?> cl =
comp.getFactory().Package().get("spoon.support.compiler.jdt").
comp.getFactory().Package().get("spoon.support.compiler.jdt.testclasses").
getType("ExtendedStringLiteralTestClass");
CtField<?> f = cl.getField("extendedStringLiteral");
CtExpression<?> de = f.getDefaultExpression();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package spoon.support.compiler.jdt;
package spoon.support.compiler.jdt.testclasses;

public class ExtendedStringLiteralTestClass {

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/spoon/test/arrays/ArraysTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public class ArraysTest {

@Test
public void testArrayReferences() throws Exception {
CtType<?> type = build("spoon.test.arrays", "ArrayClass");
CtType<?> type = build("spoon.test.arrays.testclasses", "ArrayClass");
assertEquals("ArrayClass", type.getSimpleName());
assertEquals("int[][][]", type.getField("i").getType().getSimpleName());
assertEquals(3, ((CtArrayTypeReference<?>) type.getField("i").getType()).getDimensionCount());
final CtArrayTypeReference<?> arrayTypeReference = (CtArrayTypeReference<?>) type.getField("i").getDefaultExpression().getType();
assertEquals(1, arrayTypeReference.getArrayType().getAnnotations().size());
assertEquals("@spoon.test.arrays.ArrayClass.TypeAnnotation(integer = 1)", arrayTypeReference.getArrayType().getAnnotations().get(0).toString());
assertEquals("@spoon.test.arrays.testclasses.ArrayClass.TypeAnnotation(integer = 1)", arrayTypeReference.getArrayType().getAnnotations().get(0).toString());

CtField<?> x = type.getField("x");
assertTrue(x.getType() instanceof CtArrayTypeReference);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package spoon.test.arrays;
package spoon.test.arrays.testclasses;

import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/spoon/test/casts/CastTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import spoon.reflect.visitor.Query;
import spoon.reflect.visitor.filter.NamedElementFilter;
import spoon.reflect.visitor.filter.TypeFilter;
import spoon.test.casts.testclasses.Castings;
import spoon.testing.utils.ModelUtils;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -75,7 +76,7 @@ public void testCast3() {
public void testCase4() throws Exception {
// contract: If the invocation is to a method where the returned type is a generic type,
// getType returns the actual type bound to this particular invocation.
CtType<?> type = build("spoon.test.casts", "Castings");
CtType<?> type = build("spoon.test.casts.testclasses", "Castings");

final CtMethod<?> getValueMethod = type.getMethodsByName("getValue").get(0);
final CtInvocation<?> getValueInvocation = Query.getElements(type, new TypeFilter<CtInvocation<?>>(CtInvocation.class) {
Expand All @@ -97,6 +98,6 @@ public void testTypeAnnotationOnCast() throws Exception {
final CtLocalVariable local = aCastings.getMethod("bar").getElements(new TypeFilter<>(CtLocalVariable.class)).get(0);

assertEquals(1, ((CtTypeReference) local.getDefaultExpression().getTypeCasts().get(0)).getAnnotations().size());
assertEquals("(([email protected](integer = 1)" + System.lineSeparator() + "String) (\"\"))", local.getDefaultExpression().toString());
assertEquals("(([email protected].testclasses.Castings.TypeAnnotation(integer = 1)" + System.lineSeparator() + "String) (\"\"))", local.getDefaultExpression().toString());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package spoon.test.casts;
package spoon.test.casts.testclasses;

import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/spoon/test/compilation/CompilationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import spoon.support.compiler.jdt.JDTBatchCompiler;
import spoon.test.compilation.testclasses.Bar;
import spoon.test.compilation.testclasses.IBar;
import spoon.test.compilation.testclasses.Ifoo;
import spoon.testing.utils.ModelUtils;

public class CompilationTest {
Expand Down Expand Up @@ -150,7 +151,7 @@ public void testNewInstance() throws Exception {
// contract: a ctclass can be instantiated, and each modification results in a new valid object
Factory factory = new Launcher().getFactory();
CtClass<Ifoo> c = factory.Code().createCodeSnippetStatement(
"class X implements spoon.test.compilation.Ifoo { public int foo() {int i=0; return i;} }").compile();
"class X implements spoon.test.compilation.testclasses.Ifoo { public int foo() {int i=0; return i;} }").compile();
c.addModifier(ModifierKind.PUBLIC); // required otherwise java.lang.IllegalAccessException at runtime when instantiating

CtBlock body = c.getElements(new TypeFilter<>(CtBlock.class)).get(1);
Expand Down
5 changes: 0 additions & 5 deletions src/test/java/spoon/test/compilation/Ifoo.java

This file was deleted.

5 changes: 5 additions & 0 deletions src/test/java/spoon/test/compilation/testclasses/Ifoo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package spoon.test.compilation.testclasses;

public interface Ifoo {
int foo();
}
4 changes: 2 additions & 2 deletions src/test/java/spoon/test/ctCase/SwitchCaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class SwitchCaseTest {

@Test
public void insertAfterStatementInSwitchCaseWithoutException() throws Exception {
String packageName = "spoon.test.ctCase";
String packageName = "spoon.test.ctCase.testclasses";
String className = "ClassWithSwitchExample";
Factory factory = factoryFor(packageName, className);
List<CtCase> elements = elementsOfType(CtCase.class, factory);
Expand All @@ -37,7 +37,7 @@ public void insertAfterStatementInSwitchCaseWithoutException() throws Exception

@Test
public void insertBeforeStatementInSwitchCaseWithoutException() throws Exception {
String packageName = "spoon.test.ctCase";
String packageName = "spoon.test.ctCase.testclasses";
String className = "ClassWithSwitchExample";
Factory factory = factoryFor(packageName, className);
List<CtCase> elements = elementsOfType(CtCase.class, factory);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package spoon.test.ctCase;
package spoon.test.ctCase.testclasses;

public class ClassWithSwitchExample {

Expand Down
5 changes: 3 additions & 2 deletions src/test/java/spoon/test/enums/EnumsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import spoon.test.enums.testclasses.Burritos;
import spoon.test.enums.testclasses.Foo;
import spoon.test.enums.testclasses.NestedEnums;
import spoon.test.enums.testclasses.Regular;
import spoon.testing.utils.ModelUtils;

import static org.junit.Assert.assertEquals;
Expand All @@ -36,7 +37,7 @@ public class EnumsTest {

@Test
public void testModelBuildingEnum() throws Exception {
CtEnum<Regular> enumeration = build("spoon.test.enums", "Regular");
CtEnum<Regular> enumeration = build("spoon.test.enums.testclasses", "Regular");
assertEquals("Regular", enumeration.getSimpleName());
assertEquals(3, Regular.values().length);
assertEquals(3, enumeration.getEnumValues().size());
Expand Down Expand Up @@ -147,7 +148,7 @@ public void testPrintEnumValues() throws IOException {

@Test
public void testEnumValue() {
// contract: constructorCall on enumvalues should be implicit if they're not declared
// contract: constructorCall on enum values should be implicit if they're not declared

Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/java/spoon/test/comment/testclasses/EnumClass.java");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package spoon.test.enums;
package spoon.test.enums.testclasses;

import java.util.Stack;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package spoon.test.enums;
package spoon.test.enums.testclasses;

import java.util.Stack;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package spoon.test.enums;
package spoon.test.enums.testclasses;

public enum Regular {
A, B, C;
Expand Down