---
# (DD47) Business Logic — PetTypeFormatterTests.shouldThrowParseException() [7 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `org.springframework.samples.petclinic.owner.PetTypeFormatterTests` |
| Layer | Utility |
| Module | `owner` (Package: `org.springframework.samples.petclinic.owner`) |

## 1. Role

### PetTypeFormatterTests.shouldThrowParseException()

This test method verifies the negative business behavior of the `PetTypeFormatter` lookup flow when the requested pet type name does not exist in the available reference data. It prepares a controlled list of valid pet types through the repository mock, then invokes the formatter with the invalid business value `"Fish"` to confirm that the formatter rejects unmapped input by raising a `ParseException`.

From a domain perspective, this method protects the pet registration and maintenance workflow from accepting unsupported pet type labels. It exercises the formatter's data-matching responsibility rather than persistence or UI rendering, and it specifically validates the failure path of a read-only reference-data translation pattern. The method has no business branching of its own; instead, it asserts that the formatter's parsing branch cannot resolve the supplied input against the available pet type catalog and therefore terminates with an exception.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["shouldThrowParseException()"])
    STEP1["Stub PetTypeRepository.findPetTypes() with sample pet types"]
    STEP2["Create assertion that ParseException is expected"]
    STEP3["Invoke PetTypeFormatter.parse(\"Fish\", Locale.ENGLISH)"]
    STEP4["Formatter searches reference pet types for matching name"]
    STEP5{"Does 'Fish' match an available pet type?"}
    STEP6["No match found - raise ParseException"]
    END_NODE(["Test completes after exception assertion passes"])

    START --> STEP1
    STEP1 --> STEP2
    STEP2 --> STEP3
    STEP3 --> STEP4
    STEP4 --> STEP5
    STEP5 -- "No" --> STEP6
    STEP6 --> END_NODE
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | - |

External state used by this method:
- `types` - mocked `PetTypeRepository` used to supply reference pet type records to the formatter.
- `petTypeFormatter` - formatter instance under test, created in `setup()`.
- `Locale.ENGLISH` - locale context used to simulate the UI language for parsing.
- `makePetTypes()` - local test helper that provides the valid reference pet type list (`Dog`, `Bird`).

## 4. CRUD Operations / Called Services

### Pre-computed evidence from code analysis graph:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `PetTypeFormatterTests.makePetTypes` | PetTypeFormatterTests | - | Calls `makePetTypes` in `PetTypeFormatterTests` |

The method itself does not perform direct CRUD against a database. It executes a read-oriented test setup and assertion flow around a formatter call, with the only executable dependency being the local helper method that assembles sample reference data.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `makePetTypes` | PetTypeFormatterTests | `PetType` (test fixture only) | Builds in-memory reference data used to simulate the pet type catalog |
| R | `types.findPetTypes()` | PetTypeRepository | `PetType` | Reads the available pet type master records for formatter lookup |
| R | `petTypeFormatter.parse()` | PetTypeFormatter | `PetType` | Resolves an input label against the reference list and fails when no match exists |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Test: `PetTypeFormatterTests` | `PetTypeFormatterTests.shouldThrowParseException` | `petTypeFormatter.parse [R] PetType` |

This method is only invoked by the local JUnit test class and has no production callers. Its downstream dependency path is limited to the formatter parse operation and the mock repository lookup used to supply the candidate pet types.

## 6. Per-Branch Detail Blocks

**Block 1** — [TRY] `(assertThrows ParseException expectation)` (L73)

> Verifies the negative parsing path and confirms that invalid reference-data input is rejected.

| # | Type | Code |
|---|------|------|
| 1 | SET | `given(types.findPetTypes()).willReturn(makePetTypes());` // Stub the reference-data source with valid pet types |
| 2 | CALL | `makePetTypes();` // Build the in-memory sample pet type catalog |
| 3 | EXEC | `Assertions.assertThrows(ParseException.class, () -> { ... });` // Expect the formatter to fail for unmatched input |
| 4 | CALL | `petTypeFormatter.parse("Fish", Locale.ENGLISH);` // Attempt to resolve an unsupported pet type name |

**Block 1.1** — [CALL inside assertion lambda] `(petTypeFormatter.parse("Fish", Locale.ENGLISH))` (L74)

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `petTypeFormatter.parse("Fish", Locale.ENGLISH);` // Search the available pet types for a matching business label |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `PetType` | Domain entity | Reference master record describing a category of pet, such as Dog or Bird |
| `PetTypeRepository` | Repository | Data access component that provides the available pet type master list |
| `Formatter` | Technical term | Spring component that converts between display text and domain objects |
| `parse` | Technical term | Conversion operation that resolves a text label into a domain object |
| `ParseException` | Technical term | Error raised when text cannot be matched to a valid domain value |
| `Locale.ENGLISH` | Technical term | English-language formatting context used during parsing |
| `Fish` | Business value | Invalid pet type label used to verify the rejection path |
| `Dog` | Business value | Valid sample pet type in the test fixture |
| `Bird` | Business value | Valid sample pet type in the test fixture |
| `types` | Field | Mocked repository reference that supplies the pet type master list |
| `petTypeFormatter` | Field | Formatter instance under test that performs the name-to-object conversion |
| `makePetTypes()` | Helper method | Test-only builder that creates sample reference pet types in memory |
| `assertThrows` | Testing API | Assertion that verifies an exception is raised for invalid input |
| `BDDMockito.given` | Testing API | Mock setup that defines repository return behavior |
