@Test
 public void test() {
   final Object o = "G";
   final String s = " + data";
   int count = 0;
   for (final InstrumentDefinition<?> definition : TestInstrumentDefinitions.getAllInstruments()) {
     assertEquals(definition.accept(VISITOR), definition.getClass().getSimpleName());
     assertEquals(definition.accept(VISITOR, o), definition.getClass().getSimpleName() + s);
     count += 2;
   }
   // assertEquals("Have not tested all methods - need to make sure that the accept() method in the
   // definition points to the right method:",
   // InstrumentDefinitionVisitor.class.getMethods().length, count);
 }
 private String getValue(final InstrumentDefinition<?> definition, final boolean withData) {
   String result = definition.getClass().getSimpleName();
   if (withData) {
     result += " + data";
   }
   return result;
 }
 @Test
 public void testPayCashFlowsNoNetting() {
   for (final InstrumentDefinition<?> definition : NO_NETTING_PAY_INSTRUMENTS) {
     final TreeMap<LocalDate, MultipleCurrencyAmount> pay =
         new TreeMap<LocalDate, MultipleCurrencyAmount>(definition.accept(PAY_CASH_FLOWS));
     final TreeMap<LocalDate, MultipleCurrencyAmount> netted =
         new TreeMap<LocalDate, MultipleCurrencyAmount>(definition.accept(VISITOR));
     assertEquals(pay.size(), netted.size());
     assertEquals(pay.keySet(), netted.keySet());
     final Iterator<Map.Entry<LocalDate, MultipleCurrencyAmount>> nettedIterator =
         netted.entrySet().iterator();
     for (final Map.Entry<LocalDate, MultipleCurrencyAmount> payEntry : pay.entrySet()) {
       final Map.Entry<LocalDate, MultipleCurrencyAmount> nettedEntry = nettedIterator.next();
       assertEquals(payEntry.getKey(), nettedEntry.getKey());
       assertEquals(payEntry.getValue().size(), nettedEntry.getValue().size());
       final Iterator<CurrencyAmount> nettedMCAIterator = nettedEntry.getValue().iterator();
       for (final CurrencyAmount payCA : payEntry.getValue()) {
         final CurrencyAmount nettedCA = nettedMCAIterator.next();
         assertEquals(payCA.getCurrency(), nettedCA.getCurrency());
         assertEquals(payCA.getAmount(), -nettedCA.getAmount());
       }
     }
   }
 }
 @Test
 public void testMultipleCashFlowsNoNetting() {
   for (final InstrumentDefinition<?> definition : NO_NETTING_MULTIPLE_CASHFLOWS) {
     final TreeMap<LocalDate, MultipleCurrencyAmount> pay =
         new TreeMap<LocalDate, MultipleCurrencyAmount>(
             definition.accept(PAY_CASH_FLOWS, IBOR_FIXING_SERIES));
     final TreeMap<LocalDate, MultipleCurrencyAmount> receive =
         new TreeMap<LocalDate, MultipleCurrencyAmount>(
             definition.accept(RECEIVE_CASH_FLOWS, IBOR_FIXING_SERIES));
     final TreeMap<LocalDate, MultipleCurrencyAmount> netted =
         new TreeMap<LocalDate, MultipleCurrencyAmount>(
             definition.accept(VISITOR, IBOR_FIXING_SERIES));
     final Set<LocalDate> combinedDates = new HashSet<LocalDate>();
     combinedDates.addAll(pay.keySet());
     combinedDates.addAll(receive.keySet());
     assertEquals(combinedDates.size(), netted.size());
     for (final Map.Entry<LocalDate, MultipleCurrencyAmount> entry : netted.entrySet()) {
       final LocalDate date = entry.getKey();
       final MultipleCurrencyAmount payAmount = pay.get(date);
       final MultipleCurrencyAmount receiveAmount = receive.get(date);
       MultipleCurrencyAmount combinedAmountForDate = null;
       if (payAmount != null) {
         combinedAmountForDate = payAmount.multipliedBy(-1);
         if (receiveAmount != null) {
           combinedAmountForDate = combinedAmountForDate.plus(receiveAmount);
         }
       } else {
         if (receiveAmount != null) {
           combinedAmountForDate = receiveAmount;
         }
       }
       assertNotNull(combinedAmountForDate);
       assertEquals(combinedAmountForDate, entry.getValue());
     }
   }
 }