/** Tests the {@link CurrencyDirectory#getDtausCurrencies(Date)} method to return sane values. */ public void testGetDtausCurrencies() throws Exception { assert this.getCurrencyDirectory() != null; Assert.assertTrue( this.getCurrencyDirectory().getDtausCurrencies( new Date() ).length >= 0 ); }
private void updateCurrencies() { final Currency[] currencies = getCurrencyDirectory(). getDtausCurrencies(this.date != null ? this.date : new Date()); Arrays.sort(currencies, new Comparator() { public int compare(final Object o1, final Object o2) { assert o1 instanceof Currency; assert o2 instanceof Currency; return ((Currency) o1).getCurrencyCode(). compareTo(((Currency) o2).getCurrencyCode()); } }); final Object prevSelection = currencyComboBox.getSelectedItem(); currencyComboBox.removeAllItems(); for(int i = 0; i < currencies.length; i++) { currencyComboBox.addItem(currencies[i]); } currencyComboBox.setSelectedItem(prevSelection); }
private void updateCurrencies() { final Currency[] currencies = getCurrencyDirectory(). getDtausCurrencies(this.getDate()); Arrays.sort(currencies, new Comparator() { public int compare(final Object o1, final Object o2) { assert o1 instanceof Currency; assert o2 instanceof Currency; return ((Currency) o1).getCurrencyCode(). compareTo(((Currency) o2).getCurrencyCode()); } }); final Object prevSelection = currencyComboBox.getSelectedItem(); currencyComboBox.removeAllItems(); for(int i = 0; i < currencies.length; i++) { currencyComboBox.addItem(currencies[i]); } currencyComboBox.setSelectedItem(prevSelection); }
/** * Test the {@link CurrencyDirectory#getDtausCurrencies(Date)} method to handle illegal arguments correctly by * throwing a {@code NullPointerException}. */ public void testGetDtausCurrenciesNull() { assert this.getCurrencyDirectory() != null; try { this.getCurrencyDirectory().getDtausCurrencies( null ); throw new AssertionError(); } catch ( NullPointerException e ) { Assert.assertNotNull( e.getMessage() ); System.out.println( e.toString() ); } }
/** * Tests the {@link CurrencyDirectory#getDtausCurrencies(Date)} method to return correct values for the EUR and DEM * currency for various dates. */ public void testCurrencyConstraints() throws Exception { assert this.getCurrencyDirectory() != null; final Calendar cal = Calendar.getInstance(); final Date now = cal.getTime(); cal.set( Calendar.YEAR, 2001 ); cal.set( Calendar.MONTH, 11 ); cal.set( Calendar.DAY_OF_MONTH, 31 ); final Date lastDayDEM = cal.getTime(); cal.set( Calendar.YEAR, 2002 ); cal.set( Calendar.MONTH, 0 ); cal.set( Calendar.DAY_OF_MONTH, 1 ); final Date firstDayEUR = cal.getTime(); this.assertContainsCurrency( this.getCurrencyDirectory().getDtausCurrencies( now ), "EUR" ); this.assertNotContainsCurrency( this.getCurrencyDirectory().getDtausCurrencies( now ), "DEM" ); this.assertNotContainsCurrency( this.getCurrencyDirectory().getDtausCurrencies( lastDayDEM ), "EUR" ); this.assertContainsCurrency( this.getCurrencyDirectory().getDtausCurrencies( lastDayDEM ), "DEM" ); this.assertContainsCurrency( this.getCurrencyDirectory().getDtausCurrencies( firstDayEUR ), "EUR" ); this.assertNotContainsCurrency( this.getCurrencyDirectory().getDtausCurrencies( firstDayEUR ), "DEM" ); }