1 package org.codehaus.plexus.compiler.eclipse;
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 import java.util.Arrays;
27 import java.util.Collection;
28
29 import org.codehaus.plexus.compiler.AbstractCompilerTest;
30 import org.codehaus.plexus.compiler.CompilerConfiguration;
31 import org.junit.jupiter.api.BeforeEach;
32 import org.junit.jupiter.api.Test;
33
34 import static org.hamcrest.MatcherAssert.assertThat;
35 import static org.hamcrest.Matchers.startsWith;
36 import static org.junit.jupiter.api.Assertions.assertThrows;
37
38
39
40
41 public class EclipseCompilerTest extends AbstractCompilerTest {
42
43 @BeforeEach
44 public void setUp() {
45 setCompilerDebug(true);
46 setCompilerDeprecationWarnings(true);
47 }
48
49 @Override
50 protected String getRoleHint() {
51 return "eclipse";
52 }
53
54 @Override
55 protected int expectedErrors() {
56 return 4;
57 }
58
59 @Override
60 protected int expectedWarnings() {
61 return 2;
62 }
63
64 @Override
65 protected Collection<String> expectedOutputFiles() {
66 return Arrays.asList(
67 "org/codehaus/foo/Deprecation.class",
68 "org/codehaus/foo/ExternalDeps.class",
69 "org/codehaus/foo/Person.class",
70 "org/codehaus/foo/ReservedWord.class");
71 }
72
73
74 @Test
75 public void testCustomArgument() throws Exception {
76 CompilerConfiguration compilerConfig = createMinimalCompilerConfig();
77
78 compilerConfig.addCompilerCustomArgument("-key", "value");
79
80 getCompiler().performCompile(compilerConfig);
81 }
82
83 @Test
84 public void testInitializeWarningsForPropertiesArgument() {
85 CompilerConfiguration compilerConfig = createMinimalCompilerConfig();
86
87 compilerConfig.addCompilerCustomArgument("-properties", "file_does_not_exist");
88
89 IllegalArgumentException e =
90 assertThrows(IllegalArgumentException.class, () -> getCompiler().performCompile(compilerConfig));
91 assertThat("Message must start with 'Properties file'", e.getMessage(), startsWith("Properties file"));
92 }
93
94 private CompilerConfiguration createMinimalCompilerConfig() {
95 CompilerConfiguration compilerConfig = new CompilerConfiguration();
96 compilerConfig.setOutputLocation("target/" + getRoleHint() + "/classes-CustomArgument");
97 return compilerConfig;
98 }
99 }