@Test public void shouldThrowIndexOutOfBoundsExceptionIfTheIndexIsToHighOrNegative() { final PriceLevels cut = new PriceLevels(new Price(5.4), new Price(3.5), new Price(6.9), new Price(-1.6)); boolean firstCaught = false; boolean secondCaught = false; try { cut.get(-5); } catch (final IndexOutOfBoundsException e) { firstCaught = true; } try { cut.get(4); } catch (final IndexOutOfBoundsException e) { secondCaught = true; } assertThat(firstCaught).as("A negative index should have thrown an IndexOutOfBoundsException but didn't.") .isTrue(); assertThat(secondCaught) .as("An index that is to great should have thrown an IndexOutOfBoundsException but didn't.").isTrue(); }
public Price get(final int index) throws IndexOutOfBoundsException { return priceLevels[index]; }
PriceLevels { public Price get(final int index) throws IndexOutOfBoundsException { return priceLevels[index]; } }
PriceLevels { public Price get(final int index) throws IndexOutOfBoundsException { return priceLevels[index]; } PriceLevels(final Price... priceLevels);  PriceLevels(final List<Price> priceLevels); }
PriceLevels { public Price get(final int index) throws IndexOutOfBoundsException { return priceLevels[index]; } PriceLevels(final Price... priceLevels);  PriceLevels(final List<Price> priceLevels); Optional<Price> nextHigherLevel(final Price price); Optional<Price> nextLowerLevel(final Price price); int count(); Price get(final int index); boolean contains(final Price price); @Override String toString(); }
PriceLevels { public Price get(final int index) throws IndexOutOfBoundsException { return priceLevels[index]; } PriceLevels(final Price... priceLevels);  PriceLevels(final List<Price> priceLevels); Optional<Price> nextHigherLevel(final Price price); Optional<Price> nextLowerLevel(final Price price); int count(); Price get(final int index); boolean contains(final Price price); @Override String toString();  }