Create ShapeContractTest (parameterized) #8

Closed
opened 2026-03-27 15:01:20 +00:00 by thib8956 · 1 comment
Owner

Priority: P0 — High

Context: A testing audit identified these issues in the existing test suite:

  • Shallow coverage — most shape tests only verify creation and bounds
  • No contract tests — Shape interface has no tests verifying invariants across implementations
  • Inconsistent clone testing — some tests verify deep copy, others do not

A parameterized contract test would catch violations across all Shape implementations at once.

Scope: All Shape implementations (SRectangle, SCircle, STriangle, SText, SCollection)

Goal: Verify Shape interface invariants across all implementations using @ParameterizedTest + @MethodSource:

  • clone() returns independent copy
  • getBounds() returns a copy (not internal state)
  • translate() mutates in place

Recommended pattern:

class ShapeContractTest {
    @ParameterizedTest
    @MethodSource("ovh.gasser.newshapes.shapes.ShapeFactory#allShapes")
    void testCloneIsIndependent(Shape s) { ... }

    @ParameterizedTest
    @MethodSource("ovh.gasser.newshapes.shapes.ShapeFactory#allShapes")
    void testGetBoundsReturnsCopy(Shape s) { ... }

    @ParameterizedTest
    @MethodSource("ovh.gasser.newshapes.shapes.ShapeFactory#allShapes")
    void testTranslateMutatesInPlace(Shape s) { ... }
}

Estimate: 2 hours
Dependencies: None

**Priority:** P0 — High **Context:** A testing audit identified these issues in the existing test suite: - **Shallow coverage** — most shape tests only verify creation and bounds - **No contract tests** — Shape interface has no tests verifying invariants across implementations - **Inconsistent clone testing** — some tests verify deep copy, others do not A parameterized contract test would catch violations across all Shape implementations at once. **Scope:** All Shape implementations (SRectangle, SCircle, STriangle, SText, SCollection) **Goal:** Verify Shape interface invariants across all implementations using `@ParameterizedTest` + `@MethodSource`: - `clone()` returns independent copy - `getBounds()` returns a copy (not internal state) - `translate()` mutates in place **Recommended pattern:** ```java class ShapeContractTest { @ParameterizedTest @MethodSource("ovh.gasser.newshapes.shapes.ShapeFactory#allShapes") void testCloneIsIndependent(Shape s) { ... } @ParameterizedTest @MethodSource("ovh.gasser.newshapes.shapes.ShapeFactory#allShapes") void testGetBoundsReturnsCopy(Shape s) { ... } @ParameterizedTest @MethodSource("ovh.gasser.newshapes.shapes.ShapeFactory#allShapes") void testTranslateMutatesInPlace(Shape s) { ... } } ``` **Estimate:** 2 hours **Dependencies:** None
Author
Owner

Work in progress on branch issue-8/shape-contract-test. Commit 2ff811e adds parameterized contract tests for clone(), getBounds(), and translate() across all Shape implementations. All 15 new tests pass.

Work in progress on branch `issue-8/shape-contract-test`. Commit 2ff811e adds parameterized contract tests for clone(), getBounds(), and translate() across all Shape implementations. All 15 new tests pass.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: thib8956/new-shapes#8