diff --git a/digitalassetlinks/build.gradle b/digitalassetlinks/build.gradle index ed3ed56..9cad924 100644 --- a/digitalassetlinks/build.gradle +++ b/digitalassetlinks/build.gradle @@ -87,8 +87,8 @@ tasks.whenTaskAdded { task -> } dependencies { - compileOnly 'org.jetbrains:annotations:23.0.0' - testCompileOnly 'org.jetbrains:annotations:23.0.0' + implementation 'androidx.annotation:annotation:1.4.0' + implementation 'androidx.collection:collection:1.2.0' testImplementation 'com.google.protobuf:protobuf-java:3.21.2' testImplementation 'junit:junit:4.13.2' testImplementation 'org.mockito:mockito-inline:4.6.1' diff --git a/digitalassetlinks/src/main/java/com/solana/digitalassetlinks/AndroidAppPackageVerifier.java b/digitalassetlinks/src/main/java/com/solana/digitalassetlinks/AndroidAppPackageVerifier.java index b4becc0..268ff74 100644 --- a/digitalassetlinks/src/main/java/com/solana/digitalassetlinks/AndroidAppPackageVerifier.java +++ b/digitalassetlinks/src/main/java/com/solana/digitalassetlinks/AndroidAppPackageVerifier.java @@ -9,7 +9,8 @@ import android.content.pm.Signature; import android.os.Build; -import org.jetbrains.annotations.NotNull; +import androidx.annotation.NonNull; + import org.json.JSONArray; import org.json.JSONObject; @@ -29,7 +30,7 @@ public class AndroidAppPackageVerifier extends URISourceVerifier { * Construct a new {@link AndroidAppPackageVerifier} * @param pm the {@link PackageManager} from which to look up app package details */ - public AndroidAppPackageVerifier(@NotNull PackageManager pm) { + public AndroidAppPackageVerifier(@NonNull PackageManager pm) { mPackageManager = pm; } @@ -50,7 +51,7 @@ public AndroidAppPackageVerifier(@NotNull PackageManager pm) { * successful. Note that this doesn't necessarily imply that the package was not verified, * but rather that a relationship could not be established. */ - public boolean verify(@NotNull String packageName, @NotNull URI uri) + public boolean verify(@NonNull String packageName, @NonNull URI uri) throws CouldNotVerifyPackageException { if (!"https".equalsIgnoreCase(uri.getScheme())) { throw new CouldNotVerifyPackageException( @@ -144,9 +145,9 @@ public boolean verify(@NotNull String packageName, @NotNull URI uri) return result; } - @NotNull + @NonNull private static byte[][] convertDEREncodedCertificatesToSHA256Fingerprints( - @NotNull Signature[] derEncodedCerts) { + @NonNull Signature[] derEncodedCerts) { final MessageDigest digest; try { digest = MessageDigest.getInstance("SHA-256"); @@ -160,9 +161,9 @@ private static byte[][] convertDEREncodedCertificatesToSHA256Fingerprints( return sha256CertFingerprints; } - @NotNull + @NonNull private static byte[] convertSHA256CertFingerprintStringToByteArray( - @NotNull String sha256CertFingerprint) { + @NonNull String sha256CertFingerprint) { // NOTE: the format of the certificate fingerprint string is already checked against // AssetLinksGrammer.SHA256_CERT_FINGERPRINT_PATTERN by AssetLinksJSONParser final byte[] fp = new byte[32]; diff --git a/digitalassetlinks/src/main/java/com/solana/digitalassetlinks/AssetLinksGrammar.java b/digitalassetlinks/src/main/java/com/solana/digitalassetlinks/AssetLinksGrammar.java index f951b37..2c12b3a 100644 --- a/digitalassetlinks/src/main/java/com/solana/digitalassetlinks/AssetLinksGrammar.java +++ b/digitalassetlinks/src/main/java/com/solana/digitalassetlinks/AssetLinksGrammar.java @@ -4,7 +4,7 @@ package com.solana.digitalassetlinks; -import org.jetbrains.annotations.NotNull; +import androidx.annotation.NonNull; import java.net.URI; @@ -36,7 +36,7 @@ public final class AssetLinksGrammar { public static final String SHA256_CERT_FINGERPRINT_PATTERN = "^(?:[0-9A-F]{2}:){31}[0-9A-F]{2}$"; /** Tests if the specified URI is valid for {@link #GRAMMAR_WEB_SITE} */ - public static boolean isValidSiteURI(@NotNull URI uri) { + public static boolean isValidSiteURI(@NonNull URI uri) { return (uri.isAbsolute() && ("http".equalsIgnoreCase(uri.getScheme()) || "https".equalsIgnoreCase(uri.getScheme())) && diff --git a/digitalassetlinks/src/main/java/com/solana/digitalassetlinks/AssetLinksJSONParser.java b/digitalassetlinks/src/main/java/com/solana/digitalassetlinks/AssetLinksJSONParser.java index c9a9d25..04ec91b 100644 --- a/digitalassetlinks/src/main/java/com/solana/digitalassetlinks/AssetLinksJSONParser.java +++ b/digitalassetlinks/src/main/java/com/solana/digitalassetlinks/AssetLinksJSONParser.java @@ -7,8 +7,9 @@ import android.util.Log; import android.util.Pair; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -45,7 +46,7 @@ public AssetLinksJSONParser() {} * @return a {@link List} of {@link URI}s in the order discovered. The first entry is the source * {@link URI} for this Asset Links tree. */ - @NotNull + @NonNull public List getURIs() { return Collections.unmodifiableList(mURIs); } @@ -84,8 +85,8 @@ public boolean isError() { * @param statementMatcher the {@link StatementMatcher} to add * @param callback the {@link StatementMatcherCallback} to invoke when a match occurs */ - public void addStatementMatcher(@NotNull StatementMatcher statementMatcher, - @NotNull StatementMatcherCallback callback) { + public void addStatementMatcher(@NonNull StatementMatcher statementMatcher, + @NonNull StatementMatcherCallback callback) { mStatementMatchers.add(Pair.create(statementMatcher, callback)); } @@ -94,8 +95,8 @@ public void addStatementMatcher(@NotNull StatementMatcher statementMatcher, * @param sourceURI the initial Asset Links {@link URI}. It must be an absolute {@link URI}. * @return the first {@link URI} to fetch for {@link #onDocumentLoaded(URI, String)} */ - @NotNull - public URI start(@NotNull URI sourceURI) { + @NonNull + public URI start(@NonNull URI sourceURI) { if (!sourceURI.isAbsolute()) { throw new IllegalArgumentException("Source URI must be absolute"); } @@ -126,7 +127,7 @@ public URI start(@NotNull URI sourceURI) { * @throws MatcherException if any registered {@link StatementMatcher} throws an exception */ @Nullable - public URI onDocumentLoaded(@NotNull URI documentURI, @NotNull String document) + public URI onDocumentLoaded(@NonNull URI documentURI, @NonNull String document) throws IllFormattedStatementException, TooManyIncludesException, MatcherException { if (mIsError) { throw new IllegalStateException("AssetLinksJSONParser already in the error state"); @@ -186,10 +187,10 @@ public URI onDocumentLoaded(@NotNull URI documentURI, @NotNull String document) } } - private void parseAssetLinksDocument(@NotNull URI documentURI, - @NotNull String document, - @NotNull ArrayList statementList, - @NotNull ArrayList includeList) + private void parseAssetLinksDocument(@NonNull URI documentURI, + @NonNull String document, + @NonNull ArrayList statementList, + @NonNull ArrayList includeList) throws IllFormattedStatementException { try { final JSONArray statements = new JSONArray(document); // mandatory top-level array @@ -215,9 +216,9 @@ private void parseAssetLinksDocument(@NotNull URI documentURI, } } - private void parseIncludeStatement(@NotNull URI documentURI, - @NotNull JSONObject statement, - @NotNull ArrayList includeList) + private void parseIncludeStatement(@NonNull URI documentURI, + @NonNull JSONObject statement, + @NonNull ArrayList includeList) throws JSONException, IllFormattedStatementException { if (statement.has(AssetLinksGrammar.GRAMMAR_RELATION) || statement.has(AssetLinksGrammar.GRAMMAR_TARGET)) { @@ -239,8 +240,8 @@ private void parseIncludeStatement(@NotNull URI documentURI, includeList.add(resolvedURI); } - private void parseAssetLinkStatement(@NotNull JSONObject statement, - @NotNull ArrayList statementList) + private void parseAssetLinkStatement(@NonNull JSONObject statement, + @NonNull ArrayList statementList) throws JSONException, IllFormattedStatementException { final JSONArray relations = statement.getJSONArray(AssetLinksGrammar.GRAMMAR_RELATION); if (relations.length() == 0) { @@ -263,7 +264,7 @@ private void parseAssetLinkStatement(@NotNull JSONObject statement, statementList.add(statement); } - private void validateWebTarget(@NotNull JSONObject webTarget) + private void validateWebTarget(@NonNull JSONObject webTarget) throws JSONException, IllFormattedStatementException { final String site = webTarget.getString(AssetLinksGrammar.GRAMMAR_WEB_SITE); final URI uri; @@ -278,7 +279,7 @@ private void validateWebTarget(@NotNull JSONObject webTarget) } } - private void validateAndroidAppTarget(@NotNull JSONObject androidAppTarget) + private void validateAndroidAppTarget(@NonNull JSONObject androidAppTarget) throws JSONException, IllFormattedStatementException { final String packageName = androidAppTarget.getString("package_name"); if (!packageName.matches(AssetLinksGrammar.PACKAGE_NAME_PATTERN)) { @@ -300,7 +301,7 @@ private void validateAndroidAppTarget(@NotNull JSONObject androidAppTarget) /** A callback to be invoked when a {@link StatementMatcher} match occurs */ public interface StatementMatcherCallback { - void onMatch(@NotNull StatementMatcher matcher, @NotNull JSONObject o) throws JSONException; + void onMatch(@NonNull StatementMatcher matcher, @NonNull JSONObject o) throws JSONException; } /** The base type for all {@link AssetLinksJSONParser} exceptions */ diff --git a/digitalassetlinks/src/main/java/com/solana/digitalassetlinks/StatementMatcher.java b/digitalassetlinks/src/main/java/com/solana/digitalassetlinks/StatementMatcher.java index 3c95cac..d55a0fc 100644 --- a/digitalassetlinks/src/main/java/com/solana/digitalassetlinks/StatementMatcher.java +++ b/digitalassetlinks/src/main/java/com/solana/digitalassetlinks/StatementMatcher.java @@ -4,10 +4,10 @@ package com.solana.digitalassetlinks; -import android.util.ArrayMap; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.collection.ArrayMap; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -24,7 +24,7 @@ public class StatementMatcher { @Nullable private final String mRelation; @Nullable private final String mTargetNamespace; - @NotNull private final ArrayMap mTargetKeyValues; + @NonNull private final ArrayMap mTargetKeyValues; /** * Construct a new {@link StatementMatcher} @@ -35,7 +35,7 @@ public class StatementMatcher { */ protected StatementMatcher(@Nullable String relation, @Nullable String targetNamespace, - @NotNull ArrayMap targetKeyValues) { + @NonNull ArrayMap targetKeyValues) { if (relation != null && !relation.matches(AssetLinksGrammar.RELATION_PATTERN)) { throw new IllegalArgumentException("relation does not match the expected format"); } @@ -51,7 +51,7 @@ protected StatementMatcher(@Nullable String relation, * @return true if all conditions of this {@link StatementMatcher} are satisfied, else false * @throws IllegalArgumentException if o is not a well-formed Asset Links statement object */ - public boolean compare(@NotNull JSONObject o) { + public boolean compare(@NonNull JSONObject o) { try { if (mRelation != null) { final JSONArray relations = o.getJSONArray(AssetLinksGrammar.GRAMMAR_RELATION); // mandatory field @@ -138,8 +138,8 @@ public boolean compare(@NotNull JSONObject o) { } // Removes default port numbers and the trailing FQDN '.' for comparison purposes - @NotNull - private URI canonicalizeURI(@NotNull URI uri) { + @NonNull + private URI canonicalizeURI(@NonNull URI uri) { final boolean hasExplicitDefaultPort; final String scheme = uri.getScheme(); final int port = uri.getPort(); @@ -181,7 +181,7 @@ private URI canonicalizeURI(@NotNull URI uri) { * @return a {@link StatementMatcher} * @throws IllegalArgumentException if site is non-null and fails validation */ - public static StatementMatcher createWebStatementMatcher(@NotNull String relation, + public static StatementMatcher createWebStatementMatcher(@NonNull String relation, @Nullable URI site) { final Builder builder = StatementMatcher.newBuilder() .setRelation(relation) @@ -209,7 +209,7 @@ public static StatementMatcher createWebStatementMatcher(@NotNull String relatio * @throws IllegalArgumentException if packageName is non-null and fails validation, or if * sha256CertFingerprint is non-null and fails validation. */ - public static StatementMatcher createAndroidAppStatementMatcher(@NotNull String relation, + public static StatementMatcher createAndroidAppStatementMatcher(@NonNull String relation, @Nullable String packageName, @Nullable String sha256CertFingerprint) { final Builder builder = StatementMatcher.newBuilder() @@ -237,7 +237,7 @@ public static StatementMatcher createAndroidAppStatementMatcher(@NotNull String * Create a new {@link Builder} * @return a new {@link Builder} */ - @NotNull + @NonNull public static Builder newBuilder() { return new Builder(); } @@ -257,7 +257,7 @@ public int hashCode() { return Objects.hash(mRelation, mTargetNamespace, mTargetKeyValues); } - @NotNull + @NonNull @Override public String toString() { return "StatementMatcher{" + @@ -285,7 +285,7 @@ public Builder() {} * @param relation the relation condition for the {@link StatementMatcher} * @return this {@link Builder} */ - @NotNull + @NonNull public Builder setRelation(@Nullable String relation) { mRelation = relation; return this; @@ -296,7 +296,7 @@ public Builder setRelation(@Nullable String relation) { * @param targetNamespace the target namespace condition for the {@link StatementMatcher} * @return this {@link Builder} */ - @NotNull + @NonNull public Builder setTargetNamespace(@Nullable String targetNamespace) { mTargetNamespace = targetNamespace; return this; @@ -308,8 +308,8 @@ public Builder setTargetNamespace(@Nullable String targetNamespace) { * @param value the target String value of this condition * @return this {@link Builder} */ - @NotNull - public Builder setTargetKeyValue(@NotNull String key, @Nullable String value) { + @NonNull + public Builder setTargetKeyValue(@NonNull String key, @Nullable String value) { return setTargetKeyValue(key, value, false); } @@ -321,8 +321,8 @@ public Builder setTargetKeyValue(@NotNull String key, @Nullable String value) { * for key * @return this {@link Builder} */ - @NotNull - public Builder setTargetKeyValue(@NotNull String key, + @NonNull + public Builder setTargetKeyValue(@NonNull String key, @Nullable String value, boolean allowMatchInArray) { if (value != null) { @@ -343,8 +343,8 @@ public Builder setTargetKeyValue(@NotNull String key, * @param value the target {@link URI} value of this condition * @return this {@link Builder} */ - @NotNull - public Builder setTargetKeyValue(@NotNull String key, @Nullable URI value) { + @NonNull + public Builder setTargetKeyValue(@NonNull String key, @Nullable URI value) { if (value != null) { mKeyValues.put(key, value); } else { @@ -357,17 +357,17 @@ public Builder setTargetKeyValue(@NotNull String key, @Nullable URI value) { * Construct a new {@link StatementMatcher} from the current state of this {@link Builder} * @return a new {@link StatementMatcher} */ - @NotNull + @NonNull public StatementMatcher build() { return new StatementMatcher(mRelation, mTargetNamespace, mKeyValues); } } private static final class AllowMatchInArray { - @NotNull + @NonNull public final String value; - public AllowMatchInArray(@NotNull String value) { + public AllowMatchInArray(@NonNull String value) { this.value = value; } } diff --git a/digitalassetlinks/src/main/java/com/solana/digitalassetlinks/URISourceVerifier.java b/digitalassetlinks/src/main/java/com/solana/digitalassetlinks/URISourceVerifier.java index 04e7949..38a4a3d 100644 --- a/digitalassetlinks/src/main/java/com/solana/digitalassetlinks/URISourceVerifier.java +++ b/digitalassetlinks/src/main/java/com/solana/digitalassetlinks/URISourceVerifier.java @@ -4,7 +4,7 @@ package com.solana.digitalassetlinks; -import org.jetbrains.annotations.NotNull; +import androidx.annotation.NonNull; import java.io.IOException; import java.io.InputStream; @@ -32,8 +32,8 @@ public abstract class URISourceVerifier { * @return the corresponding well-known Asset Links {@link URI} * @throws IllegalArgumentException if baseURI is not an hierarchical HTTP or HTTPS URI */ - @NotNull - public static URI getWellKnownAssetLinksURI(@NotNull URI baseURI) { + @NonNull + public static URI getWellKnownAssetLinksURI(@NonNull URI baseURI) { if (!baseURI.isAbsolute() || baseURI.isOpaque()) { throw new IllegalArgumentException("Source URI must be absolute and hierarchical"); } @@ -67,7 +67,7 @@ public static URI getWellKnownAssetLinksURI(@NotNull URI baseURI) { * @throws CouldNotVerifyException if verification could not be performed for any reason (such * as malformed Asset Links files, network unavailability, too many includes, etc). */ - protected boolean verify(@NotNull URI sourceURI, StatementMatcherWithCallback... matchers) + protected boolean verify(@NonNull URI sourceURI, StatementMatcherWithCallback... matchers) throws CouldNotVerifyException { if (!mVerificationInProgress.compareAndSet(false, true)) { throw new IllegalStateException("verification already in progress"); @@ -130,8 +130,8 @@ private void throwIfCancelled() throws CouldNotVerifyException { // N.B. protected only so compatibility test suite harnesses can override this to provide mock // URL objects - @NotNull - protected String loadDocument(@NotNull URL documentURL) throws IOException { + @NonNull + protected String loadDocument(@NonNull URL documentURL) throws IOException { final HttpURLConnection URIConnection = (HttpURLConnection)documentURL.openConnection(); mHttpURLConnection.set(URIConnection); @@ -174,14 +174,14 @@ protected String loadDocument(@NotNull URL documentURL) throws IOException { * Asset Links tree. */ protected static final class StatementMatcherWithCallback { - @NotNull + @NonNull public final StatementMatcher statementMatcher; - @NotNull + @NonNull public final AssetLinksJSONParser.StatementMatcherCallback callback; - public StatementMatcherWithCallback(@NotNull StatementMatcher statementMatcher, - @NotNull AssetLinksJSONParser.StatementMatcherCallback callback) { + public StatementMatcherWithCallback(@NonNull StatementMatcher statementMatcher, + @NonNull AssetLinksJSONParser.StatementMatcherCallback callback) { this.statementMatcher = statementMatcher; this.callback = callback; } diff --git a/digitalassetlinks/src/test/java/com/solana/digitalassetlinks/AndroidAppPackageVerifierUnitTests.java b/digitalassetlinks/src/test/java/com/solana/digitalassetlinks/AndroidAppPackageVerifierUnitTests.java index 61747d0..339a5c4 100644 --- a/digitalassetlinks/src/test/java/com/solana/digitalassetlinks/AndroidAppPackageVerifierUnitTests.java +++ b/digitalassetlinks/src/test/java/com/solana/digitalassetlinks/AndroidAppPackageVerifierUnitTests.java @@ -13,7 +13,8 @@ import android.content.pm.SigningInfo; import android.os.Build; -import org.jetbrains.annotations.NotNull; +import androidx.annotation.NonNull; + import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; @@ -201,8 +202,8 @@ public void testAppPackageVerificationNoMatchingPackageInPackageManager() { () ->verifier.verify("com.test.sample", URI.create("https://www.test.com"))); } - private static PackageManager mockPackageManagerFactory(@NotNull String packageName, - @NotNull byte[][] certificates, + private static PackageManager mockPackageManagerFactory(@NonNull String packageName, + @NonNull byte[][] certificates, boolean multipleSigners) { if (certificates.length == 0) { throw new IllegalArgumentException("at least 1 certificate required"); @@ -243,19 +244,19 @@ private static PackageManager mockPackageManagerFactory(@NotNull String packageN } private static class AndroidAppPackageVerifierHarness extends AndroidAppPackageVerifier { - @NotNull + @NonNull private final MockWebContentServer server; public AndroidAppPackageVerifierHarness( - @NotNull PackageManager pm, - @NotNull List mockWebContent) { + @NonNull PackageManager pm, + @NonNull List mockWebContent) { super(pm); server = new MockWebContentServer(mockWebContent); } - @NotNull + @NonNull @Override - protected String loadDocument(@NotNull URL documentURL) throws IOException { + protected String loadDocument(@NonNull URL documentURL) throws IOException { try { return super.loadDocument(server.serve(documentURL.toURI())); } catch (URISyntaxException e) { diff --git a/digitalassetlinks/src/test/java/com/solana/digitalassetlinks/DigitalAssetLinksCompatibilityTestSuite.java b/digitalassetlinks/src/test/java/com/solana/digitalassetlinks/DigitalAssetLinksCompatibilityTestSuite.java index 8e90558..a21461e 100644 --- a/digitalassetlinks/src/test/java/com/solana/digitalassetlinks/DigitalAssetLinksCompatibilityTestSuite.java +++ b/digitalassetlinks/src/test/java/com/solana/digitalassetlinks/DigitalAssetLinksCompatibilityTestSuite.java @@ -6,13 +6,14 @@ import static org.junit.Assert.*; +import androidx.annotation.NonNull; + import com.google.digitalassetlinks.v1.MessagesProto; import com.google.digitalassetlinks.v1.testproto.TestProto; import com.google.protobuf.AbstractMessage; import com.google.protobuf.Message; import com.google.protobuf.TextFormat; -import org.jetbrains.annotations.NotNull; import org.json.JSONArray; import org.json.JSONObject; import org.junit.Assume; @@ -63,7 +64,7 @@ public class DigitalAssetLinksCompatibilityTestSuite { new File(BASE_PATH, "5000-include-file-processing/5000-include-file-processing.pb"), }; - @NotNull + @NonNull @ParameterizedRobolectricTestRunner.Parameters(name="{0} -> {1}") public static Iterable data() { final ArrayList tests = new ArrayList<>(); @@ -91,7 +92,7 @@ public static Iterable data() { return tests; } - private static void loadTextProtobuf(@NotNull File file, @NotNull Message.Builder messageBuilder) { + private static void loadTextProtobuf(@NonNull File file, @NonNull Message.Builder messageBuilder) { try { loadTextProtobuf(new FileReader(file), messageBuilder); } catch (FileNotFoundException e) { @@ -99,7 +100,7 @@ private static void loadTextProtobuf(@NotNull File file, @NotNull Message.Builde } } - private static void loadTextProtobuf(@NotNull Reader reader, @NotNull Message.Builder messageBuilder) { + private static void loadTextProtobuf(@NonNull Reader reader, @NonNull Message.Builder messageBuilder) { final TextFormat.Parser textParser = TextFormat.getParser(); try { textParser.merge(reader, messageBuilder); @@ -108,22 +109,22 @@ private static void loadTextProtobuf(@NotNull Reader reader, @NotNull Message.Bu } } - @NotNull + @NonNull private final String testGroupName; - @NotNull + @NonNull private final String testName; - @NotNull + @NonNull private final TestProto.TestGroup testGroup; - @NotNull + @NonNull private final AbstractMessage testCase; - public DigitalAssetLinksCompatibilityTestSuite(@NotNull String testGroupName, - @NotNull String testName, - @NotNull TestProto.TestGroup testGroup, - @NotNull AbstractMessage testCase) { + public DigitalAssetLinksCompatibilityTestSuite(@NonNull String testGroupName, + @NonNull String testName, + @NonNull TestProto.TestGroup testGroup, + @NonNull AbstractMessage testCase) { this.testGroupName = testGroupName; this.testName = testName; this.testGroup = testGroup; @@ -160,7 +161,7 @@ private void skippedTests() { // List request test case // ============================================================================================= - private void listRequestTestCase(@NotNull TestProto.ListTestCase listTestCase) { + private void listRequestTestCase(@NonNull TestProto.ListTestCase listTestCase) { final MessagesProto.ListRequest request = listTestCase.getRequest(); final MessagesProto.Asset source = request.getSource(); final MessagesProto.Asset.AssetCase assetCase = source.getAssetCase(); @@ -203,8 +204,8 @@ private void listRequestTestCase(@NotNull TestProto.ListTestCase listTestCase) { } } - private void assertStatementsListsMatch(@NotNull List ref, - @NotNull List check) { + private void assertStatementsListsMatch(@NonNull List ref, + @NonNull List check) { assertEquals(ref.size(), check.size()); final ArrayList mutCheck = new ArrayList<>(check); @@ -251,11 +252,11 @@ private void assertStatementsListsMatch(@NotNull List r // the Digital Asset Links Compatibility Test Suite to our verifier implementation. private static class ListRequestVerifierHarness extends MockInjectingURISourceVerifier { public ListRequestVerifierHarness( - @NotNull List hostedWebContents) { + @NonNull List hostedWebContents) { super(hostedWebContents); } - public List list(@NotNull URI uri, @NotNull String relation) + public List list(@NonNull URI uri, @NonNull String relation) throws CouldNotVerifyException, QueryParsingException { if (!AssetLinksGrammar.isValidSiteURI(uri)) { throw new QueryParsingException("Invalid source URI"); @@ -321,7 +322,7 @@ public List list(@NotNull URI uri, @NotNull String rela // Check request test case // ============================================================================================= - private void checkRequestTestCase(@NotNull TestProto.CheckTestCase checkTestCase) { + private void checkRequestTestCase(@NonNull TestProto.CheckTestCase checkTestCase) { final MessagesProto.CheckRequest request = checkTestCase.getRequest(); final MessagesProto.Asset source = request.getSource(); final MessagesProto.Asset.AssetCase assetCase = source.getAssetCase(); @@ -357,13 +358,13 @@ private void checkRequestTestCase(@NotNull TestProto.CheckTestCase checkTestCase // the Digital Asset Links Compatibility Test Suite to our verifier implementation. private static class CheckRequestVerifierHarness extends MockInjectingURISourceVerifier { public CheckRequestVerifierHarness( - @NotNull List hostedWebContents) { + @NonNull List hostedWebContents) { super(hostedWebContents); } - public boolean check(@NotNull URI uri, - @NotNull String relation, - @NotNull MessagesProto.Asset target) + public boolean check(@NonNull URI uri, + @NonNull String relation, + @NonNull MessagesProto.Asset target) throws CouldNotVerifyException, QueryParsingException { if (!AssetLinksGrammar.isValidSiteURI(uri)) { throw new QueryParsingException("Invalid source URI"); @@ -428,7 +429,7 @@ private static class MockInjectingURISourceVerifier extends URISourceVerifier { private boolean hasParserWarnings; public MockInjectingURISourceVerifier( - @NotNull List hostedWebContents) { + @NonNull List hostedWebContents) { if (RUN_LOCALLY) { ArrayList mockWebContents = new ArrayList<>(hostedWebContents.size()); @@ -446,8 +447,8 @@ public MockInjectingURISourceVerifier( } // Removes default port numbers and the trailing FQDN '.' for comparison purposes - @NotNull - private URI canonicalizeURI(@NotNull URI uri) { + @NonNull + private URI canonicalizeURI(@NonNull URI uri) { final boolean hasExplicitDefaultPort; final String scheme = uri.getScheme(); final int port = uri.getPort(); @@ -481,7 +482,7 @@ private URI canonicalizeURI(@NotNull URI uri) { } @Override - protected boolean verify(@NotNull URI sourceURI, StatementMatcherWithCallback... matchers) + protected boolean verify(@NonNull URI sourceURI, StatementMatcherWithCallback... matchers) throws CouldNotVerifyException { final boolean result = super.verify(sourceURI, matchers); hasParserWarnings = !result; @@ -492,9 +493,9 @@ public boolean hasParserWarnings() { return this.hasParserWarnings; } - @NotNull + @NonNull @Override - protected String loadDocument(@NotNull URL documentURL) throws IOException { + protected String loadDocument(@NonNull URL documentURL) throws IOException { URL url; if (RUN_LOCALLY) { try { diff --git a/digitalassetlinks/src/test/java/com/solana/digitalassetlinks/MockWebContentServer.java b/digitalassetlinks/src/test/java/com/solana/digitalassetlinks/MockWebContentServer.java index b02a96a..5c92cd6 100644 --- a/digitalassetlinks/src/test/java/com/solana/digitalassetlinks/MockWebContentServer.java +++ b/digitalassetlinks/src/test/java/com/solana/digitalassetlinks/MockWebContentServer.java @@ -7,8 +7,8 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -26,7 +26,7 @@ public static final class Content { public final String contentType; public final String responseBody; - public Content(@NotNull URI url, + public Content(@NonNull URI url, int responseCode, @Nullable String contentType, @Nullable String responseBody) { @@ -50,8 +50,8 @@ public MockWebContentServer(List contents) { } } - @NotNull - private static URL createMockURLForContent(@NotNull Content content) { + @NonNull + private static URL createMockURLForContent(@NonNull Content content) { try { final HttpURLConnection mockConn = mock(HttpURLConnection.class); when(mockConn.getResponseCode()).thenReturn(content.responseCode); @@ -70,7 +70,7 @@ private static URL createMockURLForContent(@NotNull Content content) { } } - @NotNull + @NonNull public URL serve(URI source) { URL url = mockURLs.get(source); if (url == null) { diff --git a/digitalassetlinks/src/test/java/com/solana/digitalassetlinks/URISourceVerifierUnitTests.java b/digitalassetlinks/src/test/java/com/solana/digitalassetlinks/URISourceVerifierUnitTests.java index 937fa81..cbb4242 100644 --- a/digitalassetlinks/src/test/java/com/solana/digitalassetlinks/URISourceVerifierUnitTests.java +++ b/digitalassetlinks/src/test/java/com/solana/digitalassetlinks/URISourceVerifierUnitTests.java @@ -7,7 +7,8 @@ import static org.junit.Assert.*; import static org.mockito.Mockito.*; -import org.jetbrains.annotations.NotNull; +import androidx.annotation.NonNull; + import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -153,11 +154,11 @@ public void testCancellation() { } private static class URISourceVerifierMockContentHarness extends URISourceVerifier { - @NotNull + @NonNull private final MockWebContentServer server; public URISourceVerifierMockContentHarness( - @NotNull List mockWebContent) { + @NonNull List mockWebContent) { server = new MockWebContentServer(mockWebContent); } @@ -165,9 +166,9 @@ public void verify(URI sourceURI) throws CouldNotVerifyException { super.verify(sourceURI); } - @NotNull + @NonNull @Override - protected String loadDocument(@NotNull URL documentURL) throws IOException { + protected String loadDocument(@NonNull URL documentURL) throws IOException { try { return super.loadDocument(server.serve(documentURL.toURI())); } catch (URISyntaxException e) { @@ -180,9 +181,9 @@ private static class URISourceVerifierCancellationHarness extends URISourceVerif private final Semaphore connectCalledSem = new Semaphore(0); private final Semaphore connectCancelledSem = new Semaphore(0); - @NotNull + @NonNull @Override - protected String loadDocument(@NotNull URL documentURL) throws IOException { + protected String loadDocument(@NonNull URL documentURL) throws IOException { // Busy-wait until disconnect is called (on another thread), then throw an IOException final HttpURLConnection mockConn = mock(HttpURLConnection.class); doAnswer(invocation -> { @@ -199,7 +200,7 @@ protected String loadDocument(@NotNull URL documentURL) throws IOException { return super.loadDocument(mockURL); } - public void launchAsyncAfterConnect(@NotNull Runnable r) { + public void launchAsyncAfterConnect(@NonNull Runnable r) { new Thread(() -> { try { connectCalledSem.acquire();