Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

[New arch] Use moshi to parse sharees #352

Merged
merged 18 commits into from
Oct 29, 2020
Merged

Conversation

theScrabi
Copy link
Contributor

@theScrabi theScrabi commented Oct 14, 2020

related issue: owncloud/android#2704
related app pr: owncloud/android#2994

Copy link
Contributor

@abelgardep abelgardep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes requested @theScrabi

owncloudComLibrary/build.gradle Outdated Show resolved Hide resolved
owncloudComLibrary/build.gradle Outdated Show resolved Hide resolved
owncloudComLibrary/build.gradle Outdated Show resolved Hide resolved
Comment on lines 82 to 87
val EXAMPLE_RESPONSE = """
{
"ocs": {
"data": {
"exact": {
"groups": [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it, but i think that we could create a new responses package with json files and import those files in the test. That way we will have all responses in the same package as real json and not in companion as strings. What do you think? I could help to do it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, tell me if you need some help to do it

private const val NODE_EXACT = "exact"
private const val NODE_USERS = "users"
private const val NODE_GROUPS = "groups"
private const val NODE_REMOTES = "remotes"
const val NODE_VALUE = "value"
const val PROPERTY_LABEL = "label"
const val PROPERTY_SHARE_TYPE = "shareType"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some constants are not used anywhere, could you take a look?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those properties are not used anymore, you parse it directly using moshi. I think you can remove them.

Copy link
Contributor

@abelgardep abelgardep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@theScrabi Tiny suggestions

private const val NODE_EXACT = "exact"
private const val NODE_USERS = "users"
private const val NODE_GROUPS = "groups"
private const val NODE_REMOTES = "remotes"
const val NODE_VALUE = "value"
const val PROPERTY_LABEL = "label"
const val PROPERTY_SHARE_TYPE = "shareType"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those properties are not used anymore, you parse it directly using moshi. I think you can remove them.

private val values = values();
fun fromValue(value: Int) = values.firstOrNull { it.value == value }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private val values = values();
fun fromValue(value: Int) = values.firstOrNull { it.value == value }
fun fromValue(value: Int) = values().firstOrNull { it.value == value }

Copy link
Contributor

@abelgardep abelgardep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at the failing tests and then we move it forward 🚀 @theScrabi

Comment on lines 180 to 171
private const val NODE_GROUPS = "groups"
private const val NODE_REMOTES = "remotes"
const val NODE_VALUE = "value"
const val PROPERTY_LABEL = "label"
const val PROPERTY_SHARE_TYPE = "shareType"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some constants that are not used anymore. Please, remove them. @theScrabi

@@ -0,0 +1,60 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it 🎉 🎉 But tests failed, could you take a look? 👍

@theScrabi theScrabi force-pushed the new_arch/moshi_parse_sharees branch 2 times, most recently from 77739ef to 9c9a225 Compare October 21, 2020 14:18
Copy link
Contributor

@abelgardep abelgardep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some questions here @theScrabi


@Test
fun `check structure - ok - contains users`() {
assertNotEquals(null, response.ocs.data.users)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are using the same response on each test, why shouldn't we unify them in a single one?

assertNull
assertNotNull 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please correct me if I am wrong, but I learned that every test should test one thing and not everything. Am I wrong?

Comment on lines 115 to 85
fun `check empty response - ok - parsing ok`() {
val moshi = Moshi.Builder().build()
val type: Type = Types.newParameterizedType(CommonOcsResponse::class.java, ShareeOcsResponse::class.java)
val adapter: JsonAdapter<CommonOcsResponse<ShareeOcsResponse>> = moshi.adapter(type)
loadResponses(EMPTY_RESPONSE_JSON, adapter)!!
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To test this, you have a Before where you load a EXAMPLE_RESPONSE_JSON and then you load an empty one. What are you testing here? I cannot see any assert 🤔

Comment on lines 46 to 52
@Before
fun prepare() {
val moshi = Moshi.Builder().build()
val type: Type = Types.newParameterizedType(CommonOcsResponse::class.java, ShareeOcsResponse::class.java)
val adapter: JsonAdapter<CommonOcsResponse<ShareeOcsResponse>> = moshi.adapter(type)
response = loadResponses(EXAMPLE_RESPONSE_JSON, adapter)!!
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would load responses on each test depending on the testing purpose. You can move adapter to a lateinit var for example, and on each test, simply call: loadResponses(EXAMPLE_RESPONSE_JSON) and assert that everything is fine with that response.

Suggested change
@Before
fun prepare() {
val moshi = Moshi.Builder().build()
val type: Type = Types.newParameterizedType(CommonOcsResponse::class.java, ShareeOcsResponse::class.java)
val adapter: JsonAdapter<CommonOcsResponse<ShareeOcsResponse>> = moshi.adapter(type)
response = loadResponses(EXAMPLE_RESPONSE_JSON, adapter)!!
}
@Before
fun prepare() {
val moshi = Moshi.Builder().build()
val type: Type = Types.newParameterizedType(CommonOcsResponse::class.java, ShareeOcsResponse::class.java)
val adapter: JsonAdapter<CommonOcsResponse<ShareeOcsResponse>> = moshi.adapter(type)
}

Comment on lines 54 to 51
@Test
fun `check structure - ok - example response files exist`() {
val file = File(EXAMPLE_RESPONSE_JSON)
assertTrue(file.exists())
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my point of view, this test is not needed. If json do not exists, every test will fail, not only this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, but this way you can directly see what happens.

Copy link
Contributor

@abelgardep abelgardep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved on my side

@abelgardep abelgardep changed the title New arch/moshi parse sharees [New arch] Use moshi to parse sharees Oct 29, 2020
@abelgardep abelgardep merged commit af579a3 into master Oct 29, 2020
@delete-merged-branch delete-merged-branch bot deleted the new_arch/moshi_parse_sharees branch October 29, 2020 12:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants