-
-
Notifications
You must be signed in to change notification settings - Fork 472
Vendor JSON Writer/Reader: OperatingSystem #1671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
denrase
merged 8 commits into
feat/vendor-json-writer-reader
from
feat/vendor-json-writer-reader-os
Aug 26, 2021
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
39139ab
move unknwn getter/setter requirement to own interface
denrase 8eda7f6
mark interface as public
denrase ecc145e
generate api dump
denrase 7f51fbc
add test json file and implement serialization interfaces
denrase 027a468
test operating system serialization/deserialization
denrase 6e47f1a
update api
denrase f6c2d06
handle unknown in os
denrase 2dc0171
Merge branch 'feat/vendor-json-writer-reader' into feat/vendor-json-w…
denrase File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
67 changes: 67 additions & 0 deletions
67
sentry/src/test/java/io/sentry/protocol/OeratingSystemSerializationTest.kt
This file contains hidden or 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,67 @@ | ||
| package io.sentry.protocol | ||
|
|
||
| import com.nhaarman.mockitokotlin2.mock | ||
| import io.sentry.FileFromResources | ||
| import io.sentry.ILogger | ||
| import io.sentry.JsonObjectReader | ||
| import io.sentry.JsonObjectWriter | ||
| import io.sentry.JsonSerializable | ||
| import java.io.StringReader | ||
| import java.io.StringWriter | ||
| import kotlin.test.assertEquals | ||
| import org.junit.Test | ||
|
|
||
| class OperatingSystemSerializationTest { | ||
| private class Fixture { | ||
| var logger: ILogger = mock() | ||
|
|
||
| fun getSut() = OperatingSystem().apply { | ||
| name = "686a11a8-eae7-4393-aa10-a1368d523cb2" | ||
| version = "3033f32d-6a27-4715-80c8-b232ce84ca61" | ||
| rawDescription = "eb2d0c5e-f5d4-49c7-b876-d8a654ee87cf" | ||
| build = "bd197b97-eb68-49c3-9d07-ef789caf3069" | ||
| kernelVersion = "1df24aec-3a6f-49a9-8b50-69ae5f9dde08" | ||
| isRooted = true | ||
| } | ||
| } | ||
| private val fixture = Fixture() | ||
|
|
||
| @Test | ||
| fun serialize() { | ||
| val expected = sanitizedFile("gson/operating_system.json") | ||
| val actual = serializeToString(fixture.getSut()) | ||
| assertEquals(expected, actual) | ||
| } | ||
|
|
||
| @Test | ||
| fun deserialize() { | ||
| val expectedJson = sanitizedFile("gson/operating_system.json") | ||
| val actual = deserialize(expectedJson) | ||
| val actualJson = serializeToString(actual) | ||
| assertEquals(expectedJson, actualJson) | ||
| } | ||
|
|
||
| // Helper | ||
|
|
||
| private fun sanitizedFile(path: String): String { | ||
| return FileFromResources.invoke(path) | ||
| .replace(Regex("[\n\r]"), "") | ||
| .replace(" ", "") | ||
| } | ||
|
|
||
| private fun serializeToString(jsonSerializable: JsonSerializable): String { | ||
| return this.serializeToString { wrt -> jsonSerializable.serialize(wrt, fixture.logger) } | ||
| } | ||
|
|
||
| private fun serializeToString(serialize: (JsonObjectWriter) -> Unit): String { | ||
| val wrt = StringWriter() | ||
| val jsonWrt = JsonObjectWriter(wrt) | ||
| serialize(jsonWrt) | ||
| return wrt.toString() | ||
| } | ||
|
|
||
| private fun deserialize(json: String): OperatingSystem { | ||
| val reader = JsonObjectReader(StringReader(json)) | ||
| return OperatingSystem.Deserializer().deserialize(reader, fixture.logger) | ||
| } | ||
| } | ||
This file contains hidden or 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,8 @@ | ||
| { | ||
| "name": "686a11a8-eae7-4393-aa10-a1368d523cb2", | ||
| "version": "3033f32d-6a27-4715-80c8-b232ce84ca61", | ||
| "raw_description": "eb2d0c5e-f5d4-49c7-b876-d8a654ee87cf", | ||
| "build": "bd197b97-eb68-49c3-9d07-ef789caf3069", | ||
| "kernel_version": "1df24aec-3a6f-49a9-8b50-69ae5f9dde08", | ||
| "rooted": true | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.