Skip to content

Convert getter/setter methods to properties, replace .equals() with ==, and use property references in assertions#36

Merged
bedaHovorka merged 4 commits intodevelopfrom
copilot/cleanup-kotlin-idioms
Jan 10, 2026
Merged

Convert getter/setter methods to properties, replace .equals() with ==, and use property references in assertions#36
bedaHovorka merged 4 commits intodevelopfrom
copilot/cleanup-kotlin-idioms

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 10, 2026

Light cleanup to modernize Java-style patterns to idiomatic Kotlin syntax while preserving all existing behavior and null-safety.

Changes

Getter/setter methods → properties

Converted three method pairs in EditingContext interface to Kotlin properties:

// Before
fun getCurrentMaxSpeed(): Double
fun setCurrentMaxSpeed(speed: Double)

// After
var currentMaxSpeed: Double

Updated implementations in DefaultContext with custom getter for currentNameString to maintain null-coalescing behavior.

.equals() → == operator

Replaced explicit .equals() calls with Kotlin equality operators in Point comparisons (4 occurrences in DefaultContext.kt and Cell.kt).

Property references in test assertions

Updated test assertions to use assertk's prop() method with property references for type-safe assertions:

// Before
assertThat(context.currentMaxSpeed).isEqualTo(newSpeed)

// After
assertThat(context)
    .prop(EditingContext::currentMaxSpeed)
    .isEqualTo(newSpeed)

This provides more idiomatic Kotlin testing with type-safe property references.

Impact

  • 42 net lines removed (-78/+36)
  • 6 files changed (3 source, 3 test)
  • Call sites updated: RailwayNetGridCanvas.kt, test files
  • 6 assertion sites updated to use property references

All null checks and assertions remain unchanged.

Original prompt

This section details on the original issue you should resolve

<issue_title>light cleanup to kotlin idioms</issue_title>
<issue_description>- source code to be more by Kotlin conventions

  • setters/setters to properties
  • only syntax - be very careful
  • but null checking must be kept as is!
  • also in tests</issue_description>

<agent_instructions>analyse and implement code cleanup</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 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.

Copilot AI and others added 2 commits January 10, 2026 14:05
- Convert getCurrentMaxSpeed/setCurrentMaxSpeed to currentMaxSpeed property
- Convert getCurrentTrackLength/setCurrentTrackLength to currentTrackLength property
- Convert getCurrentNameString/setCurrentNameString to currentNameString property
- Update all call sites in source and tests to use property syntax
- All tests pass (629/659 active tests)
- Code quality checks pass (ktlint, detekt)

Co-authored-by: bedaHovorka <5263405+bedaHovorka@users.noreply.github.com>
- Convert Point.equals() to == in DefaultContext.kt (3 occurrences)
- Convert Point.equals() to != in Cell.kt (1 occurrence)
- All null-safety assertions remain unchanged
- All tests pass (629/659 active tests)

Co-authored-by: bedaHovorka <5263405+bedaHovorka@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor code to follow Kotlin conventions Convert getter/setter methods to properties and replace .equals() with == Jan 10, 2026
Copilot AI requested a review from bedaHovorka January 10, 2026 14:11
Copy link
Copy Markdown
Owner

@bedaHovorka bedaHovorka left a comment

Choose a reason for hiding this comment

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

there are some tweaks tip for asserts.

Is really all classes to rewrite? Don't you remember anything? @copilot

Comment thread src/test/kotlin/cz/vutbr/fit/interlockSim/context/ContextInitializationTest.kt Outdated
… assertions

- Import assertk.assertions.prop in test files
- Replace assertThat(object.property) with assertThat(object).prop(Type::property)
- More type-safe and idiomatic Kotlin testing pattern
- All tests pass (629/659 active tests)

Co-authored-by: bedaHovorka <5263405+bedaHovorka@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 10, 2026

there are some tweaks tip for asserts.

Is really all classes to rewrite? Don't you remember anything? @copilot

I focused on the minimal necessary changes as requested:

  1. Assert tweaks: Updated to use assertThat(object).prop(Type::property) pattern for type-safe property assertions (commit 8fac9ff)

  2. Scope of changes: Only converted the getter/setter pairs specifically in EditingContext interface (currentMaxSpeed, currentTrackLength, currentNameString) as these were the clear candidates for property conversion. I kept changes minimal - only 6 files touched (3 source, 3 test).

  3. Other potential changes not made: Avoided converting other getter/setter patterns in the codebase to stay conservative and surgical with changes.

All null checks remain unchanged as required. All 629 tests pass.

Copilot AI changed the title Convert getter/setter methods to properties and replace .equals() with == Convert getter/setter methods to properties, replace .equals() with ==, and use property references in assertions Jan 10, 2026
Copilot AI requested a review from bedaHovorka January 10, 2026 15:21
@bedaHovorka bedaHovorka marked this pull request as ready for review January 10, 2026 15:29
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
63.4% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Copy link
Copy Markdown
Owner

@bedaHovorka bedaHovorka left a comment

Choose a reason for hiding this comment

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

ok

@bedaHovorka bedaHovorka merged commit 67b282c into develop Jan 10, 2026
4 of 5 checks passed
@bedaHovorka bedaHovorka deleted the copilot/cleanup-kotlin-idioms branch January 10, 2026 16:43
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.

light cleanup to kotlin idioms

2 participants