-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Improves non mockability reasons also report mock maker, mockito version #3535
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
base: main
Are you sure you want to change the base?
Conversation
Triggers generation after idea sync Revisits class generation with task class
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3535 +/- ##
============================================
- Coverage 85.60% 84.73% -0.88%
+ Complexity 2954 2946 -8
============================================
Files 341 342 +1
Lines 8976 9006 +30
Branches 1118 1122 +4
============================================
- Hits 7684 7631 -53
- Misses 1003 1075 +72
- Partials 289 300 +11 ☔ View full report in Codecov by Sentry. |
fe3dcbf
to
52e746c
Compare
} | ||
|
||
tasks.withType<Checkstyle> { | ||
exclude("org/mockito/internal/util/MockitoVersion.java") |
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.
Ultra-nit: define constant value to use both here and in the task implementation
|
||
configure<SpotlessExtension> { | ||
java { | ||
targetExclude(relativePath(generateVersionClass.get().generatedVersionClassDir) + "/**") |
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.
Nit: to avoid eager configuration, let's also define a constant for project.layout.buildDirectory.dir("generated/sources/version/java")
. That way, we define it once and use it twice to configure:
val generatedVersionClassDirLocation = project.layout.buildDirectory.dir("generated/sources/version/java")
generateVersionClass.configure {
generatedVersionClassDir(generatedVersionClassDirLocation)
}
configure<SpotlessExtension> {
java {
targetExclude(relativePath(generatedVersionClassDirLocation) + "/**")
}
}
That also allows us to remove the .convention
on the task property
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.
Good observation!
return INSTRUMENTATION.isModifiableClass(type) && !EXCLUDES.contains(type); | ||
return INSTRUMENTATION.isModifiableClass(type) | ||
&& !EXCLUDES.contains(type) | ||
&& !(Modifier.isAbstract(type.getModifiers()) |
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.
Nit: use TypeSupport.isAbstractAndSealed
here (and below)
if (type.isEnum()) { | ||
return "Sealed abstract enums can't be mocked. Since Java 15 abstract enums are declared sealed, which prevents mocking. You can still return an existing enum literal from a stubbed method call."; | ||
} else { | ||
return "Sealed interfaces or abstract classes can't be mocked. Interfaces cannot be instantiated and cannot be subclassed for mocking purposes. Instead of mocking a sealed interface or an abstract class, a non-abstract class can be mocked and used to represent the interface."; |
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.
Nit: use join
to make it multiple lines and a bit more readable.
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 I didn't it's because this string will appear has single reason prefixed by -
. Joining will land the next line on column 0.
This can be worked around though.
Seems like the build logs were cut off, but the raw logs still had the full build. Here's the relevant scan with failing tests: https://scans.gradle.com/s/72gtfyapmryfw |
024937c
to
5eaf285
Compare
This comment was marked as off-topic.
This comment was marked as off-topic.
31a03ef
to
1cba555
Compare
Can you split up the commits in separate PRs so we can debug these issues in isolation? That way we are more likely to figure out which commit/change is the culprit for instability |
Improves a bit the error report
abstract sealed class
being non mockableShould help diagnosing in cases like
Supersedes #3531 as its gha workflow doesn't start anymore
Checklist
including project members to get a better picture of the change
commit is meaningful and help the people that will explore a change in 2 years
Fixes #<issue number>
in the description if relevantFixes #<issue number>
if relevant