-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure that serialized signatures use HashSets
Because Animal Sniffer signatures are serialized using Java Serialization, we need to make sure that the types embedded into the signatures are available on the classpath when Animal Sniffer is run. Specifically, for Clazz.signatures, when the set is empty, Kotlin's toSet method will return a kotlin.collections.EmptySet. This change ensures that a plain HashSet is always used. Fixes #23.
- Loading branch information
Showing
4 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
api/19/src/test/java/com/toasttab/android/Api19SignaturesTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (c) 2023. Toast Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.toasttab.android | ||
|
||
import org.codehaus.mojo.animal_sniffer.Clazz | ||
import org.junit.Test | ||
import strikt.api.expectThat | ||
import strikt.assertions.all | ||
import strikt.assertions.contains | ||
import strikt.assertions.isA | ||
import strikt.assertions.isNotNull | ||
import java.io.File | ||
import java.io.ObjectInputStream | ||
import java.util.zip.GZIPInputStream | ||
|
||
class Api19SignaturesTest { | ||
@Test | ||
fun `signatures include Integer#hashCode(int)`() { | ||
val desc = ObjectInputStream(GZIPInputStream(File(System.getProperty("signatures")).inputStream())).use { | ||
generateSequence { it.readObject() as Clazz? }.toList() | ||
} | ||
|
||
val integer = desc.find { it.name == "java/lang/Integer" } | ||
|
||
expectThat(integer).isNotNull().and { | ||
get { signatures }.contains("hashCode(I)I") | ||
} | ||
} | ||
|
||
@Test | ||
fun `core lib signatures include Stream#count()`() { | ||
val desc = ObjectInputStream(GZIPInputStream(File(System.getProperty("coreLibSignatures")).inputStream())).use { | ||
generateSequence { it.readObject() as Clazz? }.toList() | ||
} | ||
|
||
val stream = desc.find { it.name == "java/util/stream/Stream" } | ||
|
||
expectThat(stream).isNotNull().and { | ||
get { signatures }.contains("count()J") | ||
} | ||
} | ||
|
||
@Test | ||
fun `signatures use HashSet`() { | ||
val desc = ObjectInputStream(GZIPInputStream(File(System.getProperty("signatures")).inputStream())).use { | ||
generateSequence { it.readObject() as Clazz? }.toList() | ||
} | ||
|
||
expectThat(desc).all { | ||
get { signatures }.isA<HashSet<*>>() | ||
} | ||
} | ||
|
||
@Test | ||
fun `core lib signatures use HashSet`() { | ||
val desc = ObjectInputStream(GZIPInputStream(File(System.getProperty("coreLibSignatures")).inputStream())).use { | ||
generateSequence { it.readObject() as Clazz? }.toList() | ||
} | ||
|
||
expectThat(desc).all { | ||
get { signatures }.isA<HashSet<*>>() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters