From 757736612b01b08ea72fac1c1b48d79330a55205 Mon Sep 17 00:00:00 2001 From: Pavel Vojtechovsky Date: Thu, 15 Jun 2017 19:58:56 +0200 Subject: [PATCH] test nulls in list --- .../java/spoon/test/replace/ReplaceTest.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/test/java/spoon/test/replace/ReplaceTest.java b/src/test/java/spoon/test/replace/ReplaceTest.java index 636c9405586..78a01fa7d63 100644 --- a/src/test/java/spoon/test/replace/ReplaceTest.java +++ b/src/test/java/spoon/test/replace/ReplaceTest.java @@ -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; @@ -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 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 lst = sample.getMethod("statements").getBody().getStatements(); + List 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")