Skip to content

Commit 3bbc545

Browse files
committed
Upgrade Guice to 6 - adds support to run test with jakarta @Inject annotations
1 parent 8ced05e commit 3bbc545

7 files changed

+114
-10
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<dependency>
4444
<groupId>com.google.inject</groupId>
4545
<artifactId>guice</artifactId>
46-
<version>5.1.0</version>
46+
<version>6.0.0</version>
4747
</dependency>
4848
<dependency>
4949
<groupId>org.junit.jupiter</groupId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.codehaus.plexus.testing;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
import jakarta.inject.Inject;
23+
import org.junit.jupiter.api.Test;
24+
25+
import static org.junit.jupiter.api.Assertions.assertNotNull;
26+
27+
@PlexusTest
28+
class PlexusTestJakartaTest {
29+
30+
@Inject
31+
private TestJakartaComponent testJakartaComponent;
32+
33+
@Test
34+
void dependencyShouldBeInjected() {
35+
assertNotNull(testJakartaComponent);
36+
assertNotNull(testJakartaComponent.getTestJakartaComponent2());
37+
assertNotNull(testJakartaComponent.getTestJavaxComponent2());
38+
}
39+
}

src/test/java/org/codehaus/plexus/testing/PlexusTestTest.java renamed to src/test/java/org/codehaus/plexus/testing/PlexusTestJavaxTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
import static org.junit.jupiter.api.Assertions.assertNotNull;
2727

2828
@PlexusTest
29-
class PlexusTestTest {
29+
class PlexusTestJavaxTest {
3030

3131
@Inject
32-
private TestComponent testComponent;
32+
private TestJavaxComponent testJavaxComponent;
3333

3434
@Test
3535
void dependencyShouldBeInjected() {
36-
assertNotNull(testComponent);
37-
assertNotNull(testComponent.getTestComponent2());
36+
assertNotNull(testJavaxComponent);
37+
assertNotNull(testJavaxComponent.getTestComponent2());
3838
}
3939
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.codehaus.plexus.testing;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
import jakarta.inject.Inject;
23+
import jakarta.inject.Named;
24+
25+
@Named
26+
public class TestJakartaComponent {
27+
@Inject
28+
private TestJavaxComponent2 testJavaxComponent2;
29+
30+
@Inject
31+
private TestJakartaComponent2 testJakartaComponent2;
32+
33+
public TestJavaxComponent2 getTestJavaxComponent2() {
34+
return testJavaxComponent2;
35+
}
36+
37+
public TestJakartaComponent2 getTestJakartaComponent2() {
38+
return testJakartaComponent2;
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.codehaus.plexus.testing;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
import javax.inject.Named;
23+
24+
@Named
25+
public class TestJakartaComponent2 {}

src/test/java/org/codehaus/plexus/testing/TestComponent.java renamed to src/test/java/org/codehaus/plexus/testing/TestJavaxComponent.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
import javax.inject.Named;
2424

2525
@Named
26-
public class TestComponent {
26+
public class TestJavaxComponent {
2727
@Inject
28-
private TestComponent2 testComponent2;
28+
private TestJavaxComponent2 testJavaxComponent2;
2929

30-
public TestComponent2 getTestComponent2() {
31-
return testComponent2;
30+
public TestJavaxComponent2 getTestComponent2() {
31+
return testJavaxComponent2;
3232
}
3333
}

src/test/java/org/codehaus/plexus/testing/TestComponent2.java renamed to src/test/java/org/codehaus/plexus/testing/TestJavaxComponent2.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
import javax.inject.Named;
2323

2424
@Named
25-
public class TestComponent2 {}
25+
public class TestJavaxComponent2 {}

0 commit comments

Comments
 (0)