### Question:
TicketRegistryDecorator extends AbstractTicketRegistry { @Override public void addTicket(final Ticket ticket) { if (ticket instanceof TicketGrantingTicket) { final TicketGrantingTicket ticketGrantingTicket = (TicketGrantingTicket) ticket; final String ticketId = ticketGrantingTicket.getId(); final String userName = ticketGrantingTicket.getAuthentication().getPrincipal().getId().toLowerCase(); logger.debug("Creating mapping ticket {} to user name {}", ticketId, userName); this.cache.put(ticketId, userName); } this.ticketRegistry.addTicket(ticket); } TicketRegistryDecorator(final TicketRegistry actualTicketRegistry, final Map<String, String> cache); @Override void addTicket(final Ticket ticket); @Override Ticket getTicket(final String ticketId); @Override boolean deleteTicket(final String ticketId); @Override Collection<Ticket> getTickets(); @Override int sessionCount(); @Override int serviceTicketCount();  }### Answer:
@Test public void addTicketWithTGT() { when(tgt.getId()).thenReturn("TGT-123"); Authentication authentication = mock(Authentication.class); Principal principal = mock(Principal.class); when(authentication.getPrincipal()).thenReturn(principal); when(principal.getId()).thenReturn("username"); when(tgt.getAuthentication()).thenReturn(authentication); decorator.addTicket(tgt); verify(registry).addTicket(tgt); assertEquals("username", cache.get("TGT-123")); }
@Test public void addTicketWithNonTGT() { decorator.addTicket(ticket); verify(registry).addTicket(ticket); }