/*
   * Test that if enabled, but not configured, that the code creates the 2nd level classloader
   */
  @Test
  public void testDefaultConfig() throws Exception {

    Whitebox.setInternalState(
        AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null);

    File conf = folder1.newFile("accumulo-site.xml");
    FileWriter out = new FileWriter(conf);
    out.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    out.append("<configuration>\n");
    out.append("<property>\n");
    out.append("<name>general.classpaths</name>\n");
    out.append("<value></value>\n");
    out.append("</property>\n");
    out.append("<property>\n");
    out.append("<name>general.vfs.classpaths</name>\n");
    out.append("<value></value>\n");
    out.append("</property>\n");
    out.append("</configuration>\n");
    out.close();

    Whitebox.setInternalState(
        AccumuloClassLoader.class, "SITE_CONF", conf.toURI().toURL().toString());
    Whitebox.setInternalState(AccumuloVFSClassLoader.class, "lock", new Object());
    ClassLoader acl = AccumuloVFSClassLoader.getClassLoader();
    Assert.assertTrue((acl instanceof VFSClassLoader));
    Assert.assertTrue((acl.getParent() instanceof URLClassLoader));
  }
  @Test
  public void setAxisMoveSingleParameterWrongTest() {
    Drone drone = Drone.getInstance();

    ThreadCmd tc = new ThreadCmd(drone);
    float prevValueState = 0;
    float testValue = 0;

    Whitebox.setInternalState(tc, "move_armed", 0);
    Whitebox.setInternalState(tc, "move_roll", 0);
    Whitebox.setInternalState(tc, "move_pitch", 0);
    Whitebox.setInternalState(tc, "move_altitude", 0);
    Whitebox.setInternalState(tc, "move_yaw", 0);

    // move_roll
    prevValueState = Whitebox.getInternalState(tc, "move_roll");
    tc.setAxisMove(-1.0001f, 0, 0, 0);
    testValue = Whitebox.getInternalState(tc, "move_roll");
    Assert.assertEquals(prevValueState, testValue);

    prevValueState = Whitebox.getInternalState(tc, "move_roll");
    tc.setAxisMove(1.0001f, 0, 0, 0);
    testValue = Whitebox.getInternalState(tc, "move_roll");
    Assert.assertEquals(prevValueState, testValue);

    // move_pitch
    prevValueState = Whitebox.getInternalState(tc, "move_pitch");
    tc.setAxisMove(0, -1.0001f, 0, 0);
    testValue = Whitebox.getInternalState(tc, "move_pitch");
    Assert.assertEquals(prevValueState, testValue);

    prevValueState = Whitebox.getInternalState(tc, "move_pitch");
    tc.setAxisMove(0, 1.0001f, 0, 0);
    testValue = Whitebox.getInternalState(tc, "move_pitch");
    Assert.assertEquals(prevValueState, testValue);

    // move_altitude
    prevValueState = Whitebox.getInternalState(tc, "move_altitude");
    tc.setAxisMove(0, -1.0001f, 0, 0);
    testValue = Whitebox.getInternalState(tc, "move_altitude");
    Assert.assertEquals(prevValueState, testValue);

    prevValueState = Whitebox.getInternalState(tc, "move_altitude");
    tc.setAxisMove(0, 1.0001f, 0, 0);
    testValue = Whitebox.getInternalState(tc, "move_altitude");
    Assert.assertEquals(prevValueState, testValue);

    // move_yaw
    prevValueState = Whitebox.getInternalState(tc, "move_yaw");
    tc.setAxisMove(0, -1.0001f, 0, 0);
    testValue = Whitebox.getInternalState(tc, "move_yaw");
    Assert.assertEquals(prevValueState, testValue);

    prevValueState = Whitebox.getInternalState(tc, "move_yaw");
    tc.setAxisMove(0, 1.0001f, 0, 0);
    testValue = Whitebox.getInternalState(tc, "move_yaw");
    Assert.assertEquals(prevValueState, testValue);
  }
 @Before
 public void setUp() {
   pmf =
       new PersistenceManagerFactory(
           cluster, ImmutableMap.<ConfigurationParameters, Object>of(FORCE_TABLE_CREATION, true));
   pmf.configurationMap = configMap;
   Whitebox.setInternalState(pmf, ArgumentExtractor.class, argumentExtractor);
   Whitebox.setInternalState(pmf, AchillesBootstrapper.class, boostrapper);
   Whitebox.setInternalState(pmf, ProxyClassFactory.class, proxyClassFactory);
 }
 @Before
 public void setUp() {
   logger = createMock(Logger.class);
   bundle = ResourceBundleProducer.create("demoiselle-jpa-bundle", Locale.getDefault());
   producer = new EntityManagerFactoryProducer();
   cache = Collections.synchronizedMap(new HashMap<String, EntityManagerFactory>());
   setInternalState(producer, Map.class, cache);
   setInternalState(producer, Logger.class, logger);
   setInternalState(producer, ResourceBundle.class, bundle);
   emFactory = createMock(EntityManagerFactory.class);
 }
  @Before
  public void init() {
    controller = new FlexOfferController();
    Whitebox.setInternalState(controller, messageService);
    Whitebox.setInternalState(controller, jmsService);
    Whitebox.setInternalState(controller, corePlanboardBusinessService);
    Whitebox.setInternalState(controller, corePlanboardValidatorService);
    Whitebox.setInternalState(controller, config);

    PowerMockito.when(config.getProperty(Matchers.eq(ConfigParam.HOST_DOMAIN)))
        .thenReturn("usef-example.com");
  }
Пример #6
0
  @Before
  public void setUp() {
    File dataDir = tempDir.getRoot();

    when(settings.getDocumentrDataDir()).thenReturn(dataDir);

    globalRepoManager = new GlobalRepositoryManager();
    Whitebox.setInternalState(globalRepoManager, settings, repoManagerFactory, eventBus);
    globalRepoManager.init();

    pageStore = new PageStore();
    Whitebox.setInternalState(pageStore, globalRepoManager, eventBus);
  }
Пример #7
0
 /** Sets up all dependencies before running a test. */
 @Before
 public void before() {
   mLineageMasterClient = PowerMockito.mock(LineageMasterClient.class);
   mLineageContext = PowerMockito.mock(LineageContext.class);
   Mockito.when(mLineageContext.acquireMasterClient()).thenReturn(mLineageMasterClient);
   Whitebox.setInternalState(LineageContext.class, "INSTANCE", mLineageContext);
   mAlluxioLineageFileSystem = LineageFileSystem.get();
   Whitebox.setInternalState(mAlluxioLineageFileSystem, "mLineageContext", mLineageContext);
   FileSystemContext fileSystemContext = PowerMockito.mock(FileSystemContext.class);
   FileSystemMasterClient fileSystemMasterClient = PowerMockito.mock(FileSystemMasterClient.class);
   Mockito.when(fileSystemContext.acquireMasterClient()).thenReturn(fileSystemMasterClient);
   Whitebox.setInternalState(FileSystemContext.class, "INSTANCE", fileSystemContext);
   Whitebox.setInternalState(mAlluxioLineageFileSystem, "mContext", fileSystemContext);
 }
 @BeforeClass
 public void setUpClass() {
   mockControl = EasyMock.createStrictControl();
   logger = mockControl.createMock(Logger.class);
   generator = mockControl.createMock(RandomNumberGenerator.class);
   setUpEnemy();
   setUpResolvationData();
   underTest = new SingleFightRoundResolver();
   Whitebox.setInternalState(underTest, "logger", logger);
   Whitebox.setInternalState(underTest, "generator", generator);
   init(mockControl, underTest);
   beforeRoundResult = new FightBeforeRoundResult();
   diceResultRenderer = mockControl.createMock(DiceResultRenderer.class);
   Whitebox.setInternalState(underTest, "diceResultRenderer", diceResultRenderer);
 }
Пример #9
0
  @Test
  public void shouldGetOpenOrders() throws IOException {
    // given
    final LimitOrder[] expectedOrders = expectedOrders();

    BitMarketOrdersResponse response =
        new BitMarketOrdersResponse(
            true, createOpenOrdersData(), new BitMarketAPILimit(3, 100, 12345000L), 0, null);

    BitMarketAuthenticated bitMarketAuthenticated = mock(BitMarketAuthenticated.class);
    PowerMockito.when(
            bitMarketAuthenticated.orders(
                Mockito.eq(SPECIFICATION_API_KEY),
                Mockito.any(ParamsDigest.class),
                Mockito.any(SynchronizedValueFactory.class)))
        .thenReturn(response);
    Whitebox.setInternalState(tradeService, "bitMarketAuthenticated", bitMarketAuthenticated);

    // when
    OpenOrders orders = tradeService.getOpenOrders();
    List<LimitOrder> openOrders = orders.getOpenOrders();

    // then
    assertThat(openOrders).hasSize(2);
    for (int i = 0; i < openOrders.size(); i++) {
      BitMarketAssert.assertEquals(openOrders.get(i), expectedOrders[i]);
      assertThat(orders.toString()).contains(expectedOrders[i].toString());
    }
  }
Пример #10
0
  @Test
  public void shouldCancelOrder() throws IOException {
    // given
    BitMarketCancelResponse response =
        new BitMarketCancelResponse(
            true,
            new BitMarketBalance(createAvailable(), createBlocked()),
            new BitMarketAPILimit(3, 100, 12345000L),
            0,
            null);

    BitMarketAuthenticated bitMarketAuthenticated = mock(BitMarketAuthenticated.class);
    PowerMockito.when(
            bitMarketAuthenticated.cancel(
                Mockito.eq(SPECIFICATION_API_KEY),
                Mockito.any(ParamsDigest.class),
                Mockito.any(SynchronizedValueFactory.class),
                Mockito.eq(12345L)))
        .thenReturn(response);
    Whitebox.setInternalState(tradeService, "bitMarketAuthenticated", bitMarketAuthenticated);

    // when
    boolean cancelled = tradeService.cancelOrder("12345");

    // then
    assertThat(cancelled).isTrue();
  }
Пример #11
0
  private LocalAlluxioMaster() throws IOException {
    mHostname = NetworkAddressUtils.getConnectHost(ServiceType.MASTER_RPC);

    mJournalFolder = Configuration.get(Constants.MASTER_JOURNAL_FOLDER);

    mAlluxioMaster = AlluxioMaster.Factory.create();
    Whitebox.setInternalState(AlluxioMaster.class, "sAlluxioMaster", mAlluxioMaster);

    // Reset the master port
    Configuration.set(Constants.MASTER_RPC_PORT, Integer.toString(getRPCLocalPort()));

    Runnable runMaster =
        new Runnable() {
          @Override
          public void run() {
            try {
              mAlluxioMaster.start();
            } catch (Exception e) {
              throw new RuntimeException(e + " \n Start Master Error \n" + e.getMessage(), e);
            }
          }
        };

    mMasterThread = new Thread(runMaster);
  }
Пример #12
0
  @Test(expected = ExchangeException.class)
  public void shouldFailOnUnsuccessfulLimitOrder() throws IOException {
    // given
    BitMarketTradeResponse response =
        new BitMarketTradeResponse(
            false, null, new BitMarketAPILimit(3, 100, 12345000L), 502, "Invalid message hash");

    BitMarketAuthenticated bitMarketAuthenticated = mock(BitMarketAuthenticated.class);
    PowerMockito.when(
            bitMarketAuthenticated.trade(
                Mockito.eq(SPECIFICATION_API_KEY),
                Mockito.any(ParamsDigest.class),
                Mockito.any(SynchronizedValueFactory.class),
                Mockito.eq("BTCAUD"),
                Mockito.eq("sell"),
                Mockito.eq(BigDecimal.ONE),
                Mockito.eq(BigDecimal.TEN)))
        .thenReturn(response);
    Whitebox.setInternalState(tradeService, "bitMarketAuthenticated", bitMarketAuthenticated);

    // when
    tradeService.placeLimitOrder(
        new LimitOrder(
            Order.OrderType.ASK,
            BigDecimal.ONE,
            CurrencyPair.BTC_AUD,
            "12345",
            null,
            BigDecimal.TEN));

    // then
    fail(
        "BitMarketTradeService should throw ExchangeException when place limit order request was unsuccessful");
  }
  @Before
  public void init() {
    repository = new SynchronisationConnectionRepository();
    setInternalState(repository, "entityManager", entityManager);

    // clear the entity manager to avoid unexpected results
    repository.getEntityManager().clear();
  }
Пример #14
0
  @Test
  public void shouldGetCurrencyPairTradeHistory() throws IOException {
    // given
    final UserTrade[] expectedCpUserTrades = expectedCpUserTrades();

    BitMarketHistoryTradesResponse historyTradesCPResponse =
        parse("trade/example-history-trades-cp-data", BitMarketHistoryTradesResponse.class);
    BitMarketHistoryOperationsResponse marketHistoryOperationsEurResponse =
        parse(
            "trade/example-history-operations-eur-data", BitMarketHistoryOperationsResponse.class);
    BitMarketHistoryOperationsResponse marketHistoryOperationsBtcResponse =
        parse(
            "trade/example-history-operations-btc-data", BitMarketHistoryOperationsResponse.class);

    BitMarketAuthenticated bitMarketAuthenticated = mock(BitMarketAuthenticated.class);
    PowerMockito.when(
            bitMarketAuthenticated.trades(
                Mockito.eq(SPECIFICATION_API_KEY),
                Mockito.any(ParamsDigest.class),
                Mockito.any(SynchronizedValueFactory.class),
                Mockito.eq("BTCEUR"),
                Mockito.eq(1000),
                Mockito.eq(0L)))
        .thenReturn(historyTradesCPResponse);

    PowerMockito.when(
            bitMarketAuthenticated.history(
                Mockito.eq(SPECIFICATION_API_KEY),
                Mockito.any(ParamsDigest.class),
                Mockito.any(SynchronizedValueFactory.class),
                Mockito.eq(Currency.EUR.toString()),
                Mockito.anyInt(),
                Mockito.anyLong()))
        .thenReturn(marketHistoryOperationsEurResponse);
    PowerMockito.when(
            bitMarketAuthenticated.history(
                Mockito.eq(SPECIFICATION_API_KEY),
                Mockito.any(ParamsDigest.class),
                Mockito.any(SynchronizedValueFactory.class),
                Mockito.eq(Currency.BTC.toString()),
                Mockito.anyInt(),
                Mockito.anyLong()))
        .thenReturn(marketHistoryOperationsBtcResponse);

    Whitebox.setInternalState(tradeService, "bitMarketAuthenticated", bitMarketAuthenticated);

    // when
    UserTrades tradesCP =
        tradeService.getTradeHistory(
            new DefaultTradeHistoryParamCurrencyPair(CurrencyPair.BTC_EUR));
    List<UserTrade> userTrades = tradesCP.getUserTrades();

    // then
    assertThat(userTrades).hasSize(2);
    for (int i = 0; i < userTrades.size(); i++) {
      BitMarketAssert.assertEquals(userTrades.get(i), expectedCpUserTrades[i]);
    }
  }
Пример #15
0
  /**
   * Tests run of zipalign with correct parameters as well adding aligned file to artifacts
   *
   * @throws Exception
   */
  public void testDefaultRun() throws Exception {
    ZipalignMojo mojo = createMojo("zipalign-config-project3");

    MavenProject project = Whitebox.getInternalState(mojo, "project");
    project.setPackaging(AndroidExtension.APK);

    MavenProjectHelper projectHelper = EasyMock.createNiceMock(MavenProjectHelper.class);
    Capture<File> capturedParameter = new Capture<File>();
    projectHelper.attachArtifact(
        EasyMock.eq(project),
        EasyMock.eq(AndroidExtension.APK),
        EasyMock.eq("aligned"),
        EasyMock.capture(capturedParameter));
    Whitebox.setInternalState(mojo, "projectHelper", projectHelper);

    final CommandExecutor mockExecutor = PowerMock.createMock(CommandExecutor.class);
    PowerMock.replace(
            CommandExecutor.Factory.class.getDeclaredMethod("createDefaultCommmandExecutor"))
        .with(
            new InvocationHandler() {
              @Override
              public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                return mockExecutor;
              }
            });

    Capture<List<String>> capturedFile = new Capture<List<String>>();
    mockExecutor.setLogger(EasyMock.anyObject(Log.class));
    mockExecutor.executeCommand(EasyMock.anyObject(String.class), EasyMock.capture(capturedFile));

    PowerMock.mockStatic(FileUtils.class);
    EasyMock.expect(FileUtils.fileExists("app-updated.apk")).andReturn(true);

    EasyMock.replay(projectHelper);
    PowerMock.replay(mockExecutor);
    PowerMock.replay(FileUtils.class);

    mojo.execute();

    PowerMock.verify(mockExecutor);
    List<String> parameters = capturedFile.getValue();
    List<String> parametersExpected = new ArrayList<String>();
    parametersExpected.add("-v");
    parametersExpected.add("-f");
    parametersExpected.add("4");
    parametersExpected.add("app.apk");
    parametersExpected.add("app-updated.apk");
    assertEquals("Zipalign arguments aren't as expected", parametersExpected, parameters);

    PowerMock.verify(projectHelper);
    assertEquals(
        "File should be same as expected",
        new File("app-updated.apk"),
        capturedParameter.getValue());

    // verify that all method were invoked
    PowerMock.verify(FileUtils.class);
  }
  @Test
  public void mockPolicyWithExpectationsWorks() throws Exception {
    final SimpleClassWithADependency tested = new SimpleClassWithADependency();
    Whitebox.setInternalState(tested, new ResultCalculator(5));

    assertEquals(2.0, tested.getResult(), 0.0);

    verifyAll();
  }
 @Test
 public void testSupressStaticInitializerAndSetFinalField() throws Exception {
   assertNull(
       "Should be null because the static initializer should be suppressed",
       StaticInitializerExample.getMySet());
   final HashSet<String> hashSet = new HashSet<String>();
   Whitebox.setInternalState(StaticInitializerExample.class, "mySet", hashSet);
   assertSame(hashSet, Whitebox.getInternalState(StaticInitializerExample.class, "mySet"));
 }
 @Before
 public void before() throws Exception {
   AlluxioWorker alluxioWorker = mResource.get().getWorker();
   mBlockWorker = PowerMockito.mock(BlockWorker.class);
   // Replace the block worker created by LocalAlluxioClusterResource with a mock.
   BlockWorker blockWorker = Whitebox.getInternalState(alluxioWorker, "mBlockWorker");
   blockWorker.stop();
   Whitebox.setInternalState(alluxioWorker, "mBlockWorker", mBlockWorker);
 }
 @BeforeMethod
 public void setUpMethod() {
   command = new FfFightCommand();
   init(command);
   Whitebox.setInternalState(command, "roundNumber", 1);
   fixEnemy();
   enemies = new ArrayList<>();
   command.getResolvedEnemies().clear();
   mockControl.reset();
 }
Пример #20
0
  /** {@inheritDoc} */
  @Before
  public void setUp() {
    ts = new Timestamp();
    ts.setNodeId("node1");
    ts.setSeqNumber(10);

    theSummary = new Summary();

    setInternalState(theSummary, data);
  }
Пример #21
0
  @Before
  public void setUp() {
    et = createMock(EntityTransaction.class);
    em = createMock(EntityManager.class);
    cache = new HashMap<String, EntityManager>();
    producer = EasyMock.createMock(EntityManagerProducer.class);

    tx = new JPATransaction();
    setInternalState(tx, EntityManagerProducer.class, producer);
  }
  @Test
  public void wifiConnectThreadStartTest() throws Exception {
    WiFiConnection wifi = createMock(WiFiConnection.class);
    NavData navData = new NavData();
    PacketDemo packetDemo = new PacketDemo();
    mockStatic(Tools.class);

    wifi.connect();
    expectLastCall();
    expect(Tools.get_state_bit(navData.drone_state, 6)).andReturn(false);
    wifi.sendAtCommand("AT*CONFIG=#SEQ#,\"custom:session_id\",\"ca0000d1\"");
    expectLastCall();
    expect(Tools.get_state_bit(navData.drone_state, 6)).andReturn(true);
    wifi.sendAtCommand("AT*CTRL=#SEQ#,5,0");
    expectLastCall();
    expect(wifi.isRunning()).andReturn(true).anyTimes();
    //		wifi.setRunning(false);
    //		expectLastCall();

    replayAll();
    Drone drone = Drone.getInstance();
    Whitebox.setInternalState(drone, "wifi", wifi);
    Whitebox.setInternalState(navData, "drone_state", 0);
    Whitebox.setInternalState(drone, "navData", navData);
    drone.connect();
    //	Thread.sleep(500);
    ThreadNavData threadNavData = Whitebox.getInternalState(drone, "threadNavData");
    ThreadCmd threadCmd = Whitebox.getInternalState(drone, "threadCmd");

    //		threadNavData.stop();
    assertFalse("Drone.threadCmd is in state NEW", threadCmd.getState() == Thread.State.NEW);
    assertFalse(
        "Drone.threadCmd is in state TERMINATED", threadCmd.getState() == Thread.State.TERMINATED);
    assertFalse(
        "Drone.threadNavData is in state NEW", threadNavData.getState() == Thread.State.NEW);
    assertFalse(
        "Drone.threadNavData is in state TERMINATED",
        threadNavData.getState() == Thread.State.TERMINATED);
    threadCmd.stop();
    threadNavData.stop();
    verifyAll();
  }
Пример #23
0
  @Test
  public void testAddAd() {
    AMItemService instance = new AMItemService();
    Whitebox.setInternalState(instance, "storeService", storeService);

    // Setting up
    EasyMock.expect(storeService.addMarketAd(ad)).andReturn(ad);
    PowerMock.replayAll();
    Ad response = instance.addAd(ad);
    PowerMock.verifyAll();
  }
  @Test
  public void testProcessList() throws NoSuchFieldException, IllegalAccessException {
    List<String> list = Arrays.asList("sup1", "sup2", "sup3", "sup4", "sup5");

    ListManager manager = new ListManager();
    // change the value paginationSize to a better value for test
    Whitebox.setInternalState(ListManager.class, "paginationSize", 2);

    int count = manager.processList(list);
    assertEquals(count, 3);
  }
  /*
   * Test with default context configured
   */
  @Test
  public void testDefaultContextConfigured() throws Exception {

    Whitebox.setInternalState(
        AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null);

    // Copy jar file to TEST_DIR
    FileUtils.copyURLToFile(
        this.getClass().getResource("/HelloWorld.jar"), folder1.newFile("HelloWorld.jar"));

    File conf = folder1.newFile("accumulo-site.xml");
    FileWriter out = new FileWriter(conf);
    out.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    out.append("<configuration>\n");
    out.append("<property>\n");
    out.append("<name>general.classpaths</name>\n");
    out.append("<value></value>\n");
    out.append("</property>\n");
    out.append("<property>\n");
    out.append("<name>general.vfs.classpaths</name>\n");
    out.append("<value>" + new File(folder1.getRoot(), "HelloWorld.jar").toURI() + "</value>\n");
    out.append("</property>\n");
    out.append("</configuration>\n");
    out.close();

    Whitebox.setInternalState(
        AccumuloClassLoader.class, "SITE_CONF", conf.toURI().toURL().toString());
    Whitebox.setInternalState(AccumuloVFSClassLoader.class, "lock", new Object());
    ClassLoader acl = AccumuloVFSClassLoader.getClassLoader();
    Assert.assertTrue((acl instanceof VFSClassLoader));
    Assert.assertTrue((acl.getParent() instanceof VFSClassLoader));
    VFSClassLoader arvcl = (VFSClassLoader) acl.getParent();
    Assert.assertEquals(1, arvcl.getFileObjects().length);
    // We can't be sure what the authority/host will be due to FQDN mappings, so just check the path
    Assert.assertTrue(arvcl.getFileObjects()[0].getURL().toString().contains("HelloWorld.jar"));
    Class<?> clazz1 = arvcl.loadClass("test.HelloWorld");
    Object o1 = clazz1.newInstance();
    Assert.assertEquals("Hello World!", o1.toString());
    Whitebox.setInternalState(
        AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null);
  }
Пример #26
0
  @Test
  public void shouldGetTradeHistory() throws IOException {
    // given
    BitMarketHistoryTradesResponse historyTradesBMResponse =
        parse("trade/example-history-trades-bm-data", BitMarketHistoryTradesResponse.class);
    BitMarketHistoryOperationsResponse marketHistoryOperationsEurResponse =
        parse(
            "trade/example-history-operations-eur-data", BitMarketHistoryOperationsResponse.class);
    BitMarketHistoryOperationsResponse marketHistoryOperationsBtcResponse =
        parse(
            "trade/example-history-operations-btc-data", BitMarketHistoryOperationsResponse.class);

    BitMarketAuthenticated bitMarketAuthenticated = mock(BitMarketAuthenticated.class);
    PowerMockito.when(
            bitMarketAuthenticated.trades(
                Mockito.eq(SPECIFICATION_API_KEY),
                Mockito.any(ParamsDigest.class),
                Mockito.any(SynchronizedValueFactory.class),
                Mockito.eq("BTCEUR"),
                Mockito.eq(3500),
                Mockito.eq(500L)))
        .thenReturn(historyTradesBMResponse);

    PowerMockito.when(
            bitMarketAuthenticated.history(
                Mockito.eq(SPECIFICATION_API_KEY),
                Mockito.any(ParamsDigest.class),
                Mockito.any(SynchronizedValueFactory.class),
                Mockito.eq(Currency.EUR.toString()),
                Mockito.anyInt(),
                Mockito.anyLong()))
        .thenReturn(marketHistoryOperationsEurResponse);
    PowerMockito.when(
            bitMarketAuthenticated.history(
                Mockito.eq(SPECIFICATION_API_KEY),
                Mockito.any(ParamsDigest.class),
                Mockito.any(SynchronizedValueFactory.class),
                Mockito.eq(Currency.BTC.toString()),
                Mockito.anyInt(),
                Mockito.anyLong()))
        .thenReturn(marketHistoryOperationsBtcResponse);

    Whitebox.setInternalState(tradeService, "bitMarketAuthenticated", bitMarketAuthenticated);

    // when
    UserTrades tradesBM =
        tradeService.getTradeHistory(new BitMarketHistoryParams(CurrencyPair.BTC_EUR, 500L, 3500));
    List<UserTrade> userTrades = tradesBM.getUserTrades();

    // then
    assertThat(userTrades).hasSize(1);
    BitMarketAssert.assertEquals(userTrades.get(0), EXPECTED_BM_USER_TRADES);
  }
 public void testSetRandomShouldSetRandomToBeforeRandom() {
   // GIVEN
   underTest = new FightBeforeRoundTransformer();
   final FfFightCommand command = new FfFightCommand();
   final FightCommandMessageList messages = new FightCommandMessageList();
   Whitebox.setInternalState(command, "messages", messages);
   final FightRoundBoundingCommand fightRandom = new FightRoundBoundingCommand(command);
   // WHEN
   underTest.setBounding(command, fightRandom);
   // THEN
   Assert.assertSame(command.getBeforeBounding(), fightRandom);
 }
  @Test
  public void testCreate() {
    request = createMock(HttpServletRequest.class);
    replay(request);

    httpServletRequestProducer = new HttpServletRequestProducer();
    Whitebox.setInternalState(httpServletRequestProducer, "request", request);

    Assert.assertEquals(httpServletRequestProducer.create(), request);

    verifyAll();
  }
Пример #29
0
  @Test
  public void testGetInstance_whenDefaultInstanceIsNull() {
    // given
    ExceptionMapper exceptionMapper = null;
    Whitebox.setInternalState(ExceptionMapper.class, "defaultInstance", exceptionMapper);

    // then
    exceptionMapper = ExceptionMapper.getInstance();
    assertEquals(
        "Should be equals because ExceptionMapper is a singleton",
        Whitebox.getInternalState(ExceptionMapper.class, "defaultInstance"),
        exceptionMapper);
  }
Пример #30
0
  @Test(expected = ExchangeException.class)
  public void shouldFailOnUnsuccessfulTradeHistory() throws IOException {
    // given
    BitMarketHistoryTradesResponse response =
        new BitMarketHistoryTradesResponse(
            false, null, new BitMarketAPILimit(3, 100, 12345000L), 502, "Invalid message hash");

    BitMarketHistoryOperationsResponse marketHistoryOperationsPlnResponse =
        parse("trade/example-history-operations-data", BitMarketHistoryOperationsResponse.class);
    BitMarketHistoryOperationsResponse marketHistoryOperationsBtcResponse =
        parse(
            "trade/example-history-operations-btc-data", BitMarketHistoryOperationsResponse.class);

    BitMarketAuthenticated bitMarketAuthenticated = mock(BitMarketAuthenticated.class);
    PowerMockito.when(
            bitMarketAuthenticated.trades(
                Mockito.eq(SPECIFICATION_API_KEY),
                Mockito.any(ParamsDigest.class),
                Mockito.any(SynchronizedValueFactory.class),
                Mockito.eq("BTCPLN"),
                Mockito.eq(1000),
                Mockito.eq(0L)))
        .thenReturn(response);
    PowerMockito.when(
            bitMarketAuthenticated.history(
                Mockito.eq(SPECIFICATION_API_KEY),
                Mockito.any(ParamsDigest.class),
                Mockito.any(SynchronizedValueFactory.class),
                Mockito.eq(Currency.PLN.toString()),
                Mockito.anyInt(),
                Mockito.anyLong()))
        .thenReturn(marketHistoryOperationsPlnResponse);
    PowerMockito.when(
            bitMarketAuthenticated.history(
                Mockito.eq(SPECIFICATION_API_KEY),
                Mockito.any(ParamsDigest.class),
                Mockito.any(SynchronizedValueFactory.class),
                Mockito.eq(Currency.BTC.toString()),
                Mockito.anyInt(),
                Mockito.anyLong()))
        .thenReturn(marketHistoryOperationsBtcResponse);

    Whitebox.setInternalState(tradeService, "bitMarketAuthenticated", bitMarketAuthenticated);

    // when
    tradeService.getTradeHistory(new DefaultTradeHistoryParamPaging(150));

    // then
    fail(
        "BitMarketTradeService should throw ExchangeException when open orders request was unsuccessful");
  }