blob: cfb6b762a110c1eae07d5c641599c82ed25f576b (
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.junit.builders;
import static org.junit.Assert.assertEquals;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Modifier;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.type.ClassOrInterfaceType;
public class NodeWithThrownExceptionsBuildersTest {
CompilationUnit cu;
@Before
public void setup() {
cu = new CompilationUnit();
}
@After
public void teardown() {
cu = null;
}
@Test
public void testThrows() {
MethodDeclaration addMethod = cu.addClass("test").addMethod("foo", Modifier.PUBLIC);
addMethod.addThrownException(IllegalStateException.class);
assertEquals(1, addMethod.getThrownExceptions().size());
assertEquals(true, addMethod.isThrown(IllegalStateException.class));
addMethod.addThrownException(new ClassOrInterfaceType("Test"));
assertEquals(2, addMethod.getThrownExceptions().size());
assertEquals("Test", addMethod.getThrownException(1).toString());
}
}
|