HistoricalDataUtils { public static BitmexRestClient.ChartDataBinSize getBinSize( int length, BarData.LengthUnit lengthUnit ) { if( lengthUnit == BarData.LengthUnit.DAY ) { if( length == 1 ) { return BitmexRestClient.ChartDataBinSize.ONE_DAY; } } else if( lengthUnit == BarData.LengthUnit.HOUR ) { if( length == 1 ) { return BitmexRestClient.ChartDataBinSize.ONE_HOUR; } } else if( lengthUnit == BarData.LengthUnit.MINUTE ) { if( length == 5 ) { return BitmexRestClient.ChartDataBinSize.FIVE_MINUTES; } else if( length == 1 ) { return BitmexRestClient.ChartDataBinSize.ONE_MINUTE; } } throw new InvalidBarSizeException("Only bar size 1D, 1H, 5M, and 1M bars are supported" ); }  static BitmexRestClient.ChartDataBinSize getBinSize( int length, BarData.LengthUnit lengthUnit ); static BarData buildBarData( Ticker ticker, int barlength, BarData.LengthUnit lengthUnit, BitmexChartData data );  }
@Test public void testGetBinSize_HappyPaths() { assertEquals(BitmexRestClient.ChartDataBinSize.ONE_DAY, HistoricalDataUtils.getBinSize(1, BarData.LengthUnit.DAY)); assertEquals(BitmexRestClient.ChartDataBinSize.ONE_HOUR, HistoricalDataUtils.getBinSize(1, BarData.LengthUnit.HOUR)); assertEquals(BitmexRestClient.ChartDataBinSize.FIVE_MINUTES, HistoricalDataUtils.getBinSize(5, BarData.LengthUnit.MINUTE)); assertEquals(BitmexRestClient.ChartDataBinSize.ONE_MINUTE, HistoricalDataUtils.getBinSize(1, BarData.LengthUnit.MINUTE)); }
@Test public void testGetBinSize_UnhappyPaths() { try { HistoricalDataUtils.getBinSize(1, BarData.LengthUnit.MONTH); fail(); } catch (InvalidBarSizeException ex) { } try { HistoricalDataUtils.getBinSize(2, BarData.LengthUnit.DAY); fail(); } catch (InvalidBarSizeException ex) { } try { HistoricalDataUtils.getBinSize(2, BarData.LengthUnit.HOUR); fail(); } catch (InvalidBarSizeException ex) { } try { HistoricalDataUtils.getBinSize(2, BarData.LengthUnit.MINUTE); fail(); } catch (InvalidBarSizeException ex) { } }