Skip to content

Commit 084f4f2

Browse files
Merge pull request #87 from hakusai22/feature_1.0
fix: code style
2 parents 79d1413 + 2dccd20 commit 084f4f2

11 files changed

+19
-28
lines changed

src/main/java/com/apple/itunes/storekit/client/AppStoreServerAPIClient.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.apple.itunes.storekit.model.TransactionHistoryRequest;
2323
import com.apple.itunes.storekit.model.TransactionInfoResponse;
2424
import com.fasterxml.jackson.annotation.JsonAutoDetect;
25-
import com.fasterxml.jackson.core.JsonParseException;
2625
import com.fasterxml.jackson.core.JsonProcessingException;
2726
import com.fasterxml.jackson.databind.ObjectMapper;
2827
import okhttp3.Call;
@@ -39,6 +38,7 @@
3938
import java.util.HashMap;
4039
import java.util.List;
4140
import java.util.Map;
41+
import java.util.Objects;
4242
import java.util.stream.Collectors;
4343

4444
public class AppStoreServerAPIClient {
@@ -95,7 +95,7 @@ private Response makeRequest(String path, String method, Map<String, List<String
9595
requestBuilder.addHeader("User-Agent", USER_AGENT);
9696
requestBuilder.addHeader("Authorization", "Bearer " + bearerTokenAuthenticator.generateToken());
9797
requestBuilder.addHeader("Accept", "application/json");
98-
HttpUrl.Builder urlBuilder = urlBase.resolve(path).newBuilder();
98+
HttpUrl.Builder urlBuilder = Objects.requireNonNull(urlBase.resolve(path)).newBuilder();
9999
for (Map.Entry<String, List<String>> entry : queryParameters.entrySet()) {
100100
for (String queryValue : entry.getValue()) {
101101
urlBuilder.addQueryParameter(entry.getKey(), queryValue);

src/main/java/com/apple/itunes/storekit/client/BearerTokenAuthenticator.java

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.time.temporal.ChronoUnit;
1515
import java.util.Base64;
1616
import java.util.Map;
17-
import java.util.stream.Collectors;
1817

1918
public class BearerTokenAuthenticator {
2019
private static final String APP_STORE_CONNECT_AUDIENCE = "appstoreconnect-v1";

src/main/java/com/apple/itunes/storekit/model/AppTransaction.java

-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
Information that represents the customer’s purchase of the app, cryptographically signed by the App Store.
1313
1414
@see <a href="https://developer.apple.com/documentation/storekit/apptransaction">AppTransaction</a>
15-
1615
*/
1716
public class AppTransaction implements DecodedSignedData {
1817

@@ -253,7 +252,6 @@ public AppTransaction deviceVerificationNonce(UUID deviceVerificationNonce) {
253252
254253
@see <a href="https://developer.apple.com/documentation/storekit/apptransaction/4013175-preorderdate">preorderDate</a>
255254
*/
256-
257255
public Long getPreorderDate() {
258256
return preorderDate;
259257
}

src/test/java/com/apple/itunes/storekit/client/AppStoreServerAPIClientTest.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void testExtendRenewalDateForAllActiveSubscribers() throws IOException, A
7878
} catch (IOException e) {
7979
throw new RuntimeException(e);
8080
}
81-
Map<String, Object> root = null;
81+
Map<String, Object> root;
8282
try {
8383
root = new ObjectMapper().readValue(buffer.readUtf8(), Map.class);
8484
} catch (JsonProcessingException e) {
@@ -118,7 +118,7 @@ public void testExtendSubscriptionRenewalDate() throws IOException, APIException
118118
} catch (IOException e) {
119119
throw new RuntimeException(e);
120120
}
121-
Map<String, Object> root = null;
121+
Map<String, Object> root;
122122
try {
123123
root = new ObjectMapper().readValue(buffer.readUtf8(), Map.class);
124124
} catch (JsonProcessingException e) {
@@ -259,7 +259,7 @@ public void testGetNotificationHistory() throws APIException, IOException {
259259
} catch (IOException e) {
260260
throw new RuntimeException(e);
261261
}
262-
Map<String, Object> root = null;
262+
Map<String, Object> root;
263263
try {
264264
root = new ObjectMapper().readValue(buffer.readUtf8(), Map.class);
265265
} catch (JsonProcessingException e) {
@@ -412,7 +412,7 @@ public void testSendConsumptionData() throws APIException, IOException {
412412
} catch (IOException e) {
413413
throw new RuntimeException(e);
414414
}
415-
Map<String, Object> root = null;
415+
Map<String, Object> root;
416416
try {
417417
root = new ObjectMapper().readValue(buffer.readUtf8(), Map.class);
418418
} catch (JsonProcessingException e) {
@@ -584,6 +584,7 @@ private AppStoreServerAPIClient getAppStoreServerAPIClient(String body, Consumer
584584

585585
private AppStoreServerAPIClient getAppStoreServerAPIClient(String body, Consumer<Request> requestVerifier, int statusCode) throws IOException {
586586
try (InputStream key = this.getClass().getClassLoader().getResourceAsStream("certs/testSigningKey.p8")) {
587+
Assertions.assertNotNull(key);
587588
return new AppStoreServerAPIClient(new String(key.readAllBytes()), "keyId", "issuerId", "com.example", Environment.LOCAL_TESTING) {
588589
@Override
589590
protected Response getResponse(Request request) {

src/test/java/com/apple/itunes/storekit/client/BearerTokenAuthenticatorTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class BearerTokenAuthenticatorTest {
1212
@Test
1313
void testCreatingToken() throws Exception {
1414
try (InputStream key = this.getClass().getClassLoader().getResourceAsStream("certs/testSigningKey.p8")) {
15+
Assertions.assertNotNull(key);
1516
var tokenGenerator = new BearerTokenAuthenticator(new String(key.readAllBytes()), "keyId", "issuerId", "bundleId");
1617
String token = tokenGenerator.generateToken();
1718
Assertions.assertNotNull(token);

src/test/java/com/apple/itunes/storekit/model/JWSRenewalInfoDecodedPayloadTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010

1111
import java.io.IOException;
1212
import java.security.NoSuchAlgorithmException;
13-
import java.security.spec.InvalidKeySpecException;
1413

1514
public class JWSRenewalInfoDecodedPayloadTest {
1615

1716
@Test
18-
public void testRenewalInfoDecoding() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, VerificationException {
17+
public void testRenewalInfoDecoding() throws IOException, NoSuchAlgorithmException, VerificationException {
1918
String signedRenewalInfo = SignedDataCreator.createSignedDataFromJson("models/signedRenewalInfo.json");
2019

2120
JWSRenewalInfoDecodedPayload renewalInfo = TestingUtility.getSignedPayloadVerifier().verifyAndDecodeRenewalInfo(signedRenewalInfo);

src/test/java/com/apple/itunes/storekit/model/JWSTransactionDecodedPayloadTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010

1111
import java.io.IOException;
1212
import java.security.NoSuchAlgorithmException;
13-
import java.security.spec.InvalidKeySpecException;
1413
import java.util.UUID;
1514

1615
public class JWSTransactionDecodedPayloadTest {
1716

1817
@Test
19-
public void testTransactionDecoding() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, VerificationException {
18+
public void testTransactionDecoding() throws IOException, NoSuchAlgorithmException, VerificationException {
2019
String signedTransaction = SignedDataCreator.createSignedDataFromJson("models/signedTransaction.json");
2120

2221
JWSTransactionDecodedPayload transaction = TestingUtility.getSignedPayloadVerifier().verifyAndDecodeTransaction(signedTransaction);

src/test/java/com/apple/itunes/storekit/model/ResponseBodyV2DecodedPayloadTest.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
import java.io.ByteArrayInputStream;
1313
import java.io.IOException;
1414
import java.security.NoSuchAlgorithmException;
15-
import java.security.spec.InvalidKeySpecException;
1615
import java.util.List;
1716
import java.util.Set;
1817

1918
public class ResponseBodyV2DecodedPayloadTest {
2019

2120
@Test
22-
public void testNotificationDecoding() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, VerificationException {
21+
public void testNotificationDecoding() throws IOException, NoSuchAlgorithmException, VerificationException {
2322
String signedNotification = SignedDataCreator.createSignedDataFromJson("models/signedNotification.json");
2423

2524
ResponseBodyV2DecodedPayload notification = TestingUtility.getSignedPayloadVerifier().verifyAndDecodeNotification(signedNotification);
@@ -46,7 +45,7 @@ public void testNotificationDecoding() throws IOException, NoSuchAlgorithmExcept
4645
}
4746

4847
@Test
49-
public void testSummaryNotificationDecoding() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, VerificationException {
48+
public void testSummaryNotificationDecoding() throws IOException, NoSuchAlgorithmException, VerificationException {
5049
String signedNotification = SignedDataCreator.createSignedDataFromJson("models/signedSummaryNotification.json");
5150

5251
ResponseBodyV2DecodedPayload notification = TestingUtility.getSignedPayloadVerifier().verifyAndDecodeNotification(signedNotification);
@@ -73,12 +72,12 @@ public void testSummaryNotificationDecoding() throws IOException, NoSuchAlgorith
7372
}
7473

7574
@Test
76-
public void testExternalPurchaseTokenNotificationDecoding() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, VerificationException {
75+
public void testExternalPurchaseTokenNotificationDecoding() throws IOException, NoSuchAlgorithmException, VerificationException {
7776
String signedNotification = SignedDataCreator.createSignedDataFromJson("models/signedExternalPurchaseTokenNotification.json");
7877

7978
SignedDataVerifier verifier = new SignedDataVerifier(Set.of(new ByteArrayInputStream(TestingUtility.readBytes("certs/testCA.der"))), "com.example", 1234L, Environment.LOCAL_TESTING, false) {
8079
@Override
81-
protected void verifyNotification(String bundleId, Long appAppleId, Environment notificationEnv) throws VerificationException {
80+
protected void verifyNotification(String bundleId, Long appAppleId, Environment notificationEnv) {
8281
Assertions.assertEquals("com.example", bundleId);
8382
Assertions.assertEquals(55555, appAppleId);
8483
Assertions.assertEquals(Environment.PRODUCTION, notificationEnv);
@@ -104,12 +103,12 @@ protected void verifyNotification(String bundleId, Long appAppleId, Environment
104103
}
105104

106105
@Test
107-
public void testExternalPurchaseTokenSandboxNotificationDecoding() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, VerificationException {
106+
public void testExternalPurchaseTokenSandboxNotificationDecoding() throws IOException, NoSuchAlgorithmException, VerificationException {
108107
String signedNotification = SignedDataCreator.createSignedDataFromJson("models/signedExternalPurchaseTokenSandboxNotification.json");
109108

110109
SignedDataVerifier verifier = new SignedDataVerifier(Set.of(new ByteArrayInputStream(TestingUtility.readBytes("certs/testCA.der"))), "com.example", 1234L, Environment.LOCAL_TESTING, false) {
111110
@Override
112-
protected void verifyNotification(String bundleId, Long appAppleId, Environment notificationEnv) throws VerificationException {
111+
protected void verifyNotification(String bundleId, Long appAppleId, Environment notificationEnv) {
113112
Assertions.assertEquals("com.example", bundleId);
114113
Assertions.assertEquals(55555, appAppleId);
115114
Assertions.assertEquals(Environment.SANDBOX, notificationEnv);

src/test/java/com/apple/itunes/storekit/offers/PromotionalOfferSignatureCreatorTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class PromotionalOfferSignatureCreatorTest {
1313
@Test
1414
void testSignatureCreator() throws Exception {
1515
try (InputStream key = this.getClass().getClassLoader().getResourceAsStream("certs/testSigningKey.p8")) {
16+
Assertions.assertNotNull(key);
1617
PromotionalOfferSignatureCreator signatureCreator = new PromotionalOfferSignatureCreator(new String(key.readAllBytes()), "keyId", "bundleId");
1718
String signature = signatureCreator.createSignature("productId", "offerId", "applicationUsername", UUID.fromString("20fba8a0-2b80-4a7d-a17f-85c1854727f8"), 1698148900000L);
1819
Assertions.assertNotNull(signature);

src/test/java/com/apple/itunes/storekit/util/SignedDataCreator.java

-8
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,11 @@
44

55
import com.auth0.jwt.JWT;
66
import com.auth0.jwt.algorithms.Algorithm;
7-
import com.auth0.jwt.interfaces.ECDSAKeyProvider;
87

98
import java.io.IOException;
10-
import java.nio.file.Files;
11-
import java.nio.file.Path;
12-
import java.security.KeyFactory;
139
import java.security.KeyPairGenerator;
1410
import java.security.NoSuchAlgorithmException;
1511
import java.security.interfaces.ECPrivateKey;
16-
import java.security.spec.InvalidKeySpecException;
17-
import java.security.spec.PKCS8EncodedKeySpec;
18-
import java.util.Base64;
19-
import java.util.Map;
2012

2113
public class SignedDataCreator {
2214

src/test/java/com/apple/itunes/storekit/util/TestingUtility.java

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.apple.itunes.storekit.model.Environment;
66
import com.apple.itunes.storekit.verification.SignedDataVerifier;
7+
import org.junit.jupiter.api.Assertions;
78

89
import java.io.ByteArrayInputStream;
910
import java.io.IOException;
@@ -19,6 +20,7 @@ public static String readFile(String file) throws IOException {
1920

2021
public static byte[] readBytes(String file) throws IOException {
2122
try (InputStream stream = TestingUtility.class.getClassLoader().getResourceAsStream(file)) {
23+
Assertions.assertNotNull(stream);
2224
return stream.readAllBytes();
2325
}
2426
}

0 commit comments

Comments
 (0)