blob: 5775bd049907b3bd4a0a4ab09765493d9d97b510 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
package com.github.javaparser.ast.stmt;
import com.github.javaparser.JavaParser;
import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.ast.expr.MethodCallExpr;
import com.github.javaparser.ast.expr.NameExpr;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class IfElseStmtTest {
@Test
public void issue1247withElseSingleStmt() {
IfStmt ifStmt = (IfStmt) JavaParser.parseStatement("if (cond) doSomething(); else doSomethingElse();");
assertEquals(false, ifStmt.hasElseBlock());
assertEquals(true, ifStmt.hasElseBranch());
assertEquals(false, ifStmt.hasCascadingIfStmt());
}
@Test
public void issue1247withElseBlockStmt() {
IfStmt ifStmt = (IfStmt) JavaParser.parseStatement("if (cond) doSomething(); else { doSomethingElse(); }");
assertEquals(true, ifStmt.hasElseBlock());
assertEquals(true, ifStmt.hasElseBranch());
assertEquals(false, ifStmt.hasCascadingIfStmt());
}
@Test
public void issue1247withElseSingleStmtWhichIsAnIf() {
IfStmt ifStmt = (IfStmt) JavaParser.parseStatement("if (cond1) doSomething(); else if (cond2) doSomethingElse();");
assertEquals(false, ifStmt.hasElseBlock());
assertEquals(true, ifStmt.hasElseBranch());
assertEquals(true, ifStmt.hasCascadingIfStmt());
}
}
|