public Transformer build() {
    Transformer transformer;
    if (name == null || name.isEmpty()) {

      transformer = mock(getClassToMock());
    } else {
      transformer = mock(getClassToMock(), name);
      doReturn(name).when(transformer).getName();
    }

    if (resultDataType != null) {
      doReturn(resultDataType).when(transformer).getReturnDataType();
    }
    if (sourceDataTypes != null) {
      doReturn(Arrays.asList(sourceDataTypes)).when(transformer).getSourceDataTypes();

      when(transformer.isSourceDataTypeSupported(
              Matchers.<DataType<?>>argThat(new SupportsSourceDataType())))
          .thenReturn(true);
    }
    try {
      doReturn(value).when(transformer).transform(Mockito.any(Object.class));
    } catch (TransformerException e) {
      // Not going to happen during mock setup
    }

    return transformer;
  }
  @Test
  public void handleSellTransactionCancelledEvent() {
    TransactionEntry transactionEntry = new TransactionEntry();
    transactionEntry.setIdentifier(transactionIdentifier.toString());
    transactionEntry.setAmountOfExecutedItems(0);
    transactionEntry.setPricePerItem(DEFAULT_ITEM_PRICE);
    transactionEntry.setState(STARTED);
    transactionEntry.setAmountOfItems(DEFAULT_TOTAL_ITEMS);
    transactionEntry.setCompanyName(DEFAULT_COMPANY_NAME);
    transactionEntry.setOrderbookIdentifier(orderBookIdentifier.toString());
    transactionEntry.setPortfolioIdentifier(portfolioIdentifier.toString());
    transactionEntry.setType(SELL);

    Mockito.when(transactionQueryRepository.findOne(transactionIdentifier.toString()))
        .thenReturn(transactionEntry);
    SellTransactionCancelledEvent event =
        new SellTransactionCancelledEvent(
            transactionIdentifier, DEFAULT_TOTAL_ITEMS, DEFAULT_TOTAL_ITEMS);
    listener.handleEvent(event);
    Mockito.verify(transactionQueryRepository)
        .save(
            Matchers.argThat(
                new TransactionEntryMatcher(
                    DEFAULT_TOTAL_ITEMS,
                    0,
                    DEFAULT_COMPANY_NAME,
                    DEFAULT_ITEM_PRICE,
                    CANCELLED,
                    SELL)));
  }
Пример #3
0
  @Test
  public void testNullWorld() {
    // Pull a core instance from the server.
    Plugin plugin = mockServer.getPluginManager().getPlugin("Multiverse-Core");

    // Make sure Core is not null
    assertNotNull(plugin);

    // Make sure Core is enabled
    assertTrue(plugin.isEnabled());

    // Initialize a fake command
    Command mockCommand = mock(Command.class);
    when(mockCommand.getName()).thenReturn("mv");

    // Ensure that there are no worlds imported. This is a fresh setup.
    assertEquals(0, creator.getCore().getMVWorldManager().getMVWorlds().size());

    // Create the NULL world
    // The safe check is now BALLS SLOW. Use the -n to skip checking.
    String[] normalArgs = new String[] {"create", "nullworld", "normal", "-n"};
    plugin.onCommand(mockCommandSender, mockCommand, "", normalArgs);

    // We should now have one world!
    assertEquals(1, creator.getCore().getMVWorldManager().getMVWorlds().size());

    // Verify
    verify(mockCommandSender).sendMessage("Starting creation of world 'nullworld'...");
    verify(mockCommandSender).sendMessage("Complete!");

    WorldCreatorMatcher matcher = new WorldCreatorMatcher(new WorldCreator("nullworld"));
    verify(mockServer).createWorld(Matchers.argThat(matcher));
  }
Пример #4
0
  @Test
  public void testRemoveListenerOnDisconnect() throws Exception {
    channelMgrMbean.makeChannelActive(clientId, false);
    channelMgrMbean.closeAll(Collections.singletonList(clientId));
    InOrder order = Mockito.inOrder(mbeanSvr);

    order
        .verify(mbeanSvr)
        .addNotificationListener(
            isA(ObjectName.class),
            Matchers.argThat(
                new ArgumentMatcher<NotificationListener>() {

                  @Override
                  public boolean matches(Object arg) {
                    return arg instanceof Client
                        && clientId.toLong() == (((Client) arg).getClientID());
                  }
                }),
            isA(NotificationFilter.class),
            Matchers.any());
    order
        .verify(mbeanSvr)
        .removeNotificationListener(
            isA(ObjectName.class),
            Matchers.argThat(
                new ArgumentMatcher<NotificationListener>() {

                  @Override
                  public boolean matches(Object arg) {
                    return arg instanceof Client
                        && clientId.toLong() == (((Client) arg).getClientID());
                  }
                }),
            isA(NotificationFilter.class),
            Matchers.any());
  }
Пример #5
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
  @SuppressWarnings("unchecked")
  public void should_execute() {
    Map<String, Object> properties = newHashMap();
    properties.put("tags", "tag2,tag3");

    DefaultIssue issue = mock(DefaultIssue.class);
    when(issue.tags()).thenReturn(ImmutableSet.of("tag1", "tag3"));

    Action.Context context = mock(Action.Context.class);
    when(context.issue()).thenReturn(issue);

    action.execute(properties, context);
    verify(issueUpdater)
        .setTags(
            eq(issue),
            (Collection<String>) Matchers.argThat(org.hamcrest.Matchers.containsInAnyOrder("tag1")),
            any(IssueChangeContext.class));
  }
  @Test
  public void handleSellTransactionStartedEvent() {
    SellTransactionStartedEvent event =
        new SellTransactionStartedEvent(
            transactionIdentifier,
            orderBookIdentifier,
            portfolioIdentifier,
            DEFAULT_TOTAL_ITEMS,
            DEFAULT_ITEM_PRICE);
    listener.handleEvent(event);

    Mockito.verify(transactionQueryRepository)
        .save(
            Matchers.argThat(
                new TransactionEntryMatcher(
                    DEFAULT_TOTAL_ITEMS,
                    0,
                    DEFAULT_COMPANY_NAME,
                    DEFAULT_ITEM_PRICE,
                    STARTED,
                    SELL)));
  }
Пример #8
0
  @Before
  public void setUp() throws Exception {
    // Mocks
    ServerManagementContext smCtxt =
        Mockito.mock(ServerManagementContext.class, Mockito.RETURNS_MOCKS);
    ClientHandshakeAckMessage msg = mock(ClientHandshakeAckMessage.class);
    final MessageChannelInternal channel = mock(MessageChannelInternal.class);
    ChannelManager chMgr = mock(ChannelManager.class);
    ChannelStats stats = mock(ChannelStats.class);

    final ArgumentCaptor<ChannelID> cidCollector = ArgumentCaptor.forClass(ChannelID.class);

    when(channel.getChannelID())
        .then(
            new Answer<ChannelID>() {

              @Override
              public ChannelID answer(InvocationOnMock invocation) throws Throwable {
                return cidCollector.getValue();
              }
            });

    final ArgumentCaptor<ChannelManagerEventListener> lsnrCaptor =
        ArgumentCaptor.forClass(ChannelManagerEventListener.class);
    Mockito.doNothing().when(chMgr).addEventListener(lsnrCaptor.capture());

    when(channel.getRemoteAddress()).thenReturn(new TCSocketAddress(8192));
    when(channel.createMessage(TCMessageType.CLIENT_HANDSHAKE_ACK_MESSAGE)).thenReturn(msg);
    when(chMgr.getChannel(cidCollector.capture())).thenReturn(channel);
    when(msg.getChannel()).thenReturn(channel);

    channelMgrMbean = new DSOChannelManagerImpl(chMgr, mock(TCConnectionManager.class), "1.0");
    Mockito.doAnswer(
            new Answer<Object>() {

              @Override
              public Object answer(InvocationOnMock invocation) throws Throwable {
                lsnrCaptor.getValue().channelRemoved(channel);
                return null;
              }
            })
        .when(channel)
        .close();

    when(smCtxt.getChannelManager()).thenReturn((DSOChannelManagerMBean) channelMgrMbean);
    when(stats.getCounter(Matchers.same(channel), Matchers.startsWith("serverMap")))
        .thenReturn(mock(SampledCumulativeCounter.class));
    when(stats.getCounter(
            Matchers.same(channel),
            Matchers.argThat(
                new ArgumentMatcher<String>() {

                  @Override
                  public boolean matches(Object argument) {
                    // Ugly, ugly, ugly
                    String str = (String) argument;
                    return !str.startsWith("serverMap");
                  }
                })))
        .thenReturn(SampledCounter.NULL_SAMPLED_COUNTER);
    when(smCtxt.getChannelStats()).thenReturn(stats);
    mbeanSvr = mock(MBeanServer.class);
    dso =
        new DSO(
            smCtxt,
            mock(ServerConfigurationContext.class),
            mbeanSvr,
            mock(TerracottaOperatorEventHistoryProvider.class));
  }