---

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

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

## 1. Role

### PetTypeFormatterTests.shouldThrowParseException()

This test verifies the failure path of the pet type formatting workflow used by the owner-facing pet registration flow. It confirms that when the formatter is asked to interpret a pet type name that is not present in the available pet type catalog, the formatter does not silently accept the value and instead raises a `ParseException`. In business terms, this protects the application from persisting or processing an invalid pet type selection that does not exist in the master list.

The method acts as a negative test case for the lookup-and-parse behavior of `PetTypeFormatter`. It first prepares a controlled reference list of valid pet types, then exercises the formatter with the unsupported input value `"Fish"`. The test follows a simple arrange-assert pattern and does not branch internally; all processing is focused on proving that the parse operation rejects unknown values. Within the larger system, it provides regression coverage for the data-entry path that converts UI text into a domain `PetType` object.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["shouldThrowParseException()"])
    SETUP(["Stub types.findPetTypes() to return sample pet types"])
    CALL_PARSE(["petTypeFormatter.parse(\"Fish\", Locale.ENGLISH)"])
    ASSERT_THROW(["assertThrows(ParseException.class, lambda)"])
    END_NODE(["Test completes"])

    START --> SETUP
    SETUP --> ASSERT_THROW
    ASSERT_THROW --> CALL_PARSE
    CALL_PARSE --> END_NODE
```

## 3. Parameter Analysis

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

External state read by the method:
- `types.findPetTypes()` is stubbed to provide a controlled list of valid pet types.
- `petTypeFormatter.parse(...)` is invoked through the test subject.
- `Locale.ENGLISH` is supplied as the locale context for parsing.
- `ParseException` is the expected business error type for an unsupported pet type name.

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `types.findPetTypes()` | PetTypeFormatterTests | `PetType` reference data | Loads the available pet type master data into the formatter stub for lookup behavior |
| C | `makePetTypes()` | PetTypeFormatterTests | `PetType` reference data | Builds the in-memory sample pet type collection used to simulate valid lookup results |
| R | `petTypeFormatter.parse()` | PetTypeFormatter | `PetType` reference data | Attempts to resolve the external text value into a known pet type and reads the available catalog to do so |
| R | `Assertions.assertThrows()` | JUnit Assertions | `ParseException` | Verifies that the formatter rejects an unknown pet type value by raising the expected parsing error |

## 5. Dependency Trace

Trace who calls this method and what this method ultimately calls.

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

## 6. Per-Branch Detail Blocks

**Block 1** — [TRY] `(assertThrows(ParseException.class, lambda))` (L71-L74)

> Verifies that the formatter rejects an unknown pet type value and surfaces a parse error.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `given(types.findPetTypes()).willReturn(makePetTypes());` // prepare the allowed pet type catalog |
| 2 | CALL | `makePetTypes();` // build sample pet types for lookup |
| 3 | CALL | `Assertions.assertThrows(ParseException.class, () -> { petTypeFormatter.parse("Fish", Locale.ENGLISH); });` // execute the parse attempt and assert failure |
| 4 | CALL | `petTypeFormatter.parse("Fish", Locale.ENGLISH);` // attempt to resolve unsupported pet type text |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `PetType` | Domain object | Master data describing a type of pet such as dog or cat |
| `petTypeFormatter` | Technical component | Formatter that converts between user-entered pet type text and the corresponding `PetType` domain object |
| `types.findPetTypes()` | Data access / lookup | Retrieves the available pet type list for formatter resolution |
| `ParseException` | Exception | Parsing failure indicating that the entered pet type text could not be matched to a valid master record |
| `Locale.ENGLISH` | Locale setting | English-language parsing context used to compare the input text with the available pet type names |
| `"Fish"` | Input value | Unsupported pet type name used to trigger the negative test path |
| `Dog` | Sample master value | Example of a valid pet type used in the in-memory reference list |
| `Cat` | Sample master value | Example of another valid pet type used in the in-memory reference list |
| `makePetTypes` | Test helper | Builds the sample `PetType` collection used by the test |
| `JUnit` | Testing framework | Assertion framework used to validate the expected exception behavior |
