• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
3  * Copyright (C) 2011, 2013-2016 The JavaParser Team.
4  *
5  * This file is part of JavaParser.
6  *
7  * JavaParser can be used either under the terms of
8  * a) the GNU Lesser General Public License as published by
9  *     the Free Software Foundation, either version 3 of the License, or
10  *     (at your option) any later version.
11  * b) the terms of the Apache License
12  *
13  * You should have received a copy of both licenses in LICENCE.LGPL and
14  * LICENCE.APACHE. Please refer to those files for details.
15  *
16  * JavaParser is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU Lesser General Public License for more details.
20  */
21 
22 package com.github.javaparser.builders;
23 
24 import com.github.javaparser.ast.CompilationUnit;
25 import com.github.javaparser.ast.body.EnumDeclaration;
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Test;
29 
30 import java.util.function.Function;
31 
32 import static com.github.javaparser.utils.Utils.EOL;
33 import static org.junit.Assert.assertEquals;
34 
35 public class EnumDeclarationBuildersTest {
36     private final CompilationUnit cu = new CompilationUnit();
37 
38     @Test
testAddImplements()39     public void testAddImplements() {
40         EnumDeclaration testEnum = cu.addEnum("test");
41         testEnum.addImplementedType(Function.class);
42         assertEquals(1, cu.getImports().size());
43         assertEquals("import " + Function.class.getName() + ";" + EOL,
44                 cu.getImport(0).toString());
45         assertEquals(1, testEnum.getImplementedTypes().size());
46         assertEquals(Function.class.getSimpleName(), testEnum.getImplementedTypes(0).getNameAsString());
47     }
48 
49     @Test
testAddEnumConstant()50     public void testAddEnumConstant() {
51         EnumDeclaration testEnum = cu.addEnum("test");
52         testEnum.addEnumConstant("MY_ENUM_CONSTANT");
53         assertEquals(1, testEnum.getEntries().size());
54         assertEquals("MY_ENUM_CONSTANT", testEnum.getEntry(0).getNameAsString());
55     }
56 }
57