Skip to content

Make tests scala 3 friendlier #576

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
merged 1 commit into from
Jul 18, 2025

Conversation

jozic
Copy link
Contributor

@jozic jozic commented Jul 2, 2025

These are low hanging fruits on the path to Scala 3. Not 100% sure we gonna get there without loses, but I hope so :)

One minor concern is dropped test using scala.reflect.io.AbstractFile (which doesn't exist in Scala 3) and named not mock final methods but that method path is not final, so I'm not sure what exactly that test was doing.
Maybe @ultrasecreth can shed some light.

@jozic jozic force-pushed the scala-3-friendlier-tests branch from de59e33 to 1aafae0 Compare July 17, 2025 12:12
@jozic jozic force-pushed the scala-3-friendlier-tests branch from 1aafae0 to 58cb6d9 Compare July 17, 2025 12:37
@jozic jozic marked this pull request as ready for review July 17, 2025 19:59
@jozic
Copy link
Contributor Author

jozic commented Jul 17, 2025

@TimvdLippe please check it out, should be an easy one

@@ -317,14 +316,6 @@ class MockitoSugarTest extends AnyWordSpec with MockitoSugar with Matchers with
org.takesManyValueClasses(new ValueClass("1"), ValueCaseClassInt(2), ValueCaseClassString("3")) shouldBe "ValueClass(1)-ValueCaseClassInt(2)-ValueCaseClassString(3)"
}

"not mock final methods" in {
val abstractFile = mock[AbstractFile]
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we create our own class which has final methods and mock those instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do that but I'm not sure what the test should be, as the current test is basically testing regular method stubbing

    val abstractFile = mock[AbstractFile] 
       when(abstractFile.path) thenReturn "sammy.scala" 
       abstractFile.path shouldBe "sammy.scala" 
     }

Do you have an idea what the real test should look like?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't recall to be honest. I am okay with merging as-is and see if we regress in the future, as the commit in question doesn't mention the motivation for the bug unfortunately.

@TimvdLippe TimvdLippe merged commit bc2e746 into mockito:release/2.x Jul 18, 2025
5 checks passed
@jozic jozic deleted the scala-3-friendlier-tests branch July 18, 2025 15:04
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.

2 participants