Updated tests.

This commit is contained in:
Erik C. Thauvin 2020-03-30 15:42:07 -07:00
parent 968823828a
commit 1035f5ba05
4 changed files with 29 additions and 21 deletions

View file

@ -4,13 +4,17 @@
<Whitelist> <Whitelist>
<ID>LongParameterList:AbstractCommand.kt$AbstractCommand$( bot: Mobibot, sender: String, login: String, args: String, isOp: Boolean, isPrivate: Boolean )</ID> <ID>LongParameterList:AbstractCommand.kt$AbstractCommand$( bot: Mobibot, sender: String, login: String, args: String, isOp: Boolean, isPrivate: Boolean )</ID>
<ID>LongParameterList:Comment.kt$Comment$( bot: Mobibot, cmd: String, sender: String, isOp: Boolean, entry: EntryLink, index: Int, commentIndex: Int )</ID> <ID>LongParameterList:Comment.kt$Comment$( bot: Mobibot, cmd: String, sender: String, isOp: Boolean, entry: EntryLink, index: Int, commentIndex: Int )</ID>
<ID>LongParameterList:Comment.kt$Comment$( bot: Mobibot, sender: String, isOp: Boolean, entry: EntryLink, index: Int, commentIndex: Int )</ID>
<ID>LongParameterList:Comment.kt$Comment$(bot: Mobibot, cmd: String, sender: String, entry: EntryLink, index: Int, commentIndex: Int)</ID> <ID>LongParameterList:Comment.kt$Comment$(bot: Mobibot, cmd: String, sender: String, entry: EntryLink, index: Int, commentIndex: Int)</ID>
<ID>MagicNumber:Comment.kt$Comment$3</ID> <ID>MagicNumber:Comment.kt$Comment$3</ID>
<ID>MagicNumber:Cycle.kt$Cycle$10</ID> <ID>MagicNumber:Cycle.kt$Cycle$10</ID>
<ID>MagicNumber:Ignore.kt$Ignore$8</ID>
<ID>MagicNumber:Modules.kt$Modules$7</ID>
<ID>MagicNumber:Recap.kt$Recap.Companion$10</ID> <ID>MagicNumber:Recap.kt$Recap.Companion$10</ID>
<ID>MagicNumber:UrlMgr.kt$UrlMgr$1000L</ID> <ID>MagicNumber:UrlMgr.kt$UrlMgr$1000L</ID>
<ID>MagicNumber:UrlMgr.kt$UrlMgr$60L</ID> <ID>MagicNumber:UrlMgr.kt$UrlMgr$60L</ID>
<ID>MagicNumber:View.kt$View$8</ID> <ID>MagicNumber:View.kt$View$8</ID>
<ID>NestedBlockDepth:Comment.kt$Comment$commandResponse</ID>
<ID>NestedBlockDepth:UrlMgr.kt$UrlMgr$commandResponse</ID> <ID>NestedBlockDepth:UrlMgr.kt$UrlMgr$commandResponse</ID>
</Whitelist> </Whitelist>
</SmellBaseline> </SmellBaseline>

View file

@ -32,6 +32,7 @@
package net.thauvin.erik.mobibot.modules; package net.thauvin.erik.mobibot.modules;
import net.thauvin.erik.mobibot.Utils;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -46,9 +47,9 @@ import static org.assertj.core.api.Assertions.assertThat;
public class CalcTest { public class CalcTest {
@Test @Test
public void testCalc() { public void testCalc() {
assertThat(Calc.calc("1 + 1")).as("calc(1+1)").isEqualTo("1+1 = 2"); assertThat(Calc.calc("1 + 1")).as("calc(1+1)").isEqualTo("1+1 = %s", Utils.bold(2));
assertThat(Calc.calc("1 -3")).as("calc(1 -3)").isEqualTo("1-3 = -2"); assertThat(Calc.calc("1 -3")).as("calc(1 -3)").isEqualTo("1-3 = %s", Utils.bold(-2));
assertThat(Calc.calc("pi+π+e+φ")).as("calc(pi+π+e+φ)").isEqualTo("pi+π+e+φ = 10.62"); assertThat(Calc.calc("pi+π+e+φ")).as("calc(pi+π+e+φ)").isEqualTo("pi+π+e+φ = %s", Utils.bold("10.62"));
assertThat(Calc.calc("one + one")).as("calc(one + one)").startsWith("No idea."); assertThat(Calc.calc("one + one")).as("calc(one + one)").startsWith("No idea.");
} }

View file

@ -33,7 +33,7 @@
package net.thauvin.erik.mobibot.modules; package net.thauvin.erik.mobibot.modules;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import net.thauvin.erik.mobibot.msg.ErrorMessage; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -46,26 +46,28 @@ import static org.assertj.core.api.Assertions.assertThat;
* @since 1.0 * @since 1.0
*/ */
public class CurrencyConverterTest { public class CurrencyConverterTest {
@Test @BeforeClass
public void testCurrencyConvertererImpl() { public void before() throws ModuleException {
AbstractModuleTest.testAbstractModule(new CurrencyConverter()); CurrencyConverter.loadRates();
}
@Test(expectedExceptions = ModuleException.class)
public void testException() throws ModuleException {
CurrencyConverter.convertCurrency("100 BLA to USD");
} }
@Test @Test
@SuppressFBWarnings("PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS") @SuppressFBWarnings("PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS")
public void testConvertCurrency() throws ModuleException { public void testConvertCurrency() {
assertThat(CurrencyConverter.convertCurrency("100 USD to EUR").getMessage()) assertThat(CurrencyConverter.convertCurrency("100 USD to EUR").getMessage())
.as("100 USD to EUR").startsWith("100.00 USD = "); .as("100 USD to EUR").matches("100\\.00 USD = \\d{2,3}\\.\\d{2} EUR");
assertThat(CurrencyConverter.convertCurrency("100 USD to USD")) assertThat(CurrencyConverter.convertCurrency("100 USD to USD").getMessage())
.as("100 USD to USD").isInstanceOf(ErrorMessage.class); .as("100 USD to USD").contains("You're kidding, right?");
assertThat(CurrencyConverter.convertCurrency(CurrencyConverter.CURRENCY_RATES_KEYWORD).isNotice()) assertThat(CurrencyConverter.convertCurrency("100 USD").getMessage())
.as(CurrencyConverter.CURRENCY_RATES_KEYWORD + " is notice").isTrue(); .as("100 USD").contains("Invalid query.");
assertThat(CurrencyConverter.convertCurrency(CurrencyConverter.CURRENCY_RATES_KEYWORD).getMessage()) assertThat(CurrencyConverter.currencyRates().size())
.as(CurrencyConverter.CURRENCY_RATES_KEYWORD).contains("USD: "); .as("currencyRates().size() == 33").isEqualTo(33);
assertThat(CurrencyConverter.currencyRates())
.as("currencyRates().get(EUR)").contains(" EUR: 1");
}
@Test
public void testCurrencyConvertererImpl() {
AbstractModuleTest.testAbstractModule(new CurrencyConverter());
} }
} }

View file

@ -32,6 +32,7 @@
package net.thauvin.erik.mobibot.modules; package net.thauvin.erik.mobibot.modules;
import net.thauvin.erik.mobibot.Utils;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -46,7 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class WordTimeTest { public class WordTimeTest {
@Test @Test
public void testWorldTime() { public void testWorldTime() {
assertThat(WorldTime.worldTime("PST").getMessage()).as("PST").endsWith("Los Angeles"); assertThat(WorldTime.worldTime("PST").getMessage()).as("PST").endsWith(Utils.bold("Los Angeles"));
assertThat(WorldTime.worldTime("BLAH").isError()).as("BLAH").isTrue(); assertThat(WorldTime.worldTime("BLAH").isError()).as("BLAH").isTrue();
assertThat(WorldTime.worldTime("BEATS").getMessage()).as("BEATS").contains("@"); assertThat(WorldTime.worldTime("BEATS").getMessage()).as("BEATS").contains("@");
} }