Skip to content

Commit

Permalink
add multiple tests on modifying ASimpleClassWithMoreFormatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomassetti committed May 21, 2017
1 parent 924ceac commit db78839
Showing 1 changed file with 45 additions and 11 deletions.
Expand Up @@ -546,28 +546,62 @@ public void handleOverrideAnnotation() {
} }


@Test @Test
public void addingParameterToMethod() throws IOException { public void preserveSpaceAsIsForASimpleClassWithMoreFormatting() throws IOException {
considerExample("ASimpleClassWithMoreFormatting"); considerExample("ASimpleClassWithMoreFormatting");
assertEquals(readExample("ASimpleClassWithMoreFormatting"), lpp.print(cu)); assertEquals(readExample("ASimpleClassWithMoreFormatting"), lpp.print(cu));
}

@Test
public void renameASimpleClassWithMoreFormatting() throws IOException {
considerExample("ASimpleClassWithMoreFormatting");


cu.getClassByName("ASimpleClass").get() cu.getClassByName("ASimpleClass").get()
.setName("MyRenamedClass"); .setName("MyRenamedClass");
assertEquals(readExample("ASimpleClassWithMoreFormatting_step1"), lpp.print(cu)); assertEquals(readExample("ASimpleClassWithMoreFormatting_step1"), lpp.print(cu));
}

@Test
public void addMethodToASimpleClassWithMoreFormatting() throws IOException {
considerExample("ASimpleClassWithMoreFormatting");


// Adding a method: we add a setter cu.getClassByName("ASimpleClass").get()
.setName("MyRenamedClass");
MethodDeclaration setter = cu MethodDeclaration setter = cu
.getClassByName("MyRenamedClass").get() .getClassByName("MyRenamedClass").get()
.addMethod("setAField", Modifier.PUBLIC); .addMethod("setAField", Modifier.PUBLIC);
assertEquals(readExample("ASimpleClassWithMoreFormatting_step2"), lpp.print(cu)); assertEquals(readExample("ASimpleClassWithMoreFormatting_step2"), lpp.print(cu));
// setter.addParameter("boolean", "aField"); }
// assertEquals(readExample("ASimpleClassWithMoreFormatting_step3"), lpp.print(cu));
// setter.getBody().get().getStatements().add(new ExpressionStmt( @Test
// new AssignExpr( public void addingParameterToAnAddedMethodInASimpleClassWithMoreFormatting() throws IOException {
// new FieldAccessExpr(new ThisExpr(),"aField"), considerExample("ASimpleClassWithMoreFormatting");
// new NameExpr("aField"),
// AssignExpr.Operator.ASSIGN cu.getClassByName("ASimpleClass").get()
// ))); .setName("MyRenamedClass");
// assertEquals(readExample("ASimpleClassWithMoreFormatting_step4"), lpp.print(cu)); MethodDeclaration setter = cu
.getClassByName("MyRenamedClass").get()
.addMethod("setAField", Modifier.PUBLIC);
setter.addParameter("boolean", "aField");
assertEquals(readExample("ASimpleClassWithMoreFormatting_step3"), lpp.print(cu));
}

@Test
public void addingStatementToAnAddedMethodInASimpleClassWithMoreFormatting() throws IOException {
considerExample("ASimpleClassWithMoreFormatting");

cu.getClassByName("ASimpleClass").get()
.setName("MyRenamedClass");
MethodDeclaration setter = cu
.getClassByName("MyRenamedClass").get()
.addMethod("setAField", Modifier.PUBLIC);
setter.addParameter("boolean", "aField");
setter.getBody().get().getStatements().add(new ExpressionStmt(
new AssignExpr(
new FieldAccessExpr(new ThisExpr(),"aField"),
new NameExpr("aField"),
AssignExpr.Operator.ASSIGN
)));
assertEquals(readExample("ASimpleClassWithMoreFormatting_step4"), lpp.print(cu));
} }


} }

0 comments on commit db78839

Please sign in to comment.