Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58441c9
commit 982be37
Showing
2 changed files
with
112 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 82 additions & 16 deletions
98
...ting/src/test/java/com/github/javaparser/junit/builders/FieldDeclarationBuildersTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,25 +1,91 @@ | |||
package com.github.javaparser.junit.builders; | package com.github.javaparser.junit.builders; | ||
|
|
||
import static org.junit.Assert.assertEquals; | |||
|
|||
import java.util.List; | |||
|
|||
import org.junit.After; | import org.junit.After; | ||
import org.junit.Before; | import org.junit.Before; | ||
import org.junit.Test; | |||
|
|
||
import com.github.javaparser.ast.CompilationUnit; | import com.github.javaparser.ast.CompilationUnit; | ||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; | |||
import com.github.javaparser.ast.body.EnumDeclaration; | |||
import com.github.javaparser.ast.body.FieldDeclaration; | |||
import com.github.javaparser.ast.body.MethodDeclaration; | |||
import com.github.javaparser.ast.body.VariableDeclarator; | |||
import com.github.javaparser.ast.body.VariableDeclaratorId; | |||
import com.github.javaparser.ast.stmt.ReturnStmt; | |||
|
|
||
public class FieldDeclarationBuildersTest { | public class FieldDeclarationBuildersTest { | ||
CompilationUnit cu; | CompilationUnit cu; | ||
|
private ClassOrInterfaceDeclaration testClass; | ||
@Before | private EnumDeclaration testEnum; | ||
public void setup() { |
|
||
cu = new CompilationUnit(); | @Before | ||
} | public void setup() { | ||
|
cu = new CompilationUnit(); | ||
@After | testClass = cu.addClass("testClass"); | ||
public void teardown() { | testEnum = cu.addEnum("testEnum"); | ||
cu = null; | } | ||
} |
|
||
/* | @After | ||
FieldDeclaration | public void teardown() { | ||
public MethodDeclaration createGetter() { | cu = null; | ||
public MethodDeclaration createSetter() { | testClass = null; | ||
*/ | testEnum = null; | ||
} | |||
|
|||
@Test(expected = IllegalStateException.class) | |||
public void testOrphanFieldGetter() { | |||
new FieldDeclaration().createGetter(); | |||
} | |||
|
|||
@Test(expected = IllegalStateException.class) | |||
public void testOrphanFieldSetter() { | |||
new FieldDeclaration().createSetter(); | |||
} | |||
|
|||
@Test | |||
public void testCreateGetterInAClass() { | |||
testClass.addPrivateField(int.class, "myField").createGetter(); | |||
assertEquals(2, testClass.getMembers().size()); | |||
assertEquals(MethodDeclaration.class, testClass.getMembers().get(1).getClass()); | |||
List<MethodDeclaration> methodsWithName = testClass.getMethodsWithName("getMyField"); | |||
assertEquals(1, methodsWithName.size()); | |||
MethodDeclaration getter = methodsWithName.get(0); | |||
assertEquals("getMyField", getter.getName()); | |||
assertEquals("int", getter.getType().toString()); | |||
assertEquals(ReturnStmt.class, getter.getBody().getStmts().get(0).getClass()); | |||
} | |||
|
|||
@Test | |||
public void testCreateSetterInAClass() { | |||
testClass.addPrivateField(int.class, "myField").createSetter(); | |||
// TODO asserts | |||
} | |||
|
|||
@Test | |||
public void testCreateGetterInEnum() { | |||
testEnum.addPrivateField(int.class, "myField").createGetter(); | |||
// TODO asserts | |||
} | |||
|
|||
@Test | |||
public void testCreateSetterInEnum() { | |||
testEnum.addPrivateField(int.class, "myField").createSetter(); | |||
// TODO asserts | |||
} | |||
|
|||
@Test(expected = IllegalStateException.class) | |||
public void testCreateGetterWithANonValidField() { | |||
FieldDeclaration myPrivateField = testClass.addPrivateField(int.class, "myField"); | |||
myPrivateField.getVariables().add(new VariableDeclarator(new VariableDeclaratorId("secondField"))); | |||
myPrivateField.createGetter(); | |||
} | |||
/* | |||
* FieldDeclaration | |||
* public MethodDeclaration createGetter() { | |||
* public MethodDeclaration createSetter() { | |||
*/ | |||
} | } |