Skip to content

Commit cd0111b

Browse files
committed
添加单测用例
1 parent 00ab107 commit cd0111b

File tree

4 files changed

+143
-2
lines changed

4 files changed

+143
-2
lines changed

core/src/main/java/com/wechat/pay/java/core/notification/RSACombinedNotificationConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public Builder publicKey(PublicKey publicKey) {
5858
return this;
5959
}
6060

61-
public Builder publicFromPath(String publicKeyPath) {
61+
public Builder publicKeyFromPath(String publicKeyPath) {
6262
this.publicKey = PemUtil.loadPublicKeyFromPath(publicKeyPath);
6363
return this;
6464
}

core/src/main/java/com/wechat/pay/java/core/notification/RSAPublicKeyNotificationConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public Builder publicKey(PublicKey publicKey) {
3434
return this;
3535
}
3636

37-
public Builder publicFromPath(String publicKeyPath) {
37+
public Builder publicKeyFromPath(String publicKeyPath) {
3838
this.publicKey = PemUtil.loadPublicKeyFromPath(publicKeyPath);
3939
return this;
4040
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.wechat.pay.java.core.notification;
2+
3+
import static com.wechat.pay.java.core.model.TestConfig.API_V3_KEY;
4+
import static com.wechat.pay.java.core.model.TestConfig.MERCHANT_CERTIFICATE_SERIAL_NUMBER;
5+
import static com.wechat.pay.java.core.model.TestConfig.MERCHANT_PRIVATE_KEY_STRING;
6+
import static com.wechat.pay.java.core.model.TestConfig.WECHAT_PAY_CERTIFICATE_SERIAL_NUMBER;
7+
import static com.wechat.pay.java.core.model.TestConfig.WECHAT_PAY_PUBLIC_KEY;
8+
import static com.wechat.pay.java.core.model.TestConfig.WECHAT_PAY_PUBLIC_KEY_PATH;
9+
import static com.wechat.pay.java.core.model.TestConfig.WECHAT_PAY_PUBLIC_KEY_STRING;
10+
import static org.junit.jupiter.api.Assertions.assertNotNull;
11+
import static org.junit.jupiter.api.Assertions.assertThrows;
12+
13+
import com.wechat.pay.java.core.notification.RSACombinedNotificationConfig.Builder;
14+
import java.util.stream.Stream;
15+
import org.junit.jupiter.api.Test;
16+
import org.junit.jupiter.params.ParameterizedTest;
17+
import org.junit.jupiter.params.provider.MethodSource;
18+
19+
class RSACombinedNotificationConfigTest implements NotificationConfigTest {
20+
21+
@ParameterizedTest
22+
@MethodSource("BuilderProvider")
23+
void testConfigWithBuilderProvider(Builder builder) {
24+
RSACombinedNotificationConfig c = builder.build();
25+
26+
assertNotNull(c);
27+
assertNotNull(c.createAeadCipher());
28+
assertNotNull(c.createVerifier());
29+
assertNotNull(c.getCipherType());
30+
assertNotNull(c.getSignType());
31+
}
32+
33+
static Stream<Builder> BuilderProvider() {
34+
return Stream.of(
35+
// from string
36+
new Builder()
37+
.merchantId("123456")
38+
.privateKey(MERCHANT_PRIVATE_KEY_STRING)
39+
.merchantSerialNumber(MERCHANT_CERTIFICATE_SERIAL_NUMBER)
40+
.publicKey(WECHAT_PAY_PUBLIC_KEY_STRING)
41+
.publicKeyId(WECHAT_PAY_CERTIFICATE_SERIAL_NUMBER)
42+
.apiV3Key(API_V3_KEY),
43+
44+
// from path
45+
new Builder()
46+
.merchantId("123456")
47+
.privateKey(MERCHANT_PRIVATE_KEY_STRING)
48+
.merchantSerialNumber(MERCHANT_CERTIFICATE_SERIAL_NUMBER)
49+
.publicKeyFromPath(WECHAT_PAY_PUBLIC_KEY_PATH)
50+
.publicKeyId(WECHAT_PAY_CERTIFICATE_SERIAL_NUMBER)
51+
.apiV3Key(API_V3_KEY),
52+
53+
// with publickey
54+
new Builder()
55+
.merchantId("123456")
56+
.privateKey(MERCHANT_PRIVATE_KEY_STRING)
57+
.merchantSerialNumber(MERCHANT_CERTIFICATE_SERIAL_NUMBER)
58+
.publicKey(WECHAT_PAY_PUBLIC_KEY)
59+
.publicKeyId(WECHAT_PAY_CERTIFICATE_SERIAL_NUMBER)
60+
.apiV3Key(API_V3_KEY));
61+
}
62+
63+
@Test
64+
void testBuildConfigWithoutEnoughParam() {
65+
Builder builder = new Builder().apiV3Key(API_V3_KEY);
66+
assertThrows(NullPointerException.class, builder::build);
67+
}
68+
69+
@Override
70+
public NotificationConfig buildNotificationConfig() {
71+
return new Builder()
72+
.publicKey(WECHAT_PAY_PUBLIC_KEY)
73+
.publicKeyId(WECHAT_PAY_CERTIFICATE_SERIAL_NUMBER)
74+
.build();
75+
}
76+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.wechat.pay.java.core.notification;
2+
3+
import static com.wechat.pay.java.core.model.TestConfig.API_V3_KEY;
4+
import static com.wechat.pay.java.core.model.TestConfig.WECHAT_PAY_CERTIFICATE_SERIAL_NUMBER;
5+
import static com.wechat.pay.java.core.model.TestConfig.WECHAT_PAY_PUBLIC_KEY;
6+
import static com.wechat.pay.java.core.model.TestConfig.WECHAT_PAY_PUBLIC_KEY_PATH;
7+
import static com.wechat.pay.java.core.model.TestConfig.WECHAT_PAY_PUBLIC_KEY_STRING;
8+
import static org.junit.jupiter.api.Assertions.assertNotNull;
9+
import static org.junit.jupiter.api.Assertions.assertThrows;
10+
11+
import com.wechat.pay.java.core.notification.RSAPublicKeyNotificationConfig.Builder;
12+
import java.util.stream.Stream;
13+
import org.junit.jupiter.api.Test;
14+
import org.junit.jupiter.params.ParameterizedTest;
15+
import org.junit.jupiter.params.provider.MethodSource;
16+
17+
class RSAPublicKeyNotificationConfigTest implements NotificationConfigTest {
18+
19+
@ParameterizedTest
20+
@MethodSource("BuilderProvider")
21+
void testConfigWithBuilderProvider(Builder builder) {
22+
RSAPublicKeyNotificationConfig c = builder.build();
23+
24+
assertNotNull(c);
25+
assertNotNull(c.createAeadCipher());
26+
assertNotNull(c.createVerifier());
27+
assertNotNull(c.getCipherType());
28+
assertNotNull(c.getSignType());
29+
}
30+
31+
static Stream<Builder> BuilderProvider() {
32+
return Stream.of(
33+
// from string
34+
new Builder()
35+
.publicKey(WECHAT_PAY_PUBLIC_KEY_STRING)
36+
.publicKeyId(WECHAT_PAY_CERTIFICATE_SERIAL_NUMBER)
37+
.apiV3Key(API_V3_KEY),
38+
39+
// from path
40+
new Builder()
41+
.publicKeyFromPath(WECHAT_PAY_PUBLIC_KEY_PATH)
42+
.publicKeyId(WECHAT_PAY_CERTIFICATE_SERIAL_NUMBER)
43+
.apiV3Key(API_V3_KEY),
44+
45+
// with publickey
46+
new Builder()
47+
.publicKey(WECHAT_PAY_PUBLIC_KEY)
48+
.publicKeyId(WECHAT_PAY_CERTIFICATE_SERIAL_NUMBER)
49+
.apiV3Key(API_V3_KEY));
50+
}
51+
52+
@Test
53+
void testBuildConfigWithoutEnoughParam() {
54+
Builder builder = new Builder().apiV3Key(API_V3_KEY);
55+
assertThrows(NullPointerException.class, builder::build);
56+
}
57+
58+
@Override
59+
public NotificationConfig buildNotificationConfig() {
60+
return new Builder()
61+
.publicKey(WECHAT_PAY_PUBLIC_KEY)
62+
.publicKeyId(WECHAT_PAY_CERTIFICATE_SERIAL_NUMBER)
63+
.build();
64+
}
65+
}

0 commit comments

Comments
 (0)