Skip to content

Commit

Permalink
Merge pull request #278 from bmarwell/jdk16-17
Browse files Browse the repository at this point in the history
(build) fix JDK 16/17 builds
  • Loading branch information
bmarwell authored Jan 13, 2021
2 parents 40c959f + eca1f2a commit cf2d085
Show file tree
Hide file tree
Showing 13 changed files with 218 additions and 154 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest, windows-latest, macOS-latest ]
java: [ 8, 11, 15, 16-ea, 17-ea ]
java: [ 8, 11, 15, 16-ea ]
fail-fast: false

runs-on: ${{ matrix.os }}
Expand Down
12 changes: 12 additions & 0 deletions integration-tests/guice3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,16 @@
</dependency>
</dependencies>

<profiles>
<profile>
<id>jdk16</id>
<activation>
<jdk>[16,)</jdk>
</activation>
<properties>
<surefire.argLine>--illegal-access=permit</surefire.argLine>
<failsafe.argLine>--illegal-access=permit</failsafe.argLine>
</properties>
</profile>
</profiles>
</project>
12 changes: 12 additions & 0 deletions integration-tests/guice4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,16 @@
</dependency>
</dependencies>

<profiles>
<profile>
<id>jdk16</id>
<activation>
<jdk>[16,)</jdk>
</activation>
<properties>
<surefire.argLine>--illegal-access=permit</surefire.argLine>
<failsafe.argLine>--illegal-access=permit</failsafe.argLine>
</properties>
</profile>
</profiles>
</project>
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
<!-- Replaced by the build number plugin at build time: -->
<buildNumber>${user.name}-${maven.build.timestamp}</buildNumber>
<jacoco.skip>true</jacoco.skip>
<!--suppress CheckTagEmptyBody -->
<surefire.argLine></surefire.argLine>
<!--suppress CheckTagEmptyBody -->
<failsafe.argLine></failsafe.argLine>

<!-- non-dependency-based properties: -->
<shiro.osgi.importRange>[2, 3)</shiro.osgi.importRange>
Expand Down Expand Up @@ -110,6 +114,7 @@

<!-- Test 3rd-party dependencies: -->
<easymock.version>4.0.2</easymock.version>
<mockito.version>3.7.0</mockito.version>
<gmaven.version>1.12.0</gmaven.version>
<groovy.version>3.0.7</groovy.version>
<junit.version>5.6.2</junit.version>
Expand Down Expand Up @@ -433,6 +438,7 @@
<configuration>
<printSummary>true</printSummary>
<useSystemClassLoader>false</useSystemClassLoader>
<argLine>${surefire.argLine}</argLine>
</configuration>
</plugin>
<plugin>
Expand All @@ -450,6 +456,7 @@
<exclude>**/*ManualIT.java</exclude>
<exclude>**/*ManualIT.groovy</exclude>
</excludes>
<argLine>${failsafe.argLine}</argLine>
</configuration>
<executions>
<execution>
Expand Down Expand Up @@ -690,6 +697,12 @@
<version>${easymock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<!-- Writing tests in groovy is fast!: -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
Expand Down Expand Up @@ -1230,6 +1243,7 @@
<link>https://docs.spring.io/spring/docs/2.5.x/javadoc-api/</link>
<link>https://junit.org/junit4/javadoc/4.12/</link>
<link>http://easymock.org/api/easymock/2.4</link>
<link>https://javadoc.io/doc/org.mockito/mockito-core/${mockito.version}/org/mockito/Mockito.html</link>
<link>https://www.quartz-scheduler.org/api/1.8.6/</link>
</links>
<!-- Don't include the sample apps - they're not part of Shiro's API: -->
Expand Down Expand Up @@ -1400,6 +1414,12 @@
</pluginManagement>
</build>
</profile>
<profile>
<id>jdk16</id>
<activation>
<jdk>[16,)</jdk>
</activation>
</profile>
<profile>
<id>docs</id>
<build>
Expand Down
12 changes: 12 additions & 0 deletions samples/guice/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,16 @@
</dependency>
</dependencies>

<profiles>
<profile>
<id>jdk16</id>
<activation>
<jdk>[16,)</jdk>
</activation>
<properties>
<surefire.argLine>--illegal-access=permit</surefire.argLine>
<failsafe.argLine>--illegal-access=permit</failsafe.argLine>
</properties>
</profile>
</profiles>
</project>
12 changes: 12 additions & 0 deletions support/guice/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,16 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>jdk16</id>
<activation>
<jdk>[16,)</jdk>
</activation>
<properties>
<surefire.argLine>--illegal-access=permit</surefire.argLine>
</properties>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,33 @@
*/
package org.apache.shiro.guice;

import com.google.inject.*;
import com.google.inject.ConfigurationException;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.MembersInjector;
import com.google.inject.Provider;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
import com.google.inject.spi.Message;
import com.google.inject.spi.TypeEncounter;
import org.apache.shiro.guice.aop.ShiroAopModule;
import org.apache.shiro.guice.web.ShiroWebModule;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.aop.DefaultAnnotationResolver;
import org.apache.shiro.crypto.cipher.BlowfishCipherService;
import org.easymock.Capture;
import org.easymock.IMocksControl;
import org.apache.shiro.guice.aop.ShiroAopModule;
import org.apache.shiro.guice.web.ShiroWebModule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;

import java.util.Collections;
import java.util.Map;

import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
* Test Cases::
Expand Down Expand Up @@ -64,43 +73,38 @@ public void testMatchedPackage() throws Exception {

@Test
public void testPropertySetting() throws Exception {
IMocksControl control = createControl();
TypeEncounter<SomeInjectableBean> encounter = control.createMock(TypeEncounter.class);
TypeEncounter<SomeInjectableBean> encounter = mock(TypeEncounter.class);

Provider<Injector> injectorProvider = control.createMock(Provider.class);
Injector injector = control.createMock(Injector.class);
Provider<Injector> injectorProvider = mock(Provider.class);
Injector injector = mock(Injector.class);

expect(encounter.getProvider(Injector.class)).andReturn(injectorProvider);
when(encounter.getProvider(Injector.class)).then(args -> injectorProvider);

expect(injectorProvider.get()).andReturn(injector).anyTimes();
when(injectorProvider.get()).then(args -> injector);

Capture<MembersInjector<SomeInjectableBean>> capture = Capture.newInstance();
encounter.register(and(anyObject(MembersInjector.class), capture(capture)));
ArgumentCaptor<MembersInjector<SomeInjectableBean>> captor = ArgumentCaptor.forClass(MembersInjector.class);

SecurityManager securityManager = control.createMock(SecurityManager.class);
SecurityManager securityManager = mock(SecurityManager.class);
String property = "myPropertyValue";

expect(injector.getInstance(Key.get(SecurityManager.class))).andReturn(securityManager);
expect(injector.getInstance(Key.get(String.class, Names.named("shiro.myProperty")))).andReturn(property);
expect(injector.getInstance(Key.get(String.class, Names.named("shiro.unavailableProperty"))))
.andThrow(new ConfigurationException(Collections.singleton(new Message("Not Available!"))));
expect((Map)injector.getInstance(BeanTypeListener.MAP_KEY)).andReturn(Collections.EMPTY_MAP).anyTimes();

control.replay();
when(injector.getInstance(Key.get(SecurityManager.class))).then(args -> securityManager);
when(injector.getInstance(Key.get(String.class, Names.named("shiro.myProperty")))).then(args -> property);
when(injector.getInstance(Key.get(String.class, Names.named("shiro.unavailableProperty"))))
.thenThrow(new ConfigurationException(Collections.singleton(new Message("Not Available!"))));
when((Map) injector.getInstance(BeanTypeListener.MAP_KEY)).then(args -> Collections.EMPTY_MAP);

BeanTypeListener underTest = new BeanTypeListener();

underTest.hear(TypeLiteral.get(SomeInjectableBean.class), encounter);

SomeInjectableBean bean = new SomeInjectableBean();

capture.getValue().injectMembers(bean);
verify(encounter).register(captor.capture());
captor.getValue().injectMembers(bean);

assertSame(securityManager, bean.securityManager);
assertSame(property, bean.myProperty);
assertNull(bean.unavailableProperty);

control.verify();
}

public static class SomeInjectableBean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import com.hazelcast.core.HazelcastInstance
import com.hazelcast.core.LifecycleService
import org.junit.Test

import static org.easymock.EasyMock.*
import static org.junit.Assert.*
import static org.mockito.Mockito.*

/**
* Unit tests for {@link HazelcastCacheManager}.
Expand All @@ -40,15 +40,11 @@ class HazelcastCacheManagerTest {
HazelcastInstance hc = mock(HazelcastInstance)
def manager = new HazelcastCacheManager();

replay hc

// when
manager.hazelcastInstance = hc

// then
assertSame hc, manager.hazelcastInstance

verify hc
}

@Test
Expand All @@ -69,35 +65,31 @@ class HazelcastCacheManagerTest {
void testImplicitlyCreated() {

// given
HazelcastInstance hazelcastInstance = niceMock(HazelcastInstance)
HazelcastInstance hazelcastInstance = mock(HazelcastInstance)

HazelcastCacheManager manager = createMockBuilder(HazelcastCacheManager)
.addMockedMethod("createHazelcastInstance")
.niceMock();
expect(manager.createHazelcastInstance()).andReturn(hazelcastInstance)
HazelcastCacheManager manager = spy(HazelcastCacheManager);
when(manager.createHazelcastInstance()).then(args -> hazelcastInstance)

// when
manager.init()

// then
assertTrue manager.implicitlyCreated
manager.destroy()
}

@Test
void testDestroy() {

// given
LifecycleService lifecycleService = niceMock(LifecycleService)
LifecycleService lifecycleService = mock(LifecycleService)

HazelcastInstance hazelcastInstance = niceMock(HazelcastInstance)
expect(hazelcastInstance.getLifecycleService()).andReturn(lifecycleService)
HazelcastInstance hazelcastInstance = spy(HazelcastInstance)
when(hazelcastInstance.getLifecycleService()).then(args -> lifecycleService)

HazelcastCacheManager manager = createMockBuilder(HazelcastCacheManager)
.addMockedMethod("createHazelcastInstance")
.niceMock();
expect(manager.createHazelcastInstance()).andReturn(hazelcastInstance)
HazelcastCacheManager manager = spy(HazelcastCacheManager);
when(manager.createHazelcastInstance()).then(args -> hazelcastInstance)

replay lifecycleService, hazelcastInstance, manager

// when
manager.init()
Expand All @@ -106,20 +98,18 @@ class HazelcastCacheManagerTest {
// then
assertFalse manager.implicitlyCreated
assertNull manager.hazelcastInstance
verify hazelcastInstance
verify manager
verify(hazelcastInstance).getLifecycleService()
verify(manager).createHazelcastInstance()
}

@Test
void testDestroyExplicit() {

// given
HazelcastInstance hazelcastInstance = niceMock(HazelcastInstance)
HazelcastInstance hazelcastInstance = mock(HazelcastInstance)
HazelcastCacheManager manager = new HazelcastCacheManager()
manager.hazelcastInstance = hazelcastInstance

replay hazelcastInstance

// when
manager.init()
manager.destroy()
Expand All @@ -134,27 +124,23 @@ class HazelcastCacheManagerTest {

// given
LifecycleService lifecycleService = mock(LifecycleService)
expect(lifecycleService.shutdown()).andThrow(new IllegalStateException())
when(lifecycleService.shutdown()).thenThrow(new IllegalStateException())

HazelcastInstance hazelcastInstance = mock(HazelcastInstance)
expect(hazelcastInstance.getLifecycleService()).andReturn(lifecycleService)

HazelcastCacheManager manager = createMockBuilder(HazelcastCacheManager)
.addMockedMethod("createHazelcastInstance")
.niceMock();
expect(manager.createHazelcastInstance()).andReturn(hazelcastInstance)
when(hazelcastInstance.getLifecycleService()).then(args -> lifecycleService)

replay lifecycleService, hazelcastInstance, manager
HazelcastCacheManager manager = spy(HazelcastCacheManager);
when(manager.createHazelcastInstance()).then(args -> hazelcastInstance)

// when
manager.init()
manager.destroy()

// then
assertFalse manager.implicitlyCreated
verify lifecycleService
verify hazelcastInstance
verify manager
verify(lifecycleService).shutdown()
verify(hazelcastInstance).getLifecycleService()
verify(manager).createHazelcastInstance()
}

}
6 changes: 6 additions & 0 deletions support/jaxrs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
<artifactId>jcl-over-slf4j</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Loading

0 comments on commit cf2d085

Please sign in to comment.