4141import org .junit .Before ;
4242import org .junit .Test ;
4343import org .junit .runner .RunWith ;
44+
4445import org .mockito .junit .MockitoJUnitRunner ;
46+ import org .mockito .Mockito ;
47+
4548
4649@ RunWith (MockitoJUnitRunner .class )
4750public class RootCAProviderTest {
@@ -57,12 +60,6 @@ private void addField(final RootCAProvider provider, final String name, final Ob
5760 f .set (provider , o );
5861 }
5962
60- private void overrideDefaultConfigValue (final ConfigKey configKey , final String name , final Object o ) throws IllegalAccessException , NoSuchFieldException {
61- Field f = ConfigKey .class .getDeclaredField (name );
62- f .setAccessible (true );
63- f .set (configKey , o );
64- }
65-
6663 @ Before
6764 public void setUp () throws Exception {
6865 caKeyPair = CertUtils .generateRandomKeyPair (1024 );
@@ -133,14 +130,16 @@ public void testRevokeCertificate() throws Exception {
133130
134131 @ Test
135132 public void testCreateSSLEngineWithoutAuthStrictness () throws Exception {
136- overrideDefaultConfigValue (RootCAProvider .rootCAAuthStrictness , "_defaultValue" , "false" );
133+ provider .rootCAAuthStrictness = Mockito .mock (ConfigKey .class );
134+ Mockito .when (provider .rootCAAuthStrictness .value ()).thenReturn (Boolean .FALSE );
137135 final SSLEngine e = provider .createSSLEngine (SSLUtils .getSSLContext (), "/1.2.3.4:5678" , null );
138136 Assert .assertFalse (e .getNeedClientAuth ());
139137 }
140138
141139 @ Test
142140 public void testCreateSSLEngineWithAuthStrictness () throws Exception {
143- overrideDefaultConfigValue (RootCAProvider .rootCAAuthStrictness , "_defaultValue" , "true" );
141+ provider .rootCAAuthStrictness = Mockito .mock (ConfigKey .class );
142+ Mockito .when (provider .rootCAAuthStrictness .value ()).thenReturn (Boolean .TRUE );
144143 final SSLEngine e = provider .createSSLEngine (SSLUtils .getSSLContext (), "/1.2.3.4:5678" , null );
145144 Assert .assertTrue (e .getNeedClientAuth ());
146145 }
0 commit comments