PowerMock AmazonS3Client 配置问题

PowerMock AmazonS3Client Config Issue

我在尝试使用 PowerMock运行 进行模拟测试时得到了这个堆栈

 Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.amazonaws.services.s3.AmazonS3Client]: Factory method   'amazonS3Client' threw exception; nested exception is org.apache.http.conn.ssl.SSLInitializationException: class configured for SSLContext: sun.security.ssl.SSLContextImpl$TLSContext not a SSLContext
 Caused by: org.apache.http.conn.ssl.SSLInitializationException: class  configured for SSLContext: sun.security.ssl.SSLContextImpl$TLSContext not a SSLContext
 Caused by: java.security.NoSuchAlgorithmException: class configured for SSLContext: sun.security.ssl.SSLContextImpl$TLSContext not a SSLContext

我尝试过使用 org.apache.http.con.ssl.* 添加 @PowerMockIgnore 的建议,但这样做会导致我的 Rabbit 连接器失败。我不确定是否有任何建议对我的测试都有负载。或者如果测试不需要就不要初始化?

我能提供的东西有限,因为这是我公司的事情。

使用亚马逊 SDK:1.11.69

这是我配置测试的方式

@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations={"classpath:applicationContext-test.xml"})
@TestExecutionListeners(listeners={ServletTestExecutionListener.class,
        DependencyInjectionTestExecutionListener.class,
        DirtiesContextTestExecutionListener.class,
        TransactionalTestExecutionListener.class,
        WithSecurityContextTestExecutionListener.class})
@PrepareForTest({Observable.class,HardDeleteUserCommand.class,SoftDeleteUserCommand.class})
@PowerMockIgnore({ "javax.management.*", "ch.qos.logback.*",
    "org.slf4j.*" })

示例 Bean:

@Configuration
@Profile("Test")
public class S3Configuration {
    @Bean
    public AmazonS3Client amazonS3Client() throws IOException {
          return new AmazonS3Client(new EnvironmentVariableCredentialsProvider());
    }
}

我能够通过添加模拟 bean 的自定义配置文件和 returns 它来解决这个问题。

@Configuration
@Profile("Test")
public class TestConfig {

    @Mock
    AmazonS3Client client;

    public TestConfig(){
        MockitoAnnotations.initMocks(this);
    }

    @Bean
    public AmazonS3Client amazonS3Client(){
        return client;
    }
}

正如@srkavin 在评论中所说,当我添加 @PowerMockIgnore({ "javax.net.ssl.*" })

时,此错误消失了