Added more tests.
This commit is contained in:
parent
1d7fcbd6ad
commit
d592536aca
2 changed files with 10 additions and 7 deletions
|
@ -84,7 +84,7 @@ public final class CurrencyConverter extends AbstractModule {
|
|||
commands.add(CURRENCY_CMD);
|
||||
}
|
||||
|
||||
static Message converyCurrency(String query) throws ModuleException {
|
||||
static Message convertCurrency(String query) throws ModuleException {
|
||||
if (EXCHANGE_RATES.isEmpty()) {
|
||||
try {
|
||||
final SAXBuilder builder = new SAXBuilder();
|
||||
|
@ -201,7 +201,7 @@ public final class CurrencyConverter extends AbstractModule {
|
|||
if (Utils.isValidString(sender) && Utils.isValidString(query)) {
|
||||
if (query.matches("\\d+([,\\d]+)?(\\.\\d+)? [a-zA-Z]{3}+ to [a-zA-Z]{3}+")) {
|
||||
try {
|
||||
final Message msg = converyCurrency(query.substring(query.indexOf(' ')));
|
||||
final Message msg = convertCurrency(query);
|
||||
if (msg.isError()) {
|
||||
helpResponse(bot, sender, CURRENCY_CMD + ' ' + query, true);
|
||||
}
|
||||
|
|
|
@ -48,15 +48,18 @@ public class CurrentConverterTest {
|
|||
AbstractModuleTest.testAbstractModule(new CurrencyConverter());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = ModuleException.class)
|
||||
public void testException() throws ModuleException {
|
||||
CurrencyConverter.convertCurrency("100 BLA to USD");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertCurrency() throws ModuleException {
|
||||
assertThat(CurrencyConverter.converyCurrency("100 USD to EUR").getMessage())
|
||||
assertThat(CurrencyConverter.convertCurrency("100 USD to EUR").getMessage())
|
||||
.as("100 USD to EUR").startsWith("100.00 USD = ");
|
||||
assertThat(CurrencyConverter.converyCurrency("100 BLA to USD").isError())
|
||||
.as("100 BLA to USD").isTrue();
|
||||
assertThat(CurrencyConverter.converyCurrency(CurrencyConverter.CURRENCY_RATES_KEYWORD).isPrivate())
|
||||
assertThat(CurrencyConverter.convertCurrency(CurrencyConverter.CURRENCY_RATES_KEYWORD).isPrivate())
|
||||
.as(CurrencyConverter.CURRENCY_RATES_KEYWORD + " is private").isTrue();
|
||||
assertThat(CurrencyConverter.converyCurrency(CurrencyConverter.CURRENCY_RATES_KEYWORD).getMessage())
|
||||
assertThat(CurrencyConverter.convertCurrency(CurrencyConverter.CURRENCY_RATES_KEYWORD).getMessage())
|
||||
.as(CurrencyConverter.CURRENCY_RATES_KEYWORD).contains("USD: ");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue