我有一个带有 bean 的配置类
@Bean
public static IAuthenticationResult getAccessTokenByClientCredentialGrant() throws Exception {
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(Files.readAllBytes(Paths.get(KeyPath)));
PrivateKey key = KeyFactory.getInstance("RSA").generatePrivate(spec);
InputStream certStream = new ByteArrayInputStream(Files.readAllBytes(Paths.get(CertPath)));
X509Certificate cert = (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(certStream);
....
ClientCredentialParameters clientCredentialParam = ClientCredentialParameters.builder(
Collections.singleton(scope))
.build();
//Need to mock this in Test
CompletableFuture<IAuthenticationResult> future = app.acquireToken(clientCredentialParam);
return future.get();
}
我想编写一个单元测试来增加我的代码覆盖率。
但我没有使用所有这些最新的库。
我想要带有模拟或 powermock 的简单模型作为获取令牌并且能够创建 bean。请指教