Skip to content

Commit

Permalink
Upgrade Guice to 6 - adds support to run test with jakarta @Inject an…
Browse files Browse the repository at this point in the history
…notations
  • Loading branch information
slachiewicz committed May 27, 2023
1 parent 8ced05e commit 3bbc545
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>5.1.0</version>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.codehaus.plexus.testing;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertNotNull;

@PlexusTest
class PlexusTestJakartaTest {

@Inject
private TestJakartaComponent testJakartaComponent;

@Test
void dependencyShouldBeInjected() {
assertNotNull(testJakartaComponent);
assertNotNull(testJakartaComponent.getTestJakartaComponent2());
assertNotNull(testJakartaComponent.getTestJavaxComponent2());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;

@PlexusTest
class PlexusTestTest {
class PlexusTestJavaxTest {

@Inject
private TestComponent testComponent;
private TestJavaxComponent testJavaxComponent;

@Test
void dependencyShouldBeInjected() {
assertNotNull(testComponent);
assertNotNull(testComponent.getTestComponent2());
assertNotNull(testJavaxComponent);
assertNotNull(testJavaxComponent.getTestComponent2());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.codehaus.plexus.testing;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import jakarta.inject.Inject;
import jakarta.inject.Named;

@Named
public class TestJakartaComponent {
@Inject
private TestJavaxComponent2 testJavaxComponent2;

@Inject
private TestJakartaComponent2 testJakartaComponent2;

public TestJavaxComponent2 getTestJavaxComponent2() {
return testJavaxComponent2;
}

public TestJakartaComponent2 getTestJakartaComponent2() {
return testJakartaComponent2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.codehaus.plexus.testing;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import javax.inject.Named;

@Named
public class TestJakartaComponent2 {}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import javax.inject.Named;

@Named
public class TestComponent {
public class TestJavaxComponent {
@Inject
private TestComponent2 testComponent2;
private TestJavaxComponent2 testJavaxComponent2;

public TestComponent2 getTestComponent2() {
return testComponent2;
public TestJavaxComponent2 getTestComponent2() {
return testJavaxComponent2;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
import javax.inject.Named;

@Named
public class TestComponent2 {}
public class TestJavaxComponent2 {}

0 comments on commit 3bbc545

Please sign in to comment.