/** Test of analyse method, of class AuditServiceThreadImpl. */
  public void testAnalyse() {
    System.out.println("analyse");

    AuditCommand mockAuditCommand = createMock(AuditCommand.class);
    mockAuditCommand.analyse();
    expectLastCall().once();
    replay(mockAuditCommand);

    AuditServiceThreadImpl instance = initialiseAuditServiceThread(mockAuditCommand);
    instance.analyse();

    verify(mockAuditCommand);
  }
  /** Test of getAudit method, of class AuditServiceThreadImpl. */
  public void testGetAudit() {
    System.out.println("getAudit");

    Audit audit = createMock(Audit.class);
    Audit auditReturnedByAuditCommand = createMock(Audit.class);
    AuditCommand mockAuditCommand = createMock(AuditCommand.class);
    expect(mockAuditCommand.getAudit()).andReturn(auditReturnedByAuditCommand);
    replay(mockAuditCommand);

    AuditServiceThreadImpl instance = initialiseAuditServiceThread(audit);
    assertEquals(audit, instance.getAudit());

    instance = initialiseAuditServiceThread(mockAuditCommand);
    assertEquals(auditReturnedByAuditCommand, instance.getAudit());
  }
  /** Test of run method, of class AuditServiceThreadImpl. */
  public void testRun() {
    System.out.println("run");

    Audit mockAudit = createMock(Audit.class);
    expect(mockAudit.getId()).andReturn(1l).anyTimes();

    AuditCommand mockAuditCommand = createMock(AuditCommand.class);
    mockAuditCommand.init();
    expectLastCall().once();
    mockAuditCommand.loadContent();
    expectLastCall().once();
    mockAuditCommand.adaptContent();
    expectLastCall().once();
    mockAuditCommand.process();
    expectLastCall().once();
    mockAuditCommand.consolidate();
    expectLastCall().once();
    mockAuditCommand.analyse();
    expectLastCall().once();
    expect(mockAuditCommand.getAudit()).andReturn(mockAudit).anyTimes();

    replay(mockAudit);
    replay(mockAuditCommand);

    AuditServiceThreadImpl instance = initialiseAuditServiceThread(mockAuditCommand);

    AuditServiceThreadListener auditServiceThreadListener =
        createMock(AuditServiceThreadListener.class);
    auditServiceThreadListener.auditCompleted(instance);
    expectLastCall().once();
    replay(auditServiceThreadListener);

    instance.add(auditServiceThreadListener);
    instance.run();

    verify(mockAudit);
    verify(mockAuditCommand);
    verify(auditServiceThreadListener);
  }
  /** Test of add/remove AuditServiceListener method of class AuditServiceImpl. */
  public void testAddAndRemove() {

    Audit audit = createMock(Audit.class);

    AuditServiceThreadImpl instance = initialiseAuditServiceThread(audit);

    AuditServiceThreadListener mockAuditServiceThreadListener =
        createMock(AuditServiceThreadListener.class);
    // when try to remove a listener not recorded, nothing happened
    instance.remove(mockAuditServiceThreadListener);

    instance.add(mockAuditServiceThreadListener);
    assertTrue(instance.getListeners().contains(mockAuditServiceThreadListener));
    instance.remove(mockAuditServiceThreadListener);
    assertTrue(instance.getListeners().isEmpty());
  }