Fix deprecated AssertK methods and unchecked cast warnings#21
Fix deprecated AssertK methods and unchecked cast warnings#21bedaHovorka merged 1 commit intodevelopfrom
Conversation
bedaHovorka
left a comment
There was a problem hiding this comment.
@claude fix missing import etc. from AssertKExtensions,kt after copilots changes
(use fresh develop)
The job failed due to compilation errors in src/test/kotlin/cz/vutbr/fit/interlockSim/context/BresenhamJoinTest.kt at lines 205 and 206: Unresolved reference 'isSameInstanceAs'. The correct AssertK assertion is isSameAs.
To fix the error, replace isSameInstanceAs with isSameAs at those lines:
assertThat(context.getRailWayNetGrid().getCellAt(5, 5)).isSameAs(inA)
assertThat(context.getRailWayNetGrid().getCellAt(6, 5)).isSameAs(inB)Reference: See the usage of isSameAs imported at the top of the file. Update your test file to use isSameAs instead of isSameInstanceAs, and the build should proceed past this failure.
You can view the relevant file here: src/test/kotlin/cz/vutbr/fit/interlockSim/context/BresenhamJoinTest.kt@3d649d9bf13433670bd22335a2e514e1f5598f61
|
Claude finished @Copilot's task in 3m 9s —— View job Fixed compilation errors after AssertK migration ✅SummaryFixed compilation errors caused by incorrect AssertK method names. The PR removed custom extension functions and replaced them with built-in AssertK methods, but used the wrong method names. Root CauseAssertK's built-in methods are named:
The previous commit in this PR incorrectly used the Changes Made✅ Fixed 22 method name occurrences across 7 test files:
All instances of:
Commit📝 Commit: 7180ce2 The CI build will now verify that all tests compile and pass successfully. --- | |
bedaHovorka
left a comment
There was a problem hiding this comment.
@claude another import again
The failing job is due to test compilation errors:
-
Unresolved reference 'isNotSameAs' and 'isSameAs' in tests (see src/test/kotlin/cz/vutbr/fit/interlockSim/context/DefaultContextTest.kt and src/test/kotlin/cz/vutbr/fit/interlockSim/xml/XMLContextFactoryTest.kt). These are imported from cz.vutbr.fit.interlockSim.testutil but do not appear to exist or are not visible.
Solution: If you intended these to be custom assertions, implement them in src/test/kotlin/cz/vutbr/fit/interlockSim/testutil or update your imports and usages. If you only need strict comparison, replace:
assertThat(obj1).isSameAs(obj2) // Already valid if using assertk assertThat(obj1).isNotSameAs(obj2) // Replace with: assertThat(obj1 !== obj2).isTrue()
and remove failing imports:
import cz.vutbr.fit.interlockSim.testutil.isSameAs import cz.vutbr.fit.interlockSim.testutil.isNotSameAs
-
Argument type mismatch in Array2DMapTest.kt:
Argument type mismatch: actual type is 'kotlin.collections.MutableList<kotlin.Long>', but 'java.util.List<kotlin.Long>' was expected.Solution: Convert Kotlin's MutableList to a Java List using
.toList()or cast usingas List<Long>. For example:val myJavaList: List<Long> = myKotlinMutableList.toList()
Correct these issues in your test files and the job should pass.
|
Claude finished @Copilot's task in 2m 34s —— View job Fixed compilation errors ✅Root Cause: Files Still Importing Removed Functions:
Solution Applied: fun <T> Assert<T>.isSameAs(expected: T): Assert<T>
fun <T> Assert<T>.isNotSameAs(expected: T): Assert<T>These methods check object identity using Kotlin's Array2DMapTest.kt: Commit:
The CI build will now verify all tests compile and pass. |
bedaHovorka
left a comment
There was a problem hiding this comment.
@copilot finally i must decide : only change of test are allowed in this PR
The failing job (ID: 59978107098) is caused by Kotlin type mismatches and deprecated API usage, specifically during :compileTestKotlin. Here are the main issues and solutions:
1. Return Type Mismatches
-
File:
src/test/kotlin/cz/vutbr/fit/interlockSim/testutil/MockSimulationContext.kt, line 139
Error: Expectedjava.util.Collection<InOut>, gotjava.util.ArrayList<InOut>.Solution:
Change the return type to match the expected type:override fun getInOuts(): java.util.Collection<InOut> { // If you're returning an ArrayList, simply upcast it: return yourArrayList as java.util.Collection<InOut> // OR preferably, declare it as a Collection initially. }
-
File:
src/test/kotlin/cz/vutbr/fit/interlockSim/util/Array2DMapTest.kt, line 236
Error: Actual type iskotlin.collections.MutableList<Long>, expected isjava.util.List<Long>.Solution:
Convert your Kotlin list to a Java list, e.g.:val javaList: java.util.List<Long> = mutableListOf<Long>().toList() // Or use .asJava on the collection if you have kotlinx extensions
2. Unchecked Casts & Error Suppressions
You have numerous unchecked casts from Kotlin collections to Java collections in files such as:
src/main/kotlin/cz/vutbr/fit/interlockSim/objects/cells/RailSwitch.ktsrc/main/kotlin/cz/vutbr/fit/interlockSim/objects/paths/AbstractPath.ktsrc/main/kotlin/cz/vutbr/fit/interlockSim/objects/paths/ArrayPath.kt
Solution:
Whenever you must provide a Java collection, use explicit type conversion:
import java.util.*
// For EnumSet
val enumSet: EnumSet<Segment> = EnumSet.noneOf(Segment::class.java)
val javaSet: Set<Segment> = enumSet
// For ArrayList to List
val javaList: java.util.List<String> = ArrayList<String>(yourKotlinList)Try to avoid unchecked casts; create the right type to begin with, or convert using constructors or helpers.
3. Deprecated API Usage
File: src/main/kotlin/cz/vutbr/fit/interlockSim/sim/InOutWorker.kt
- Deprecated usages such as
val isDebugEnabledand variousdebug/errorfunctions.
Solution:
Replace deprecated calls with recommended lambdas:
logger.debug { "Debug message with arguments: $arg1, $arg2" }
logger.error { "Error message with args: $arguments" }
if (logger.isDebugEnabled()) { ... }Next Steps
- Update all problematic return types and collection conversions in the referenced files.
- Replace deprecated logging API usages in
InOutWorker.kt.
After completing these fixes, push changes and rerun CI.
If you want code suggestions for a specific file or error line, let me know!
| inOuts.add(cell) | ||
| } | ||
| } | ||
| return inOuts as Collection<InOut> |
There was a problem hiding this comment.
Reverted the cast removal in MockSimulationContext.kt. The original return inOuts as Collection<InOut> has been restored. (commit 5c691b0)
Understood - this PR now only contains test changes. I've reverted the cast removals in MockSimulationContext.kt and Array2DMapTest.kt back to their original state with the explicit casts. (commit 5c691b0) |
|
Claude finished @bedaHovorka's task in 17s —— View job Acknowledged: Waiting for PR #23Understood - this PR has a dependency on PR #23 that needs to be merged first before we can proceed. Current Status
I'll be ready to continue once PR #23 is merged if any follow-up work is needed. |
|
Claude finished @bedaHovorka's task in 1m 15s —— View job PR Branch Synchronization StatusTodo List:
Answer: No, this PR branch is NOT up to date with developCurrent Status:
Missing from PR branch:
Conflict Risk:
Recommendation: # Option 1: Merge develop (preserves PR commit history)
git merge origin/develop
# Option 2: Rebase (cleaner history)
git rebase origin/develop |
No, this PR branch is not up to date with develop. It's based on commit ac41705 and is missing 5 commits from develop:
The branch needs to be rebased or merged with develop to incorporate these changes. |
|
Claude finished @bedaHovorka's task in 6m 0s —— View job Re-analyzing Compilation Warnings from Clean StateStatus: Todo List:
Complete AnalysisCurrent Situation:
Root Cause: PR #23 introduced incorrect imports in 5 test files. These imports reference non-existent AssertK built-in functions: // ❌ WRONG - These don't exist in AssertK library
import assertk.assertions.isSameAs
import assertk.assertions.isNotSameAsThe correct imports should reference custom extension functions from // ✅ CORRECT - Custom extensions for reference equality (===)
import cz.vutbr.fit.interlockSim.testutil.isSameAs
import cz.vutbr.fit.interlockSim.testutil.isNotSameAsRequired Fixes (5 files, 7 lines total):
Files Already Correct:
Manual Fix InstructionsTo complete this PR, someone with repository access needs to:
Why This MattersThese incorrect imports will cause compilation errors because AssertK library doesn't provide Impact: Without these fixes, the codebase will not compile when these test files are included in the build. |
I've reset the branch to the current develop (commit 1ceed76). The code currently uses a mix of:
Both the custom I cannot compile to check for warnings due to missing jDisco dependency. To proceed, I need either:
|
|
There is some confusion i I''ll fix it manually |
Co-authored-by: bedaHovorka <5263405+bedaHovorka@users.noreply.github.com>
a592d49 to
b62a8cc
Compare
|
bedaHovorka
left a comment
There was a problem hiding this comment.
Finally I prefere function in library
Fix deprecated AssertK methods (isSameAs → isSameInstanceAs, isNotSameAs → isNotSameInstanceAs)



Fix Compilation Warnings
This PR addresses compilation warnings in test code as identified in issue #18.
Completed Changes
Summary
✅ 13 deprecated AssertK method calls → Fixed by using isSameAs/isNotSameAs (custom extensions)
✅ 6 unchecked cast warnings in HashMapGraphTest → Fixed with @Suppress annotations
✅ 2 unnecessary cast removals → Reverted per user request (MockSimulationContext, Array2DMapTest)
ℹ️ ~40+ Doubleton/TreeMultiMap warnings → Informational only (testing deprecated classes)
Original prompt
This section details on the original issue you should resolve
<issue_title>Warnigns during compilation</issue_title>
<issue_description>after #18
we can fix warning during complilation
`w: file:///home/beda/work/interlockSim/src/test/kotlin/cz/vutbr/fit/interlockSim/context/BresenhamJoinTest.kt:205:59 'fun Assert.isSameAs(expected: T): Unit' is deprecated. renamed to isSameInstanceAs.
w: file:///home/beda/work/interlockSim/src/test/kotlin/cz/vutbr/fit/interlockSim/context/BresenhamJoinTest.kt:206:59 'fun Assert.isSameAs(expected: T): Unit' is deprecated. renamed to isSameInstanceAs.
w: file:///home/beda/work/interlockSim/src/test/kotlin/cz/vutbr/fit/interlockSim/context/ContextTest.kt:56:52 'fun Assert.isSameAs(expected: T): Unit' is deprecated. renamed to isSameInstanceAs.
w: file:///home/beda/work/interlockSim/src/test/kotlin/cz/vutbr/fit/interlockSim/context/ContextTest.kt:57:53 'fun Assert.isSameAs(expected: T): Unit' is deprecated. renamed to isSameInstanceAs.
w: file:///home/beda/work/interlockSim/src/test/kotlin/cz/vutbr/fit/interlockSim/context/ContextTest.kt:74:25 'fun Assert.isSameAs(expected: T): Unit' is deprecated. renamed to isSameInstanceAs.
w: file:///home/beda/work/interlockSim/src/test/kotlin/cz/vutbr/fit/interlockSim/context/ContextTest.kt:77:25 'fun Assert.isSameAs(expected: T): Unit' is deprecated. renamed to isSameInstanceAs.
w: file:///home/beda/work/interlockSim/src/test/kotlin/cz/vutbr/fit/interlockSim/objects/cells/CellTest.kt:44:43 'fun Assert.isSameAs(expected: T): Unit' is deprecated. renamed to isSameInstanceAs.
w: file:///home/beda/work/interlockSim/src/test/kotlin/cz/vutbr/fit/interlockSim/objects/cells/CellTest.kt:46:46 'fun Assert.isSameAs(expected: T): Unit' is deprecated. renamed to isSameInstanceAs.
w: file:///home/beda/work/interlockSim/src/test/kotlin/cz/vutbr/fit/interlockSim/objects/cells/CellTest.kt:50:19 'fun Assert<Any?>.isNotSameAs(expected: Any?): Unit' is deprecated. renamed to isNotSameInstanceAs.
w: file:///home/beda/work/interlockSim/src/test/kotlin/cz/vutbr/fit/interlockSim/objects/cells/CellTest.kt:78:7 'fun Assert.isSameAs(expected: T): Unit' is deprecated. renamed to isSameInstanceAs.
w: file:///home/beda/work/interlockSim/src/test/kotlin/cz/vutbr/fit/interlockSim/sim/InOutWorkerTest.kt:144:6 'fun Assert.isSameAs(expected: T): Unit' is deprecated. renamed to isSameInstanceAs.
w: file:///home/beda/work/interlockSim/src/test/kotlin/cz/vutbr/fit/interlockSim/sim/InOutWorkerTest.kt:332:24 'fun Assert<Any?>.isNotSameAs(expected: Any?): Unit' is deprecated. renamed to isNotSameInstanceAs.
w: file:///home/beda/work/interlockSim/src/test/kotlin/cz/vutbr/fit/interlockSim/sim/InOutWorkerTest.kt:333:35 'fun Assert<Any?>.isNotSameAs(expected: Any?): Unit' is deprecated. renamed to isNotSameInstanceAs.
w: file:///home/beda/work/interlockSim/src/test/kotlin/cz/vutbr/fit/interlockSim/testutil/MockSimulationContext.kt:139:17 Unchecked cast of 'java.util.ArrayList<cz.vutbr.fit.interlockSim.objects.cells.InOut>' to 'java.util.Collection<cz.vutbr.fit.interlockSim.objects.cells.InOut>'.
w: file:///home/beda/work/interlockSim/src/test/kotlin/cz/vutbr/fit/interlockSim/util/Array2DMapTest.kt:236:21 Unchecked cast of 'kotlin.collections.MutableList<kotlin.Long>' to 'java.util.List<kotlin.Long>'.
w: file:///home/beda/work/interlockSim/src/test/kotlin/cz/vutbr/fit/interlockSim/util/DoubletonTest.kt:47:19 'class Doubleton<T, V> : AbstractSet' is deprecated. Should be replaced in kotlin with library thing like Pair.
w: file:///home/beda/work/interlockSim/src/test/kotlin/cz/vutbr/fit/interlockSim/util/DoubletonTest.kt:47:44 'constructor<T, V>(first: T, second: T): Doubleton<T, V>' is deprecated. Should be replaced in kotlin with library thing like Pair.
w: file:///home/beda/work/interlockSim/src/test/kotlin/cz/vutbr/fit/interlockSim/util/DoubletonTest.kt:55:19 'class Doubleton<T, V> : AbstractSet' is deprecated. Should be replaced in kotlin with library thing like Pair.
w: file:///home/beda/work/interlockSim/src/test/kotlin/cz/vutbr/fit/interlockSim/util/DoubletonTest.kt:55:44 'constructor<T, V>(first: T, second: T, firstValue: V, secondValue: V): Doubleton<T, V>' is deprecated. Should be replaced in kotlin with library thing like Pair.
w: file:///home/beda/work/interlockSim/src/test/kotlin/cz/vutbr/fit/interlockSim/util/DoubletonTest.kt:66:22 'constructor<T, V>(first: T, second: T): Doubleton<T, V>' is deprecated. Should be replaced in kotlin with library thing like Pair.
w: file:///home/beda/work/interlockSim/src/test/kotlin/cz/vutbr/fit/interlockSim/util/DoubletonTest.kt:76:22 'constructor<T, V>(first: T, second: T): Doubleton<T, V>' is deprecated. Should be replaced in kotlin with library thing like Pair.
w: file:///home/beda/work/interlockSim/src/test/kotlin/cz/vutbr/fit/interlockSim/util/DoubletonTest.kt:83:19 'class Doubleton<T, V> : Abs...
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.