2626
2727import org .assertj .core .api .Assertions ;
2828import org .junit .jupiter .api .Test ;
29+
2930import software .amazon .awssdk .auth .credentials .AwsCredentials ;
3031import software .amazon .awssdk .auth .credentials .AwsCredentialsProvider ;
3132
3435import org .apache .hadoop .fs .s3a .impl .InstantiationIOException ;
3536
3637import static org .apache .hadoop .test .LambdaTestUtils .intercept ;
37- import static org .mockito .Mockito .doReturn ;
38- import static org .mockito .Mockito .spy ;
3938
4039/**
4140 * Checks that classloader isolation for loading extension classes is applied
@@ -47,9 +46,9 @@ public class ITestS3AFileSystemIsolatedClassloader extends AbstractS3ATestBase {
4746
4847 private static String customClassName = "custom.class.name" ;
4948
50- private static class CustomCredentialsProvider implements AwsCredentialsProvider {
49+ public static class CustomCredentialsProvider implements AwsCredentialsProvider {
5150
52- CustomCredentialsProvider () {
51+ public CustomCredentialsProvider () {
5352 }
5453
5554 @ Override
@@ -60,19 +59,23 @@ public AwsCredentials resolveCredentials() {
6059 }
6160
6261 private static class CustomClassLoader extends ClassLoader {
63- }
6462
65- private final ClassLoader customClassLoader = spy (new CustomClassLoader ());
66- {
67- try {
68- doReturn (CustomCredentialsProvider .class )
69- .when (customClassLoader )
70- .loadClass (customClassName );
71- } catch (ClassNotFoundException ex ) {
72- throw new RuntimeException (ex );
63+ CustomClassLoader (ClassLoader parent ) {
64+ super (parent );
65+ }
66+
67+ @ Override
68+ public Class <?> loadClass (String name ) throws ClassNotFoundException {
69+ if (customClassName .equals (name )) {
70+ return CustomCredentialsProvider .class ;
71+ }
72+ return super .loadClass (name );
7373 }
7474 }
7575
76+ private final ClassLoader customClassLoader =
77+ new CustomClassLoader (ITestS3AFileSystemIsolatedClassloader .class .getClassLoader ());
78+
7679 private S3AFileSystem createNewTestFs (Configuration conf ) throws IOException {
7780 S3AFileSystem fs = new S3AFileSystem ();
7881 fs .initialize (getFileSystem ().getUri (), conf );
0 commit comments