liveBook · Manning

Audit system

As explained in Unit Testing Principles, Practices, and Patterns

A software system that records organizational visitor entries in sequential flat files.

An audit system records organizational visitor names and visit times in sequential flat text files, rolling to a new file when the current file reaches its entry limit. section 6.4

Its core workflow is:

  • Find and sort files by their numeric index. section 6.4
  • Create audit_1.txt when no audit files exist. section 6.4
  • Append to the latest file when capacity remains; otherwise create the next indexed file. section 6.4

Filesystem coupling makes direct tests slow, difficult to maintain, and hard to parallelize. A functional architecture separates file persistence from AuditManager’s decision logic and enables output-based tests. section 6.4

Testing overflow as an output

Supply FileContent values to AuditManager, add Alice’s visit, and assert a FileUpdate containing audit_3.txt and the serialized record. The test avoids mocks and filesystem setup.

How Unit Testing Principles, Practices, and Patterns covers it

How deep it goes
Explains file rotation, testability problems, mocks, and output-based refactoring, but defers persistence and domain rules beyond this workflow.
Examples
Uses indexed audit files, visitor records, overflow into audit_3.txt, FileContent, FileUpdate, mocks, and output-based tests.
What it assumes
Assumes object-oriented programming and unit-testing familiarity while making filesystem coupling and test design concrete.
What you can do after
Build it from scratch or refactor it toward separated persistence and output-based tests.
How it connects
Connects filesystem persistence, mocking, functional architecture, output-based testing, and hexagonal architecture.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Unit Testing Principles, Practices, and Patterns. The section links point to the parts of the book it draws on.