# io.github.libtmux.junit5.FakeTmux.FakeTmux

- **Module:** io.github.libtmux.junit5.FakeTmux
- **Package:** io.github.libtmux:libtmux
- **Language:** Java
- **Kind:** class
- **Source:** https://github.com/libtmux/libtmux-java/blob/842228310449e879ebcaa3f910597757c9dbffd6/libtmux-junit5/src/main/java/io/github/libtmux/junit5/FakeTmux.java#L50
- **Page:** https://libtmux.org/en/java/latest/reference/io-github-libtmux-junit5-faketmux-faketmux/

A tmux server that is not there, for testing code that uses this library without starting one.

It answers the way tmux answers, not the way a stub would: a listing is rendered from the
template the library sends, so a snapshot of a fake server is a real snapshot and every handle
works; a handle command is fenced on the server's identity and refused once the fake is replaced,
as tmux refuses it; a group stops at its first failure. What it models is the hierarchy —
sessions, windows, panes and their names and titles — and what each pane shows. What it does not
model is a shell: keys sent to a pane are recorded, not run, and a pane shows what the test says.

For behaviour that depends on tmux itself — what a release does with a flag, how a real shell
echoes — test against real tmux with {@link TmuxExtension} instead. This is for code whose
interest in tmux ends at the calls it makes.

## Example

```java
FakeTmux tmux = new FakeTmux();
PaneId editor = tmux.addSession("work");
tmux.show(editor, "$ make", "make: Nothing to be done for 'all'.");

try (Server server = tmux.server()) {
Pane pane = server.pane(editor).orElseThrow();
pane.capture();                 // → [$ make, make: Nothing to be done for 'all'.]
pane.sendLine("make test");
}

tmux.sent();                        // every command, as the library sent it
```

## Members

- `FakeTmux` (method): A fake server with no sessions, as tmux is before anything has been created.
- `server` (method): A server this transport answers for.
- `addSession` (method): Adds a session with one window and one pane running {@code sh}, as {@code new-session} makes.
- `restart` (method): Replaces the server, as a restart does: a new process, and nothing in it.
- `show` (method): What the pane shows, one element per line, which is what capturing it answers.
- `sent` (method): Every command the library sent, in order, each as the words tmux would have read.
- `sessions` (method): The sessions the fake holds now, by id.
- `execute` (method)
- `close` (method)
- `Groups` (class): Reads a command group the way tmux's command parser reads it: words in single quotes, a quote spelled {@code '\''}, a line break spelled {@code "\n"}, commands separated by {@code ;}.
- `Formats` (class): The part of tmux's format language the library sends: variables, {@code ==} and {@code &&}.
