Skip to content

Commit

Permalink
test nulls in list
Browse files Browse the repository at this point in the history
  • Loading branch information
pvojtechovsky committed Jun 15, 2017
1 parent 15de125 commit 7577366
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/test/java/spoon/test/replace/ReplaceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import spoon.test.replace.testclasses.Mole;
import spoon.test.replace.testclasses.Tacos;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -163,6 +164,45 @@ public void testReplaceStmtByList() {
assertEquals(2, ((CtBlock) sample.getMethod("retry").getBody().getStatement(0)).getStatements().size());
}

@Test
public void testReplaceStmtByListStatements() {
CtClass<?> sample = factory.Package().get("spoon.test.replace.testclasses")
.getType("Foo");

// replace retry content by statements
CtStatement stmt = sample.getMethod("retry").getBody().getStatement(0);
List<CtStatement> lst = sample.getMethod("statements").getBody().getStatements();

// replace a single statement by a statement list
stmt.replace(lst);

// we should have only 2 statements after (from the stmt list)
assertEquals(2, sample.getMethod("retry").getBody().getStatements().size());
}

@Test
public void testReplaceStmtByListStatementsAndNull() {
//contract: null elements in list are ignored
CtClass<?> sample = factory.Package().get("spoon.test.replace.testclasses")
.getType("Foo");

// replace retry content by statements
CtStatement stmt = sample.getMethod("retry").getBody().getStatement(0);
List<CtStatement> lst = sample.getMethod("statements").getBody().getStatements();
List<CtStatement> lstWithNulls = new ArrayList<>();
lstWithNulls.add(null);
lstWithNulls.add(lst.get(0));
lstWithNulls.add(null);
lstWithNulls.add(lst.get(1));
lstWithNulls.add(null);

// replace a single statement by a statement list
stmt.replace(lstWithNulls);

// we should have only 2 statements after (from the stmt list)
assertEquals(2, sample.getMethod("retry").getBody().getStatements().size());
}

@Test
public void testReplaceField() {
CtClass<?> sample = factory.Package().get("spoon.test.replace.testclasses")
Expand Down

0 comments on commit 7577366

Please sign in to comment.