1 package com.github.javaparser.ast; 2 3 import org.junit.Test; 4 5 import static com.github.javaparser.JavaParser.parse; 6 import static com.github.javaparser.JavaParser.parsePackageDeclaration; 7 import static com.github.javaparser.utils.Utils.EOL; 8 import static org.junit.Assert.assertEquals; 9 10 public class ReplaceNodeTest { 11 @Test testSimplePropertyWithGenericReplace()12 public void testSimplePropertyWithGenericReplace() { 13 CompilationUnit cu = parse("package x; class Y {}"); 14 cu.replace(cu.getPackageDeclaration().get(), parsePackageDeclaration("package z;")); 15 assertEquals(String.format("package z;%1$s" + 16 "%1$s" + 17 "class Y {%1$s" + 18 "}%1$s", EOL), cu.toString()); 19 } 20 21 @Test testListProperty()22 public void testListProperty() { 23 CompilationUnit cu = parse("package x; class Y {}"); 24 cu.replace(cu.getClassByName("Y").get(), parse("class B{int y;}").getClassByName("B").get()); 25 assertEquals(String.format("package x;%1$s" + 26 "%1$s" + 27 "class B {%1$s" + 28 "%1$s" + 29 " int y;%1$s" + 30 "}%1$s", EOL), cu.toString()); 31 } 32 } 33