---

# (DD47) Business Logic — PetTypeFormatterTests.testPrint() [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.testPrint()

This test method validates the display-formatting behavior for a `PetType` domain object by checking that the formatter returns the type name exactly as it is stored in the object. In business terms, it verifies the presentation contract for pet category labels such as a hamster, dog, or cat so that the user interface can render the selected pet type without adding extra formatting or transformation rules. The method covers a single happy-path case: a `PetType` instance with a non-null name. It uses a straightforward arrange-act-assert pattern, where the fixture is created, the business name is assigned, the formatter is invoked, and the resulting text is compared with the expected display value. Because this is a test method, its role in the larger system is quality assurance for Spring MVC formatting rather than production data handling. It does not branch on business rules or manage multiple service types; instead, it proves that the formatter preserves the business label unchanged.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["testPrint()"])
    CREATE["Create new PetType test fixture"]
    SET_NAME["Set petType.name = \"Hamster\""]
    CALL_PRINT["Call petTypeFormatter.print(petType, Locale.ENGLISH)"]
    ASSERT["Assert returned value equals \"Hamster\""]
    END_NODE(["End"])

    START --> CREATE
    CREATE --> SET_NAME
    SET_NAME --> CALL_PRINT
    CALL_PRINT --> ASSERT
    ASSERT --> END_NODE
```

## 3. Parameter Analysis

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

External state read by the method:
- `this.petTypeFormatter` — formatter under test, injected by the test fixture.
- `Locale.ENGLISH` — locale argument used to satisfy the formatter contract.
- `PetType.name` — business display label for the pet category.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `PetTypeFormatter.print` | - | `PetType` | Reads the pet type name and returns it for UI display without modifying persisted data. |

## 5. Dependency Trace

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

## 6. Per-Branch Detail Blocks

**Block 1** — [SEQUENCE] (L55-L61)

> This block covers the complete single-path test flow.

| # | Type | Code |
|---|------|------|
| 1 | SET | `PetType petType = new PetType();` |
| 2 | EXEC | `petType.setName("Hamster");` |
| 3 | CALL | `this.petTypeFormatter.print(petType, Locale.ENGLISH);` |
| 4 | SET | `String petTypeName = ...;` |
| 5 | CALL | `assertThat(petTypeName).isEqualTo("Hamster");` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `PetType` | Domain entity | Pet category master record used to classify animals in the clinic, such as hamster, dog, or cat. |
| `name` | Field | Human-readable pet type label displayed in the user interface. |
| `Formatter` | Technical term | Spring MVC contract that converts between domain objects and text shown in forms and views. |
| `Locale` | Technical term | Language and regional context supplied to formatting logic. |
| `Hamster` | Business term | Sample pet type value used as the expected display label in this test. |
| `print` | Technical term | Formatting operation that converts a domain object into a display string. |
