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

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

## 1. Role

### PetTypeFormatterTests.shouldThrowParseException()

This test method validates the negative-path behavior of the pet type formatter when a requested pet type name cannot be resolved from the available reference data. In business terms, it simulates a user entering or selecting an unsupported pet type value and verifies that the formatter rejects that value instead of silently accepting an invalid master record. The method uses a mocked `PetTypeRepository` to provide a controlled set of valid pet types, then exercises the formatter with the invalid input `"Fish"` to confirm that parsing fails as expected. This is a quality gate for the mapping between user-facing pet type text and the system's canonical pet type master data.

The method is part of a formatter test suite, so its role in the larger system is to protect the conversion contract used by form binding and request handling. It applies a simple arrange-act-assert pattern: arrange the repository data, act by parsing an invalid token, and assert that a `ParseException` is raised. There are no business branches inside the test itself, but the scenario specifically covers the error branch of the formatter's lookup logic: valid reference data exists, but the requested value does not match any allowed pet type name.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["shouldThrowParseException()"])
    MOCK(["Stub PetTypeRepository.findPetTypes() to return sample pet types"])
    PARSE_CALL(["Call petTypeFormatter.parse('Fish', Locale.ENGLISH)"])
    PARSE(["PetTypeFormatter.parse() attempts to resolve the pet type name"])
    THROW(["No matching PetType found - ParseException is thrown"])
    ASSERT(["Assertions.assertThrows(ParseException.class, ...)"])
    END_NODE(["Test completes"])

    START --> MOCK
    MOCK --> ASSERT
    ASSERT --> PARSE_CALL
    PARSE_CALL --> PARSE
    PARSE --> THROW
    THROW --> END_NODE
```

## 3. Parameter Analysis

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

External state read by the method:
- `types` - mocked pet type reference repository used to supply valid master data during the test
- `petTypeFormatter` - formatter under test, created in `setup()`
- `Locale.ENGLISH` - locale context used by the formatter during parsing

## 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` |

Analyze all method calls within this method and classify each as a CRUD operation.
Use the pre-computed evidence above. If SC Code or Entity/DB is missing, try to infer from:
- The **SC Code** (Service Component code, e.g., `EKK0361A010SC`, `EKK1081D010CBS`) — look at the class name of the called method or its containing class.
- The **Entity/DB tables** — search for table name constants (often `KK_T_*` pattern), SQL references, or entity names in the called method's source code.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `PetTypeRepository.findPetTypes` | PetTypeRepository | PetType master collection | Reads the available pet types that define the valid lookup domain for formatter parsing |
| R | `PetTypeFormatter.parse` | PetTypeFormatter | PetType master collection | Attempts to resolve the submitted text value to an existing `PetType` reference |
| - | `Assertions.assertThrows` | JUnit assertion | - | Verifies that the negative-path parse operation raises `ParseException` |
| - | `PetTypeFormatterTests.makePetTypes` | PetTypeFormatterTests | - | Builds in-memory sample pet types for test setup |

## 5. Dependency Trace

Trace who calls this method and what this method ultimately calls. The caller search returned no direct Java callers in the repository, which is consistent with a JUnit test method executed by the test runner rather than invoked from application code.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Test Runner / JUnit 5 | `JUnitPlatform` -> `PetTypeFormatterTests.shouldThrowParseException` | `PetTypeFormatter.parse [R] PetType master collection` |

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] `(test setup)` (L70-L71)

> Arrange the repository state so the formatter sees a controlled list of valid pet types.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `makePetTypes()` |
| 2 | EXEC | `given(types.findPetTypes()).willReturn(makePetTypes());` // stub repository lookup |

**Block 2** — [CALL] `(assert negative parse outcome)` (L72-L75)

> Execute the formatter with an invalid pet type label and verify that parsing is rejected.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `Assertions.assertThrows(ParseException.class, () -> { ... })` |
| 2 | CALL | `petTypeFormatter.parse("Fish", Locale.ENGLISH);` |
| 3 | RETURN | `ParseException is expected` |

**Block 3** — [RETURN] `(test completion)` (L76)

> The test ends after the exception assertion completes.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `void` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `PetType` | Domain object | Master data record representing a supported pet category such as Dog or Bird |
| `PetTypeRepository` | Repository | Data access component that provides the list of valid pet types |
| `PetTypeFormatter` | Utility / Formatter | Converts between the text shown in forms and the underlying `PetType` domain object |
| `ParseException` | Technical exception | Signals that the submitted text cannot be mapped to a valid pet type |
| `Locale.ENGLISH` | Locale | English-language formatting and lookup context used during text-to-object conversion |
| `assertThrows` | Test assertion | Verifies that an operation fails with the expected exception type |
| `given(...).willReturn(...)` | Test stubbing | Configures the mock repository to return predefined sample master data |
| `makePetTypes` | Test helper | Builds in-memory pet type samples `Dog` and `Bird` for formatter testing |
| `Pet type master data` | Business term | The approved list of pet categories recognized by the application |
| `Formatter parse` | Technical process | Conversion from a submitted form value into a domain object instance |
