1
2
3
4
5 package com.qulice.errorprone;
6
7 import com.qulice.spi.Environment;
8 import org.hamcrest.MatcherAssert;
9 import org.hamcrest.Matchers;
10 import org.junit.jupiter.api.Test;
11
12
13
14
15
16
17 final class ReleaseTest {
18
19
20
21
22 private static final String RELEASE = "maven.compiler.release";
23
24
25
26
27 private static final String TEST_RELEASE = "maven.compiler.testRelease";
28
29 @Test
30 void addsNothingWhenNoLevelIsPinned() {
31 MatcherAssert.assertThat(
32 "an unpinned project must keep the host default level",
33 new Release(new Environment.Mock(), "main").flags(),
34 Matchers.empty()
35 );
36 }
37
38 @Test
39 void forwardsTheReleaseOfMainSources() {
40 MatcherAssert.assertThat(
41 "the release of the project must reach javac",
42 new Release(
43 new Environment.Mock().withParam(ReleaseTest.RELEASE, "8"),
44 "main"
45 ).flags(),
46 Matchers.contains("--release", "8")
47 );
48 }
49
50 @Test
51 void forwardsSourceAndTargetWhenNoReleaseIsPinned() {
52 MatcherAssert.assertThat(
53 "a project pinning only -source must keep its API surface",
54 new Release(
55 new Environment.Mock()
56 .withParam("maven.compiler.source", "1.8"),
57 "main"
58 ).flags(),
59 Matchers.contains("-source", "8", "-target", "8")
60 );
61 }
62
63 @Test
64 void forwardsTheTestReleaseToTheTestBatch() {
65 MatcherAssert.assertThat(
66 "tests compiled higher than main code must say so",
67 new Release(
68 new Environment.Mock()
69 .withParam(ReleaseTest.RELEASE, "8")
70 .withParam(ReleaseTest.TEST_RELEASE, "17"),
71 "test-1-src-test-java"
72 ).flags(),
73 Matchers.contains("--release", "17")
74 );
75 }
76
77 @Test
78 void forwardsTheTestReleaseToEveryTestRoot() {
79 MatcherAssert.assertThat(
80 "a test root beyond src/test/java must compile at the test level",
81 new Release(
82 new Environment.Mock()
83 .withParam(ReleaseTest.RELEASE, "8")
84 .withParam(ReleaseTest.TEST_RELEASE, "17"),
85 "test-2-src-mock-java"
86 ).flags(),
87 Matchers.contains("--release", "17")
88 );
89 }
90
91 @Test
92 void prefersTheTestSourceOverTheReleaseOfMainSources() {
93 MatcherAssert.assertThat(
94 "a test-specific -source must outrank the main --release",
95 new Release(
96 new Environment.Mock()
97 .withParam(ReleaseTest.RELEASE, "8")
98 .withParam("maven.compiler.testSource", "17"),
99 "test-1-src-test-java"
100 ).flags(),
101 Matchers.contains("-source", "17", "-target", "17")
102 );
103 }
104
105 @Test
106 void fallsBackToMainLevelWhenTestsPinNothing() {
107 MatcherAssert.assertThat(
108 "tests of a project pinning one level must compile at it",
109 new Release(
110 new Environment.Mock().withParam(ReleaseTest.RELEASE, "11"),
111 "test-1-src-test-java"
112 ).flags(),
113 Matchers.contains("--release", "11")
114 );
115 }
116
117 @Test
118 void keepsMainSourcesAwayFromTheTestLevel() {
119 MatcherAssert.assertThat(
120 "the level of the tests must not reach the main batch",
121 new Release(
122 new Environment.Mock()
123 .withParam(ReleaseTest.RELEASE, "8")
124 .withParam(ReleaseTest.TEST_RELEASE, "17"),
125 "main"
126 ).flags(),
127 Matchers.contains("--release", "8")
128 );
129 }
130
131 @Test
132 void forwardsTheTestTargetAlongsideTheTestSource() {
133 MatcherAssert.assertThat(
134 "a test-specific -target must be forwarded too",
135 new Release(
136 new Environment.Mock()
137 .withParam("maven.compiler.testSource", "11")
138 .withParam("maven.compiler.testTarget", "17"),
139 "test-1-src-test-java"
140 ).flags(),
141 Matchers.contains("-source", "11", "-target", "17")
142 );
143 }
144 }