Skip to content

altan/develop: Selection Tool: refactor, tests and lab portfolio#13

Open
AltanEsmer wants to merge 9 commits into
developfrom
altan/develop
Open

altan/develop: Selection Tool: refactor, tests and lab portfolio#13
AltanEsmer wants to merge 9 commits into
developfrom
altan/develop

Conversation

@AltanEsmer

Copy link
Copy Markdown
Collaborator

My individual work on the Selection Tool feature (org.jhotdraw.draw.tool.SelectionTool).

  • Refactored SelectionTool: extract/compose method on mousePressed, a single isViewActive() guard in place of the duplicated view checks, and the figure lookup split into focused helpers.
  • Unit tests (JUnit 4 + Mockito) and JGiven BDD scenarios for the feature, including US2 (clicking an empty area clears the selection).
  • Enabled assertions in surefire; removed the unused assertj-swing-junit dependency.
  • Labs/ portfolio write-ups: concept location, user story, impact analysis, refactoring, actualization, testing and BDD.

User story: #12.

Add a CI Maven settings file (.maven-settings.xml) that provides a GitHub server entry using ${env.GITHUB_ACTOR} and ${env.GITHUB_TOKEN}. Update jhotdraw-core/pom.xml to include several test dependencies (junit 4.13.2, mockito-core 3.12.4, jgiven-junit 1.3.1, assertj-core 3.24.2, assertj-swing-junit 3.17.1) and configure the maven-surefire-plugin (3.2.5) with --add-opens JVM args for java.lang and java.lang.reflect to allow reflective access during tests.
Extract mouse-press logic into helper methods (findTargetFigure, resolveTracker) and add isViewActive() for concise view checks. Consolidate tracker activation/deactivation into setTracker (with null guard) and update toolDone to use it. Replace repetitive getView()/isEnabled() checks with isViewActive and preserve existing select-behind and handle/drag/selection behaviors. Adds Javadoc for new helpers and cleans up control flow for readability and maintainability.
Add comprehensive tests for SelectionTool: a JUnit4 + Mockito test suite (SelectionToolTest) that verifies tracker lazy-init, activation/deactivation delegation, select-behind behavior, handle/drag/select-area resolution, property change firing, and boundary/invariant cases. Add JGiven BDD tests (GivenSelectionTool, WhenSelectionTool, ThenSelectionTool, SelectionToolBDDTest) to express key user stories and scenarios (clicking figures/handles/empty area, disabled view, alt-select-behind) in Given/When/Then form. Include TestableSelectionTool helper classes that expose protected SelectionTool methods for testing.
Extract selection hit-test logic into smaller helpers and clarify select-behind behavior. The method findTargetFigure now routes to isSelectBehindModifierHeld(evt) and delegates to findFigureBehindCurrentSelection(...) or findFigureAtPoint(...). Added isSelectBehindModifierHeld, findFigureBehindCurrentSelection, and findFigureAtPoint to improve readability and separate concerns; preserved original search order and select-behind semantics (ALT/CTRL modifier) and retained compatibility notes with other trackers.
- Add Labs/ portfolio write-ups for the Selection Tool feature:
  concept location, user story, impact analysis, refactoring,
  actualization (SOLID / Clean Architecture), unit testing and BDD.
- Add US2 BDD scenario: clicking an empty area clears the current selection.
- Enable assertions in surefire so the invariant assert checks actually run.
- Remove the unused assertj-swing-junit test dependency.
@AltanEsmer AltanEsmer self-assigned this Jun 4, 2026
@AltanEsmer AltanEsmer added documentation Improvements or additions to documentation refactoring labels Jun 4, 2026
jgiven-junit 1.3.1 is compiled for Java 11 (class-file major version 55)
and cannot be loaded by the JDK 8 build, which broke testCompile. 0.18.2
is the last Java 7/8-compatible release and keeps the same ScenarioTest /
Stage / scenario-state API the BDD scenarios use.
The surefire --add-opens options are Java 9+ only; on the JDK 8 CI they
crash the forked test VM ("Could not create the Java Virtual Machine").
Move them into a profile activated on JDK [9,) so JDK 8 runs the tests
without them (no module system, so they aren't needed there) while local
newer-JDK runs still get them for Mockito.
@AltanEsmer AltanEsmer changed the title Selection Tool: refactor, tests and lab portfolio altan/develop: Selection Tool: refactor, tests and lab portfolio Jun 11, 2026
@phomarkon

Copy link
Copy Markdown
Collaborator

lgtm. please fix the merge conflict and we can then request review again. ty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants