Skip to content

Commit

Permalink
Added method isInAllInstruments
Browse files Browse the repository at this point in the history
  • Loading branch information
reiss authored and reiss committed Nov 8, 2017
1 parent 2af1662 commit 988fe9d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/jforex/programming/currency/CurrencyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,14 @@ public static final boolean isInInstruments(final ICurrency currency,
.stream()
.anyMatch(instrument -> isInInstrument(currency, instrument));
}

public static final boolean isInAllInstruments(final ICurrency currency,
final Collection<Instrument> instruments) {
checkNotNull(currency);
checkNotNull(instruments);

return instruments
.stream()
.allMatch(instrument -> isInInstrument(currency, instrument));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public static final Set<Instrument> combineWithAnchorCurrency(final ICurrency an
.collect(toSet());
}

public static final Maybe<Instrument> maybeCrossInstrument(final Instrument firstInstrument,
final Instrument secondInstrument) {
public static final Maybe<Instrument> maybeCross(final Instrument firstInstrument,
final Instrument secondInstrument) {
checkNotNull(firstInstrument);
checkNotNull(secondInstrument);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jforex.programming.currency.test;

import static com.jforex.programming.currency.CurrencyUtil.isInAllInstruments;
import static com.jforex.programming.currency.CurrencyUtil.isInInstrument;
import static com.jforex.programming.currency.CurrencyUtil.isInInstruments;
import static com.jforex.programming.currency.CurrencyUtil.isNameValid;
Expand Down Expand Up @@ -85,4 +86,19 @@ public void testIsInInstrumentsIsTrueForContainingCurrency() {
public void testIsInInstrumentsIsFalseForNotContainingCurrency() {
assertFalse(isInInstruments(currencyAUD, instrumentsForTest));
}

@Test
public void testIsInAllInstrumentsIsTrueForEmptyInstrumentCollection() {
assertTrue(isInAllInstruments(currencyUSD, Collections.emptySet()));
}

@Test
public void testIsInAllInstrumentsIsTrueForContainingCurrency() {
assertTrue(isInAllInstruments(currencyUSD, instrumentsForTest));
}

@Test
public void testIsInAllInstrumentsIsFalseForNotAllContainingCurrency() {
assertFalse(isInAllInstruments(currencyEUR, instrumentsForTest));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static com.jforex.programming.instrument.InstrumentFactory.combineCurrencies;
import static com.jforex.programming.instrument.InstrumentFactory.combineWithAnchorCurrency;
import static com.jforex.programming.instrument.InstrumentFactory.maybeCrossInstrument;
import static com.jforex.programming.instrument.InstrumentFactory.maybeCross;
import static com.jforex.programming.instrument.InstrumentFactory.maybeFromCurrencies;
import static com.jforex.programming.instrument.InstrumentFactory.maybeFromName;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -161,20 +161,20 @@ public void testCombineAllWithAnchorCurrencyReturnsCorrectInstruments() {

@Test
public void testMaybeCrossInstrumentIsEmptyWhenInstrumentsFormNoCrossInstrument() {
maybeCrossInstrument(instrumentEURUSD, instrumentEURUSD)
maybeCross(instrumentEURUSD, instrumentEURUSD)
.test()
.assertNoValues();

maybeCrossInstrument(instrumentEURUSD, instrumentGBPJPY)
maybeCross(instrumentEURUSD, instrumentGBPJPY)
.test()
.assertNoValues();
}

@Test
public void testMaybeCrossInstrumentIsCorrect() {
assertThat(maybeCrossInstrument(instrumentEURUSD, instrumentGBPUSD).blockingGet(), equalTo(instrumentEURGBP));
assertThat(maybeCrossInstrument(instrumentEURUSD, instrumentUSDJPY).blockingGet(), equalTo(instrumentEURJPY));
assertThat(maybeCrossInstrument(instrumentUSDJPY, instrumentGBPUSD).blockingGet(), equalTo(instrumentGBPJPY));
assertThat(maybeCrossInstrument(instrumentGBPAUD, instrumentAUDJPY).blockingGet(), equalTo(instrumentGBPJPY));
assertThat(maybeCross(instrumentEURUSD, instrumentGBPUSD).blockingGet(), equalTo(instrumentEURGBP));
assertThat(maybeCross(instrumentEURUSD, instrumentUSDJPY).blockingGet(), equalTo(instrumentEURJPY));
assertThat(maybeCross(instrumentUSDJPY, instrumentGBPUSD).blockingGet(), equalTo(instrumentGBPJPY));
assertThat(maybeCross(instrumentGBPAUD, instrumentAUDJPY).blockingGet(), equalTo(instrumentGBPJPY));
}
}

0 comments on commit 988fe9d

Please sign in to comment.