Skip to content
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

Migrate from AsssertJ to AssertK #3178

Merged
merged 1 commit into from
Nov 15, 2024
Merged

Conversation

oldergod
Copy link
Member

No description provided.

@oldergod oldergod force-pushed the bquenaudon.2024-11-15.assertk branch 4 times, most recently from d0b7ef4 to 7cb2f4b Compare November 15, 2024 13:41
@oldergod oldergod requested review from squarejesse, JakeWharton and swankjesse and removed request for squarejesse November 15, 2024 15:15
@oldergod oldergod marked this pull request as ready for review November 15, 2024 15:15
@oldergod oldergod force-pushed the bquenaudon.2024-11-15.assertk branch from 7cb2f4b to 174e8cc Compare November 15, 2024 15:16
@@ -69,7 +72,7 @@ class ManifestParseTest {
""".trimMargin()

val modules = parseManifestModules(yaml)
assertThat(modules.keys).containsExactly("one", "two")
assertThat(modules.getValue("one").dependencies).containsExactly("two")
assertThat(modules.keys.toList()).containsExactly("one", "two")
Copy link
Contributor

Choose a reason for hiding this comment

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

containsExactly –> containsOnly
willowtreeapps/assertk#489

Copy link
Member Author

Choose a reason for hiding this comment

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

lmao

Copy link
Member Author

Choose a reason for hiding this comment

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

But assertJ containsExactly also checks the order, which is why I keep this assertion here.

Copy link
Member Author

Choose a reason for hiding this comment

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

but sets don't have ordering... so

@@ -827,7 +830,7 @@ class WireCompilerTest {
private fun assertOutputs(target: TargetLanguage, outputs: Array<String>, suffix: String = "") {
val filesAfter = paths
assertThat(filesAfter.size)
.overridingErrorMessage(filesAfter.toString())
// .overridingErrorMessage(filesAfter.toString())
Copy link
Contributor

Choose a reason for hiding this comment

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

assertThat(filesAfter).hasSize(outputs.size)

.cause() // Synthetic exception added by coroutines in StackTraceRecovery.kt.
.cause()
.hasMessage("boom!")
assertThat(expected).all {
Copy link
Contributor

Choose a reason for hiding this comment

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

switch to assertFailsWith<IOException>

// |Expected :$message (unknownFields: `${(message as com.squareup.wire.Message<*, *>).unknownFields.hex()}`)
// |Actual :$fromJson (unknownFields: `${(fromJson as com.squareup.wire.Message<*, *>).unknownFields.hex()}`)
// """.trimMargin()
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

assertThat(fromJson, displayActual = {...})

Copy link
Member Author

Choose a reason for hiding this comment

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

very nice

Copy link
Collaborator

@JakeWharton JakeWharton left a comment

Choose a reason for hiding this comment

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

Lots of the !! could be replaced with inline isNotNull() assertions, but it doesn't really matter all that much.

Comment on lines 832 to 835
assertThat(filesAfter.size)
.overridingErrorMessage(filesAfter.toString())
// .overridingErrorMessage(filesAfter.toString())
.isEqualTo(outputs.size)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can do

assertThat(filesAfter)
  .size()
  .isEqualTo(outputs.size)

which should include the list if it fails.

@@ -335,7 +350,7 @@ class GrpcClientTest {
delay(200)
responseChannel.cancel()
mockService.awaitSuccess()
assertThat(callReference.get()?.isCanceled()).isTrue()
assertThat(callReference.get()!!.isCanceled()).isTrue()
Copy link
Collaborator

Choose a reason for hiding this comment

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

The need to do this !! is fixed on AssertK trunk

Copy link
Member Author

Choose a reason for hiding this comment

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

just waiting for a release, really

@@ -459,7 +474,7 @@ class GrpcClientTest {

val latch = Mutex(locked = true)
requestChannel.invokeOnClose { expected ->
assertThat(expected).isInstanceOf(CancellationException::class.java)
assertThat(expected!!).isInstanceOf<CancellationException>()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similarly, the need to do this !! is fixed on AssertK trunk

assertThat(expected).all {
hasMessage("gRPC transport failure (HTTP status=200, grpc-status=null, grpc-message=null)")
// Synthetic exception added by coroutines in StackTraceRecovery.kt.
prop(Throwable::cause)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
prop(Throwable::cause)
cause()

// Synthetic exception added by coroutines in StackTraceRecovery.kt.
prop(Throwable::cause)
.isNotNull()
.prop(Throwable::cause)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
.prop(Throwable::cause)
.cause()

@@ -15,6 +15,7 @@
*/
package com.squareup.wire

import assertk.assertions.message
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are these really used? Or was this from some kind of automated refactor?

@oldergod oldergod force-pushed the bquenaudon.2024-11-15.assertk branch from 174e8cc to dea98d6 Compare November 15, 2024 16:32
@oldergod oldergod force-pushed the bquenaudon.2024-11-15.assertk branch from dea98d6 to c394f17 Compare November 15, 2024 16:36
@oldergod
Copy link
Member Author

I addressed all comments, thank you

@oldergod oldergod merged commit 747eaf3 into master Nov 15, 2024
11 checks passed
@oldergod oldergod deleted the bquenaudon.2024-11-15.assertk branch November 15, 2024 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants