-
Notifications
You must be signed in to change notification settings - Fork 148
Conversation
8e52305
to
88cb76b
Compare
There was a problem hiding this 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/src/main/java/com/owncloud/android/lib/resources/CommonOcsResponse.kt
Show resolved
Hide resolved
val EXAMPLE_RESPONSE = """ | ||
{ | ||
"ocs": { | ||
"data": { | ||
"exact": { | ||
"groups": [], |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good
There was a problem hiding this comment.
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
owncloudComLibrary/src/test/java/com/owncloud/android/lib/ShareeResponseTest.kt
Outdated
Show resolved
Hide resolved
owncloudComLibrary/src/test/java/com/owncloud/android/lib/ShareeResponseTest.kt
Outdated
Show resolved
Hide resolved
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" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
...Library/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteShareesOperation.kt
Outdated
Show resolved
Hide resolved
...mLibrary/src/main/java/com/owncloud/android/lib/resources/shares/responses/ShareeResponse.kt
Outdated
Show resolved
Hide resolved
owncloudComLibrary/src/test/java/com/owncloud/android/lib/ShareeResponseTest.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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" |
There was a problem hiding this comment.
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 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private val values = values(); | |
fun fromValue(value: Int) = values.firstOrNull { it.value == value } | |
fun fromValue(value: Int) = values().firstOrNull { it.value == value } |
797ca0d
to
a9e0ee6
Compare
There was a problem hiding this 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
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" |
There was a problem hiding this comment.
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 @@ | |||
{ |
There was a problem hiding this comment.
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? 👍
77739ef
to
9c9a225
Compare
There was a problem hiding this 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) |
There was a problem hiding this comment.
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
🤔
There was a problem hiding this comment.
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?
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)!! | ||
} |
There was a problem hiding this comment.
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 🤔
@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)!! | ||
} |
There was a problem hiding this comment.
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.
@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) | |
} |
@Test | ||
fun `check structure - ok - example response files exist`() { | ||
val file = File(EXAMPLE_RESPONSE_JSON) | ||
assertTrue(file.exists()) | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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
delete unused const values bla
fdb373f
to
68b8877
Compare
related issue: owncloud/android#2704
related app pr: owncloud/android#2994