Skip to content

Commit

Permalink
Reproduce test case for fixing ASSERT-KTH/sorald#603
Browse files Browse the repository at this point in the history
  • Loading branch information
algomaster99 committed Nov 19, 2021
1 parent 91c3bfa commit fb5482f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package spoon.test.fieldaccesses.testclasses;

class SourcePartitionValidator {
public enum MatchingStrategy { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package spoon.test.fieldaccesses.testclasses;

public class SourcePosition {
private SourcePartitionValidator.MatchingStrategy pleaseAttachSourcePositionToMyType;
}
17 changes: 17 additions & 0 deletions src/test/java/spoon/test/serializable/SourcePositionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package spoon.test.serializable;

import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import java.io.ByteArrayOutputStream;
Expand All @@ -25,9 +26,12 @@
import java.io.IOException;
import java.io.OutputStream;

import org.hamcrest.CoreMatchers;
import org.junit.Test;

import spoon.Launcher;
import spoon.reflect.CtModel;
import spoon.reflect.cu.position.NoSourcePosition;
import spoon.reflect.declaration.CtField;
import spoon.reflect.declaration.CtType;
import spoon.reflect.factory.Factory;
Expand Down Expand Up @@ -71,4 +75,17 @@ public void testSourcePosition() throws IOException {
CtField<?> elem2 = typeFromFile.getField("a");
assertTrue(elem1.getPosition().getFile().equals(elem2.getPosition().getFile()));
}

@Test
public void test_sourcePositionOfNestedTypeInFieldExists() {
final Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/java/spoon/test/fieldaccesses/testclasses/SourcePosition.java");
launcher.addInputResource("./src/test/java/spoon/test/fieldaccesses/testclasses/SourcePartitionValidator.java");
CtModel model = launcher.buildModel();

CtField field = (CtField) model.getElements(
element -> element instanceof CtField &&
((CtField) element).getSimpleName().equals("pleaseAttachSourcePositionToMyType")).stream().findFirst().get();
assertThat(field.getType().getPosition(), CoreMatchers.not(CoreMatchers.instanceOf(NoSourcePosition.class)));
}
}

0 comments on commit fb5482f

Please sign in to comment.