/**
   * Analyzes the data file identified by the given resource name.
   *
   * @param aResourceName the name of the resource (= data file) to analyse, cannot be <code>null
   *     </code>.
   * @return the analysis results, never <code>null</code>.
   * @throws Exception in case of exceptions.
   */
  private I2CDataSet analyseDataFile(
      final String aResourceName, final int aSclIndex, final int aSdaIndex) throws Exception {
    URL resource = ResourceUtils.getResource(getClass(), aResourceName);
    AcquisitionResult container = DataTestUtils.getCapturedData(resource);
    ToolContext toolContext = DataTestUtils.createToolContext(container);

    ToolProgressListener progressListener = Mockito.mock(ToolProgressListener.class);
    AnnotationListener annotationListener = Mockito.mock(AnnotationListener.class);

    I2CAnalyserTask worker = new I2CAnalyserTask(toolContext, progressListener, annotationListener);
    worker.setLineAIndex(aSclIndex);
    worker.setLineBIndex(aSdaIndex);
    worker.setDetectSDA_SCL(false);
    worker.setReportACK(false);
    worker.setReportNACK(false);
    worker.setReportStart(false);
    worker.setReportStop(false);

    // Simulate we're running in a separate thread by directly calling the main
    // working routine...
    I2CDataSet result = worker.call();
    assertNotNull(result);

    return result;
  }
示例#2
0
  @Test
  public void recruitersAreDisplayedByName() {
    Recruiter recruiter = Recruiter.named("George");
    RecruiterDisplayer recDisplayer = Mockito.mock(RecruiterDisplayer.class);
    recruiter.displayTo(recDisplayer);

    DisplayableName name = new Name("George");
    Mockito.verify(recDisplayer).displayRecruiter(name);
  }
示例#3
0
 @Test
 public void recruiterCanPostJob() {
   Recruiter recruiter = Recruiter.named("George");
   Job developerJob = ATSJob.titled("Developer");
   JobRepository jobRepository = Mockito.mock(JobRepository.class);
   recruiter.post(developerJob).to(jobRepository);
   JobPosting posting = new JobPosting(recruiter, developerJob);
   Mockito.verify(jobRepository).add(posting);
 }
示例#4
0
  @Test
  public void recruitersCanSeeJobseekersByJobAndDate() {
    setupRepositories();
    setupActors();
    JobPosting developerPosting = recruiter.post(developerJob).to(jobRepository);
    JobPosting architectPosting = recruiter.post(architectJob).to(jobRepository);

    TimeServer timeServerOne = Mockito.mock(TimeServer.class);
    TimeServer timeServerTwo = Mockito.mock(TimeServer.class);
    Date dayOne = null;
    Date dayTwo = null;
    try {
      dayOne = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse("2013-05-01 12:30:00");
      dayTwo = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse("2013-07-04 12:30:00");
    } catch (ParseException e) {
      fail();
    }
    Mockito.when(timeServerOne.getCurrentTime()).thenReturn(dayOne);
    Mockito.when(timeServerTwo.getCurrentTime()).thenReturn(dayTwo);
    ApplicationProcessor appProcessorOne = new ApplicationProcessor(appRepo, timeServerOne);
    ApplicationProcessor appProcessorTwo = new ApplicationProcessor(appRepo, timeServerTwo);

    boolean applyStatus;

    applyStatus = jobseekerTom.applyFor(developerPosting).to(appProcessorOne);
    assertTrue(applyStatus);
    applyStatus = jobseekerHarry.applyFor(developerPosting).to(appProcessorOne);
    assertTrue(applyStatus);
    applyStatus = jobseekerTom.applyFor(architectPosting).to(appProcessorTwo);
    assertTrue(applyStatus);
    applyStatus = jobseekerDick.applyFor(architectPosting).to(appProcessorTwo);
    assertTrue(applyStatus);

    Applications appsOnDayOne = recruiter.getApplications().filterBy(dayOne).from(appRepo);

    ApplicationsDisplayer appsDisplayer = Mockito.mock(ApplicationsDisplayer.class);
    appsOnDayOne.displayTo(appsDisplayer);
    Mockito.verify(appsDisplayer)
        .displayApplications(Mockito.argThat(new SetOfTwoAppsWithDates(dayOne)));

    Applications appsOnDayTwoForArchitect =
        recruiter.getApplications().filterBy(architectPosting).filterBy(dayTwo).from(appRepo);

    appsDisplayer = Mockito.mock(ApplicationsDisplayer.class);
    appsOnDayTwoForArchitect.displayTo(appsDisplayer);
    Mockito.verify(appsDisplayer)
        .displayApplications(
            Mockito.argThat(new SetOfTwoAppsWithJobPostingsAndDates(dayTwo, architectPosting)));
  }
  @Test
  public void testLoadEventsWithDecorators() {
    UUID identifier = UUID.randomUUID();
    SpyEventPreprocessor decorator1 = new SpyEventPreprocessor();
    SpyEventPreprocessor decorator2 = new SpyEventPreprocessor();
    testSubject.setEventStreamDecorators(Arrays.asList(decorator1, decorator2));
    when(mockEventStore.readEvents("test", identifier))
        .thenReturn(
            new SimpleDomainEventStream(
                new GenericDomainEventMessage<String>(
                    identifier, (long) 1, "Mock contents", MetaData.emptyInstance()),
                new GenericDomainEventMessage<String>(
                    identifier, (long) 2, "Mock contents", MetaData.emptyInstance()),
                new GenericDomainEventMessage<String>(
                    identifier, (long) 3, "Mock contents", MetaData.emptyInstance())));
    TestAggregate aggregate = testSubject.load(identifier);
    // loading them in...
    InOrder inOrder = Mockito.inOrder(decorator1.lastSpy, decorator2.lastSpy);
    inOrder.verify(decorator2.lastSpy).next();
    inOrder.verify(decorator1.lastSpy).next();

    inOrder.verify(decorator2.lastSpy).next();
    inOrder.verify(decorator1.lastSpy).next();

    inOrder.verify(decorator2.lastSpy).next();
    inOrder.verify(decorator1.lastSpy).next();
    aggregate.apply(new StubDomainEvent());
    aggregate.apply(new StubDomainEvent());
  }
示例#6
0
  @Test
  public void recruitersCanDisplayJobsTheyPosted() {
    setupActors();
    JobRepository jobRepository = new JobRepository();

    JobPosting developerPosting = recruiter.post(developerJob).to(jobRepository);
    JobPosting architectPosting = recruiter.post(architectJob).to(jobRepository);
    JobPosting programmerPosting = recruiter.post(programmerJob).to(jobRepository);

    JobPostings jobPostings = recruiter.getPostedJobs().from(jobRepository);

    JobPostingsDisplayer postingsDisplayer = Mockito.mock(JobPostingsDisplayer.class);
    jobPostings.displayTo(postingsDisplayer);
    Mockito.verify(postingsDisplayer)
        .displayJobPostings(
            Matchers.argThat(
                new SetOfThreeJobPostings(developerPosting, architectPosting, programmerPosting)));
  }
  @Test
  public void enrollStudentTest() throws StudentException, ServiceException, PaymentException {

    Mockito.when(
            studentController.newStudent(
                "Ana Julia Costa",
                cpf,
                rg,
                date,
                email,
                address,
                phone1,
                phone2,
                "Maria Julia",
                "Julio Costa"))
        .thenReturn(studentMock);
    Mockito.when(serviceController.newService(studentMock, courses, packages, value))
        .thenReturn(serviceMock);
    Mockito.when(paymentController.newPayment(serviceMock, 1, 1, 1)).thenReturn(paymentMock);

    try {
      enrollController.enrollStudent(
          "Ana Julia Costa",
          cpf,
          rg,
          date,
          email,
          address,
          phone1,
          phone2,
          "Maria Julia",
          "Julio Costa",
          courses,
          packages,
          1,
          1,
          2,
          value);
    } catch (StudentException | ServiceException | PaymentException e) {
      fail("Should not throw this exception: " + e.getMessage());
    }
  }
  @Test
  public void testSaveEventsWithDecorators() {
    SpyEventPreprocessor decorator1 = new SpyEventPreprocessor();
    SpyEventPreprocessor decorator2 = new SpyEventPreprocessor();
    testSubject.setEventStreamDecorators(Arrays.asList(decorator1, decorator2));
    testSubject.setEventStore(
        new EventStore() {
          @Override
          public void appendEvents(String type, DomainEventStream events) {
            while (events.hasNext()) {
              events.next();
            }
          }

          @Override
          public DomainEventStream readEvents(String type, Object identifier) {
            return mockEventStore.readEvents(type, identifier);
          }
        });
    UUID identifier = UUID.randomUUID();
    when(mockEventStore.readEvents("test", identifier))
        .thenReturn(
            new SimpleDomainEventStream(
                new GenericDomainEventMessage<String>(
                    identifier, (long) 3, "Mock contents", MetaData.emptyInstance())));
    TestAggregate aggregate = testSubject.load(identifier);
    aggregate.apply(new StubDomainEvent());
    aggregate.apply(new StubDomainEvent());

    CurrentUnitOfWork.commit();

    InOrder inOrder = Mockito.inOrder(decorator1.lastSpy, decorator2.lastSpy);
    inOrder.verify(decorator1.lastSpy).next();
    inOrder.verify(decorator2.lastSpy).next();

    inOrder.verify(decorator1.lastSpy).next();
    inOrder.verify(decorator2.lastSpy).next();
  }
示例#9
0
  @Test
  public void recruitersCanSeeJobseekersByJob() {
    setupActors();
    setupRepositories();

    JobPosting developerPosting = recruiter.post(developerJob).to(jobRepository);
    JobPosting architectPosting = recruiter.post(architectJob).to(jobRepository);

    boolean applyStatus;
    applyStatus = jobseekerTom.applyFor(developerPosting).to(appProcessor);
    assertTrue(applyStatus);
    applyStatus = jobseekerHarry.applyFor(developerPosting).to(appProcessor);
    assertTrue(applyStatus);
    applyStatus = jobseekerTom.applyFor(architectPosting).to(appProcessor);
    assertTrue(applyStatus);
    applyStatus = jobseekerDick.applyFor(architectPosting).to(appProcessor);
    assertTrue(applyStatus);

    Applications developerApps =
        recruiter.getApplications().filterBy(developerPosting).from(appRepo);

    ApplicationsDisplayer appsDisplayer = Mockito.mock(ApplicationsDisplayer.class);
    developerApps.displayTo(appsDisplayer);
    Mockito.verify(appsDisplayer)
        .displayApplications(
            Mockito.argThat(new SetOfTwoAppsWithJobSeekers(jobseekerTom, jobseekerHarry)));

    Applications architectApps =
        recruiter.getApplications().filterBy(architectPosting).from(appRepo);

    appsDisplayer = Mockito.mock(ApplicationsDisplayer.class);
    architectApps.displayTo(appsDisplayer);
    Mockito.verify(appsDisplayer)
        .displayApplications(
            Mockito.argThat(new SetOfTwoAppsWithJobSeekers(jobseekerTom, jobseekerDick)));
  }
public class QuestHouseTest {

  QuestRoom mockRoom = Mockito.mock(QuestRoom.class); // A mocked QuestRoom

  // 0================================================================0
  // |                    NEW QUEST BUILDING TESTS                    |
  // 0================================================================0

  /**
   * Tests that a new QuestBuilding object will return null if you try to get its initial QuestRoom
   * object.
   */
  @Test
  public void testEmptyInitialRoom() {
    QuestHouse houseOfRooms = new QuestHouse();
    assertNull(houseOfRooms.getInitialRoom()); // Asserts that the initial room is null
  }

  /** Tests that a new QuestBuilding object will start with zero rooms. */
  @Test
  public void testZeroStartingRooms() {
    QuestHouse houseOfRooms = new QuestHouse();
    int numRooms = houseOfRooms.getNumberOfRooms();
    assertEquals(0, numRooms); // Asserts that the initial number of rooms is zero
  }

  // 0================================================================0
  // |                       INITIAL ROOM TESTS                       |
  // 0================================================================0

  /**
   * Tests that setting the initial room of a QuestBuilding object with a non-null QuestRoom object
   * will return a non-null QuestRoom object. This is not a particularly good test but it does show
   * that an initial room will be set to something other than null.
   */
  @Test
  public void testSetInitialRoom() {
    QuestHouse houseOfRooms = new QuestHouse();
    houseOfRooms.setInitialRoom(mockRoom);
    assertNotNull(houseOfRooms.getInitialRoom()); // Asserts that the initial room is not null
  }

  /**
   * Tests that incrementing the number of rooms by a specific amount will return the same amount
   * when getNumberOfRooms is called.
   */
  @Test
  public void testIncrementNumberOfRooms() {
    QuestHouse houseOfRooms = new QuestHouse();
    int numLoops = 5;
    for (int i = 0; i < numLoops; i++) {
      houseOfRooms.incrementNumberOfRooms();
    }
    assertEquals(
        numLoops,
        houseOfRooms
            .getNumberOfRooms()); // Asserts that the number of rooms returned matches the loop
                                  // amount
  }

  /** Tests that the initial QuestRoom returned is the same as the initial QuestRoom that is set. */
  @Test
  public void testSameInitialRoom() {
    QuestHouse houseOfRooms = new QuestHouse();
    houseOfRooms.setInitialRoom(mockRoom);
    assertSame(
        mockRoom, houseOfRooms.getInitialRoom()); // Asserts that the QuestRoom objects are the same
  }
}