4141import org .junit .Before ;
4242import org .junit .Test ;
4343import org .junit .runner .RunWith ;
44+ import org .mockito .Mockito ;
4445import org .mockito .runners .MockitoJUnitRunner ;
4546
4647@ RunWith (MockitoJUnitRunner .class )
@@ -57,12 +58,6 @@ private void addField(final RootCAProvider provider, final String name, final Ob
5758 f .set (provider , o );
5859 }
5960
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-
6661 @ Before
6762 public void setUp () throws Exception {
6863 caKeyPair = CertUtils .generateRandomKeyPair (1024 );
@@ -133,17 +128,17 @@ public void testRevokeCertificate() throws Exception {
133128
134129 @ Test
135130 public void testCreateSSLEngineWithoutAuthStrictness () throws Exception {
136- overrideDefaultConfigValue (RootCAProvider .rootCAAuthStrictness , "_defaultValue" , "false" );
131+ provider .rootCAAuthStrictness = Mockito .mock (ConfigKey .class );
132+ Mockito .when (provider .rootCAAuthStrictness .value ()).thenReturn (Boolean .FALSE );
137133 final SSLEngine e = provider .createSSLEngine (SSLUtils .getSSLContext (), "/1.2.3.4:5678" , null );
138- Assert .assertFalse (e .getUseClientMode ());
139134 Assert .assertFalse (e .getNeedClientAuth ());
140135 }
141136
142137 @ Test
143138 public void testCreateSSLEngineWithAuthStrictness () throws Exception {
144- overrideDefaultConfigValue (RootCAProvider .rootCAAuthStrictness , "_defaultValue" , "true" );
139+ provider .rootCAAuthStrictness = Mockito .mock (ConfigKey .class );
140+ Mockito .when (provider .rootCAAuthStrictness .value ()).thenReturn (Boolean .TRUE );
145141 final SSLEngine e = provider .createSSLEngine (SSLUtils .getSSLContext (), "/1.2.3.4:5678" , null );
146- Assert .assertFalse (e .getUseClientMode ());
147142 Assert .assertTrue (e .getNeedClientAuth ());
148143 }
149144
0 commit comments