public void test_unaryOperator_fail1() { UnaryOperator<String> a = Unchecked.unaryOperator((t) -> { throw new IOException(); }); assertThrows(() -> a.apply("A"), UncheckedIOException.class); }
public void test_predicate_fail2() { Predicate<String> a = Unchecked.predicate((t) -> { throw new Exception(); }); assertThrows(() -> a.test("A"), RuntimeException.class); }
public void test_biConsumer_fail1() { BiConsumer<String, String> a = Unchecked.biConsumer((t, u) -> { throw new IOException(); }); assertThrows(() -> a.accept("A", "B"), UncheckedIOException.class); }
public void of_with_exception() { Result<String> test = Result.of(() -> { throw new IllegalArgumentException("Big bad error"); }); assertEquals(test.isSuccess(), false); assertEquals(test.isFailure(), true); assertThrows(test::getValue, IllegalStateException.class); }
public void test_of_empty_no_header() { try (CsvIterator csvFile = CsvIterator.of(CharSource.wrap(""), false)) { assertEquals(csvFile.headers().size(), 0); assertEquals(csvFile.containsHeader("a"), false); assertEquals(csvFile.hasNext(), false); assertEquals(csvFile.hasNext(), false); assertThrows(() -> csvFile.peek(), NoSuchElementException.class); assertThrows(() -> csvFile.next(), NoSuchElementException.class); assertThrows(() -> csvFile.next(), NoSuchElementException.class); assertThrows(() -> csvFile.remove(), UnsupportedOperationException.class); } }
public void test_load_oneDate_invalidDate() { assertThrows( () -> QuotesCsvLoader.load(date(2015, 10, 2), QUOTES_INVALID_DATE), IllegalArgumentException.class, "Error processing resource as CSV file: .*"); }
/** * Test that the box always returns the same value for any non-negative scenario index. */ public void getValue() { MarketDataBox<Integer> box = MarketDataBox.ofSingleValue(27); assertThat(box.getValue(0)).isEqualTo(27); assertThat(box.getValue(Integer.MAX_VALUE)).isEqualTo(27); assertThrows(() -> box.getValue(-1), IllegalArgumentException.class); }
public void test_empty() { ReferenceData test = ReferenceData.empty(); assertEquals(test.containsValue(ID1), false); assertThrows(() -> test.getValue(ID1), ReferenceDataNotFoundException.class); assertEquals(test.findValue(ID1), Optional.empty()); }
public void wrap_with_failure() { Result<String> test = Result.wrap(() -> Result.failure(ERROR, "Something failed")); assertEquals(test.isSuccess(), false); assertEquals(test.isFailure(), true); assertThrows(test::getValue, IllegalStateException.class); }
public void get() { assertThat(ARRAY.get(0)).isEqualTo(1d); assertThat(ARRAY.get(1)).isEqualTo(2d); assertThat(ARRAY.get(2)).isEqualTo(3d); assertThrows(() -> ARRAY.get(-1), IndexOutOfBoundsException.class); assertThrows(() -> ARRAY.get(3), IndexOutOfBoundsException.class); }
public void test_min() { assertEquals(DoubleArray.of(2d).min(), 2d); assertEquals(DoubleArray.of(2d, 1d, 3d).min(), 1d); assertThrows(() -> DoubleArray.EMPTY.min(), IllegalStateException.class); }
public void test_trade_noMarketData() { CdsIndexIsdaCreditCurveNode node = CdsIndexIsdaCreditCurveNode.ofParSpread(TEMPLATE, QUOTE_ID, INDEX_ID, LEGAL_ENTITIES); MarketData marketData = MarketData.empty(VAL_DATE); assertThrows(() -> node.trade(1d, marketData, REF_DATA), MarketDataNotFoundException.class); }
public void combineWithScenarioBoxWithWrongNumberOfScenarios() { MarketDataBox<Integer> box = MarketDataBox.ofScenarioValues(27, 28, 29); MarketDataBox<Integer> otherBox = MarketDataBox.ofScenarioValues(15, 16, 17, 18); assertThrows( () -> box.combineWith(otherBox, (v1, v2) -> v1 + v2), IllegalArgumentException.class, "Scenario values must have the same number of scenarios.*"); }
public void test_with() { IntArray test = IntArray.of(1, 2, 3); assertContent(test.with(0, 4), 4, 2, 3); assertContent(test.with(0, 1), 1, 2, 3); assertThrows(() -> test.with(-1, 2), IndexOutOfBoundsException.class); assertThrows(() -> test.with(3, 2), IndexOutOfBoundsException.class); }
public void test_scenario_byIndex() { RepeatedScenarioMarketData test = RepeatedScenarioMarketData.of(2, BASE_DATA); assertSame(test.scenario(0), BASE_DATA); assertSame(test.scenario(1), BASE_DATA); assertThrows(() -> test.scenario(-1), IndexOutOfBoundsException.class); assertThrows(() -> test.scenario(2), IndexOutOfBoundsException.class); }
public void test_copyOf_array_fromIndex() { assertContent(IntArray.copyOf(new int[] {1, 2, 3}, 0), 1, 2, 3); assertContent(IntArray.copyOf(new int[] {1, 2, 3}, 1), 2, 3); assertContent(IntArray.copyOf(new int[] {1, 2, 3}, 3)); assertThrows(() -> IntArray.copyOf(new int[] {1, 2, 3}, -1), IndexOutOfBoundsException.class); assertThrows(() -> IntArray.copyOf(new int[] {1, 2, 3}, 4), IndexOutOfBoundsException.class); }
public void test_multipliedBy_array() { IntArray test1 = IntArray.of(1, 2, 3); IntArray test2 = IntArray.of(5, 6, 7); assertContent(test1.multipliedBy(test2), 5, 12, 21); assertThrows(() -> test1.multipliedBy(IntArray.EMPTY), IllegalArgumentException.class); }
public void test_dividedBy_array() { DoubleArray test1 = DoubleArray.of(10d, 20d, 30d); DoubleArray test2 = DoubleArray.of(2d, 5d, 10d); assertContent(test1.dividedBy(test2), 5d, 4d, 3d); assertThrows(() -> test1.dividedBy(DoubleArray.EMPTY), IllegalArgumentException.class); }
public void test_createProduct_wrongType() { BondFutureOptionSecurity test = sut(); BondFuture future = PRODUCT.getUnderlyingFuture(); SecurityId secId = future.getSecurityId(); GenericSecurity sec = GenericSecurity.of(INFO); ReferenceData refData = ImmutableReferenceData.of(secId, sec); assertThrows(() -> test.createProduct(refData), ClassCastException.class); }
public void test_build_fail_noRate() { assertThrows( () -> CdsIndexIsdaCreditCurveNode.builder().template(TEMPLATE).observableId(QUOTE_ID).cdsIndexId(INDEX_ID) .legalEntityIds(LEGAL_ENTITIES).quoteConvention(CdsQuoteConvention.QUOTED_SPREAD).build(), IllegalArgumentException.class); }