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
22package com.github.javaparser.printer.lexicalpreservation.transformations.ast.body;
23
24import com.github.javaparser.ast.Modifier;
25import com.github.javaparser.ast.body.EnumDeclaration;
26import com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest;
27import org.junit.Test;
28
29import java.io.IOException;
30import java.util.EnumSet;
31
32/**
33 * Transforming EnumDeclaration and verifying the LexicalPreservation works as expected.
34 */
35public class EnumDeclarationTransformationsTest extends AbstractLexicalPreservingTest {
36
37    protected EnumDeclaration consider(String code) {
38        considerCode(code);
39        return cu.getType(0).asEnumDeclaration();
40    }
41
42    // Name
43
44    @Test
45    public void settingName() throws IOException {
46        EnumDeclaration cid = consider("enum A { E1, E2 }");
47        cid.setName("B");
48        assertTransformedToString("enum B { E1, E2 }", cid);
49    }
50
51    // implementedTypes
52
53    // Modifiers
54
55    @Test
56    public void addingModifiers() throws IOException {
57        EnumDeclaration ed = consider("enum A { E1, E2 }");
58        ed.setModifiers(EnumSet.of(Modifier.PUBLIC));
59        assertTransformedToString("public enum A { E1, E2 }", ed);
60    }
61
62    @Test
63    public void removingModifiers() throws IOException {
64        EnumDeclaration ed = consider("public enum A { E1, E2 }");
65        ed.setModifiers(EnumSet.noneOf(Modifier.class));
66        assertTransformedToString("enum A { E1, E2 }", ed);
67    }
68
69    @Test
70    public void replacingModifiers() throws IOException {
71        EnumDeclaration ed = consider("public enum A { E1, E2 }");
72        ed.setModifiers(EnumSet.of(Modifier.PROTECTED));
73        assertTransformedToString("protected enum A { E1, E2 }", ed);
74    }
75
76    // members
77
78    // Annotations
79
80    // Javadoc
81
82}
83