### Question:
CurrencyPair { public Optional<String> findCommonCcy(final CurrencyPair otherPair) { if (containsCcy(otherPair.getCcy1())) { return Optional.of(otherPair.getCcy1()); } return containsCcy(otherPair.getCcy2()) ? Optional.of(otherPair.getCcy2()) : Optional.empty(); } CurrencyPair(final String ccy1, final String ccy2); static CurrencyPair of(final String ccy1, final String ccy2); String getCcy1(); String getCcy2(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override String toString(); boolean containsCcy(final String ccy); Optional<String> findCommonCcy(final CurrencyPair otherPair); CurrencyPair createInverse();  }### Answer:
@Test public void testFindCommonCcy() throws Exception { final CurrencyPair cp = new CurrencyPair("A", "B"); final CurrencyPair cp2 = new CurrencyPair("X", "B"); assertThat(cp.findCommonCcy(cp2).get()).isEqualTo("B"); final CurrencyPair cp3 = new CurrencyPair("A", "X"); assertThat(cp3.findCommonCcy(cp).get()).isEqualTo("A"); final CurrencyPair cp4 = new CurrencyPair("Y", "X"); assertThat(cp4.findCommonCcy(cp).isPresent()).isFalse(); final CurrencyPair cpx = new CurrencyPair("GBP", "CHF"); final CurrencyPair cpy = new CurrencyPair("EUR", "GBP"); assertThat(cpx.findCommonCcy(cpy).get()).isEqualTo("GBP"); }