### Question:
Processor { public Direction next(Board board) { if (board.isMyBombermanDead()) { return Direction.STOP; } if (commands.isEmpty()) { rules = new Rules(); reader.load(rules, rulesFile); if (reader.hasErrors()) { reader.errors().forEach(console); reader.cleanErrors(); } commands.addAll(rules.process(board)); } return commands.removeFirst(); } Processor(String rulesPlace, Dice dice, Consumer<ErrorMessage> console); Direction next(Board board);  }### Answer:
@Test public void shouldStop_whenBombermanDie() { when(board.isMyBombermanDead()).thenReturn(true); Direction direction = processor.next(board); assertEquals(Direction.STOP, direction); assertEquals("[]", errors.toString()); }
@Test public void shouldSeveralDirections_whenOneRule() { cleanLns(); loadLns(" ", " ", " ", "RIGHT,LEFT,DOWN,UP,UP,LEFT"); when(board.isNearMe(any(Pattern.class))).thenReturn(true); assertEquals(Direction.RIGHT, processor.next(board)); assertEquals(Direction.LEFT, processor.next(board)); assertEquals(Direction.DOWN, processor.next(board)); assertEquals(Direction.UP, processor.next(board)); assertEquals(Direction.UP, processor.next(board)); assertEquals(Direction.LEFT, processor.next(board)); assertEquals("[]", errors.toString()); }
@Test public void shouldGetErrors_whenbadRule() { loadLns(" ", " ", " ", "BAD RULE"); when(board.isNearMe(any(Pattern.class))).thenReturn(true); Direction direction = processor.next(board); assertEquals(Direction.STOP, direction); assertEquals("[[ERROR] Pattern is not valid: ' BAD RULE' at " + SEP + "main.rule:5]", errors.toString()); }
@Test public void shouldLoadRules_whenRuleDirective() { loadLns("?☼?", "?☺?", "???", "DOWN", "", "????????", "????????", "????????", "☺", "????????", "????????", "????????", "RULE right", "", "???", "☼☺☼", "?#?", "LEFT"); loadLns("?☼?", "?☺ ", "?☼?", "RIGHT", "", "?☼?", "?☺ ", "?#?", "DOWN", "", "?#?", "?☺ ", "?☼?", "UP", "", "?#?", "?☺ ", "?#?", "LEFT"); Pattern pattern = new Pattern("?#??☺ ?☼?", null); when(board.isNearMe(eq(pattern))).thenReturn(true); Direction direction = processor.next(board); assertEquals(Direction.UP, direction); assertEquals("[]", reader.errors().toString()); }