Skip to content

Add test coverage for single-table-inheritance pattern#3468

Open
rranjangupta wants to merge 4 commits intoiluwatar:masterfrom
rranjangupta:add-single-table-inheritance-tests
Open

Add test coverage for single-table-inheritance pattern#3468
rranjangupta wants to merge 4 commits intoiluwatar:masterfrom
rranjangupta:add-single-table-inheritance-tests

Conversation

@rranjangupta
Copy link
Copy Markdown

Pull Request Template

What does this PR do?

Adds test coverage for the single-table-inheritance pattern module.

  • Add SingleTableInheritanceTest.java for testing the main application entry point
  • Add VehicleServiceTest.java with comprehensive CRUD operation tests for Vehicle entities

Test Run:
Screenshot 2026-04-21 at 9 25 31 PM

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 21, 2026

PR Summary

Adds test coverage for the single-table-inheritance module, including a smoke test for the main application and comprehensive CRUD tests for Vehicle entities across STI subtypes.

Changes

File Summary
single-table-inheritance/src/test/java/com/iluwatar/SingleTableInheritanceTest.java Introduced a minimal test ensuring the SingleTableInheritance app runs without throwing exceptions by invoking the main method with no arguments.
single-table-inheritance/src/test/java/com/iluwatar/service/VehicleServiceTest.java Introduced Spring Boot-based tests for VehicleService, covering CRUD operations for Car, Truck, Train and Freighter, verifying persistence, retrieval, updates and deletion via STI mapping.

autogenerated by presubmit.ai

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

🚨 Pull request needs attention.

Review Summary

Commits Considered (1)
Files Processed (2)
  • single-table-inheritance/src/test/java/com/iluwatar/SingleTableInheritanceTest.java (1 hunk)
  • single-table-inheritance/src/test/java/com/iluwatar/service/VehicleServiceTest.java (1 hunk)
Actionable Comments (1)
  • single-table-inheritance/src/test/java/com/iluwatar/service/VehicleServiceTest.java [112-112]

    possible_bug: "Floating-point comparison should include a delta"

Skipped Comments (1)
  • single-table-inheritance/src/test/java/com/iluwatar/service/VehicleServiceTest.java [73-79]

    maintainability: "Null-safe cleanup in tearDown"

void saveVehicle_shouldPersistFreighterWithCorrectType() {
assertTrue(savedFreighter.getVehicleId() > 0);
assertInstanceOf(Freighter.class, savedFreighter);
assertEquals(8130.0, ((Freighter) savedFreighter).getFlightLength());
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Floating-point comparisons should specify a delta to account for precision. Use a tolerance when asserting double values.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

🚨 Pull request needs attention.

Review Summary

Commits Considered (1)
  • 3fdda66: test: add delta for floating-point comparison in VehicleServiceTest
Files Processed (1)
  • single-table-inheritance/src/test/java/com/iluwatar/service/VehicleServiceTest.java (1 hunk)
Actionable Comments (1)
  • single-table-inheritance/src/test/java/com/iluwatar/service/VehicleServiceTest.java [74-80]

    possible bug: "Null-safety in teardown"

Skipped Comments (0)

Comment on lines +74 to +80
@AfterEach
void tearDown() {
vehicleService.deleteVehicle(savedCar);
vehicleService.deleteVehicle(savedTruck);
vehicleService.deleteVehicle(savedTrain);
vehicleService.deleteVehicle(savedFreighter);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Guard teardown against nulls: saved* references may be null if setup failed, which would cause a NullPointerException during cleanup. Add null checks before deleting.

@rranjangupta rranjangupta deleted the add-single-table-inheritance-tests branch April 21, 2026 16:06
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

LGTM!

Review Summary

Commits Considered (1)
  • 1b2d598: fix: guard teardown against nulls and use assertNotNull in VehicleServiceTest

Add null checks in @AfterEach tearDown() to prevent NullPointerException
if setUp() partially fails. Replace assertTrue(x != null) with assertNotNull(x).

Co-Authored-By: Claude Sonnet 4.6 [email protected]

Files Processed (1)
  • single-table-inheritance/src/test/java/com/iluwatar/service/VehicleServiceTest.java (1 hunk)
Actionable Comments (0)
Skipped Comments (4)
  • single-table-inheritance/src/test/java/com/iluwatar/service/VehicleServiceTest.java [57-57]

    maintainability: "Ensure injected dependency is non-null"

  • single-table-inheritance/src/test/java/com/iluwatar/service/VehicleServiceTest.java [136-144]

    possible bug: "Potential flakiness in getAllVehicles test"

  • single-table-inheritance/src/test/java/com/iluwatar/service/VehicleServiceTest.java [75-81]

    maintainability: "Teardown is null-safe; consider per-deletion isolation"

  • single-table-inheritance/src/test/java/com/iluwatar/service/VehicleServiceTest.java [129-132]

    best-practice: "Use a guaranteed non-existent ID for negative test"

@rranjangupta rranjangupta restored the add-single-table-inheritance-tests branch April 21, 2026 16:24
@rranjangupta rranjangupta reopened this Apr 21, 2026
…viceTest

Add null checks in @AfterEach tearDown() to prevent NullPointerException
if setUp() partially fails. Replace assertTrue(x != null) with assertNotNull(x).
@rranjangupta rranjangupta force-pushed the add-single-table-inheritance-tests branch from 1b2d598 to 0476a66 Compare April 21, 2026 17:02
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

LGTM!

Review Summary

Commits Considered (1)
  • 0476a66: fix: guard teardown against nulls and use assertNotNull in VehicleServiceTest

Add null checks in @AfterEach tearDown() to prevent NullPointerException
if setUp() partially fails. Replace assertTrue(x != null) with assertNotNull(x).

Files Processed (1)
  • single-table-inheritance/src/test/java/com/iluwatar/service/VehicleServiceTest.java (1 hunk)
Actionable Comments (0)
Skipped Comments (2)
  • single-table-inheritance/src/test/java/com/iluwatar/service/VehicleServiceTest.java [136-145]

    readability: "Verify presence of all STI subtypes in bulk retrieval"

  • single-table-inheritance/src/test/java/com/iluwatar/service/VehicleServiceTest.java [161-170]

    readability: "Enhance deletion test coverage for non-existent or removed entities"

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

LGTM!

Review Summary

Commits Considered (1)
  • 5c78862: style: format code in SingleTableInheritanceTest and VehicleServiceTest for consistency
Files Processed (2)
  • single-table-inheritance/src/test/java/com/iluwatar/SingleTableInheritanceTest.java (1 hunk)
  • single-table-inheritance/src/test/java/com/iluwatar/service/VehicleServiceTest.java (1 hunk)
Actionable Comments (0)
Skipped Comments (0)

@sonarqubecloud
Copy link
Copy Markdown

@rranjangupta
Copy link
Copy Markdown
Author

@iluwatar Can we please merge this?

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.

1 participant