Converted modules to Kotlin.
This commit is contained in:
parent
fa4457a6f6
commit
9c1ab833da
70 changed files with 3313 additions and 3446 deletions
|
@ -66,7 +66,7 @@ public class UtilsTest {
|
|||
|
||||
@Test
|
||||
public void testBold() {
|
||||
assertThat(Utils.bold(1)).as("bold(1)").isEqualTo(Colors.BOLD + "1" + Colors.BOLD);
|
||||
assertThat(Utils.bold(Integer.toString(1))).as("bold(1)").isEqualTo(Colors.BOLD + "1" + Colors.BOLD);
|
||||
assertThat(Utils.bold(ASCII)).as("bold(ascii").isEqualTo(Colors.BOLD + ASCII + Colors.BOLD);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
/*
|
||||
* AbstractModuleTest.java
|
||||
*
|
||||
* Copyright (c) 2004-2020, Erik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of this project nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.thauvin.erik.mobibot.modules;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* The <code>AbstractModuleTest</code> class.
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2019-04-07
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
final class AbstractModuleTest {
|
||||
private AbstractModuleTest() {
|
||||
throw new UnsupportedOperationException("Illegal constructor call.");
|
||||
}
|
||||
|
||||
@SuppressFBWarnings("CE_CLASS_ENVY")
|
||||
static void testAbstractModule(final AbstractModule module) {
|
||||
final String name = module.getClass().getName();
|
||||
|
||||
assertThat(module.isEnabled()).as(name + ": enabled").isNotEqualTo(module.hasProperties());
|
||||
assertThat(module.getCommands().size()).as(name + ": commands > 0").isGreaterThan(0);
|
||||
if (!module.hasProperties()) {
|
||||
assertThat(module.getPropertyKeys().size()).as(name + ": no properties").isEqualTo(0);
|
||||
module.setProperty("test", "test");
|
||||
module.setProperty("", "invalid");
|
||||
}
|
||||
|
||||
assertThat(module.getPropertyKeys().size()).as(name + ": properties > 0").isGreaterThan(0);
|
||||
|
||||
module.setProperty("invalid", "");
|
||||
assertThat(module.isValidProperties()).as(name + ": invalid properties").isFalse();
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* CalcTest.java
|
||||
* CalcTest.kt
|
||||
*
|
||||
* Copyright (c) 2004-2019, Erik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
|
@ -29,32 +29,26 @@
|
|||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.thauvin.erik.mobibot.modules
|
||||
|
||||
package net.thauvin.erik.mobibot.modules;
|
||||
|
||||
import net.thauvin.erik.mobibot.Utils;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import net.thauvin.erik.mobibot.Utils
|
||||
import net.thauvin.erik.mobibot.modules.Calc.Companion.calc
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.testng.annotations.Test
|
||||
|
||||
/**
|
||||
* The <code>CalcTest</code> class.
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2019-04-07
|
||||
* @since 1.0
|
||||
* The `CalcTest` class.
|
||||
*/
|
||||
public class CalcTest {
|
||||
class CalcTest {
|
||||
@Test
|
||||
public void testCalc() {
|
||||
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 = %s", Utils.bold(-2));
|
||||
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.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCalcImpl() {
|
||||
AbstractModuleTest.testAbstractModule(new Calc(null));
|
||||
fun testCalc() {
|
||||
Assertions.assertThat(calc("1 + 1")).`as`("calc(1+1)")
|
||||
.isEqualTo("1+1 = %s", Utils.bold(2))
|
||||
Assertions.assertThat(calc("1 -3")).`as`("calc(1 -3)")
|
||||
.isEqualTo("1-3 = %s", Utils.bold(-2))
|
||||
Assertions.assertThat(calc("pi+π+e+φ")).`as`("calc(pi+π+e+φ)")
|
||||
.isEqualTo("pi+π+e+φ = %s", Utils.bold("10.62"))
|
||||
Assertions.assertThat(calc("one + one")).`as`("calc(one + one)")
|
||||
.startsWith("No idea.")
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* CurrencyConverterTest.java
|
||||
*
|
||||
* Copyright (c) 2004-2019, Erik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of this project nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.thauvin.erik.mobibot.modules;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* The <code>CurrencyConvertTest</code> class.
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2019-04-07
|
||||
* @since 1.0
|
||||
*/
|
||||
public class CurrencyConverterTest {
|
||||
@BeforeClass
|
||||
public void before() throws ModuleException {
|
||||
CurrencyConverter.loadRates();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressFBWarnings("PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS")
|
||||
public void testConvertCurrency() {
|
||||
assertThat(CurrencyConverter.convertCurrency("100 USD to EUR").getMsg())
|
||||
.as("100 USD to EUR").matches("100\\.00 USD = \\d{2,3}\\.\\d{2} EUR");
|
||||
assertThat(CurrencyConverter.convertCurrency("100 USD to USD").getMsg())
|
||||
.as("100 USD to USD").contains("You're kidding, right?");
|
||||
assertThat(CurrencyConverter.convertCurrency("100 USD").getMsg())
|
||||
.as("100 USD").contains("Invalid query.");
|
||||
assertThat(CurrencyConverter.currencyRates().size())
|
||||
.as("currencyRates().size() == 33").isEqualTo(33);
|
||||
assertThat(CurrencyConverter.currencyRates())
|
||||
.as("currencyRates().get(EUR)").contains(" EUR: 1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCurrencyConvertererImpl() {
|
||||
AbstractModuleTest.testAbstractModule(new CurrencyConverter(null));
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* LookupTest.java
|
||||
* CurrencyConverterTest.kt
|
||||
*
|
||||
* Copyright (c) 2004-2019, Erik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
|
@ -29,40 +29,36 @@
|
|||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.thauvin.erik.mobibot.modules
|
||||
|
||||
package net.thauvin.erik.mobibot.modules;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import net.thauvin.erik.mobibot.modules.CurrencyConverter.Companion.convertCurrency
|
||||
import net.thauvin.erik.mobibot.modules.CurrencyConverter.Companion.currencyRates
|
||||
import net.thauvin.erik.mobibot.modules.CurrencyConverter.Companion.loadRates
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.testng.annotations.BeforeClass
|
||||
import org.testng.annotations.Test
|
||||
|
||||
/**
|
||||
* The <code>Lookup Test</code> class.
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2017-05-30
|
||||
* @since 1.0
|
||||
* The `CurrencyConvertTest` class.
|
||||
*/
|
||||
@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
|
||||
public class LookupTest {
|
||||
@Test
|
||||
public void testLookupImpl() {
|
||||
AbstractModuleTest.testAbstractModule(new Lookup(null));
|
||||
class CurrencyConverterTest {
|
||||
@BeforeClass
|
||||
@Throws(ModuleException::class)
|
||||
fun before() {
|
||||
loadRates()
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookup() throws Exception {
|
||||
final String result = Lookup.lookup("erik.thauvin.net");
|
||||
assertThat(result).as("lookup(erik.thauvin.net/104.31.77.12)").contains("104.31.77.12");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhois() throws Exception {
|
||||
final String[] result = Lookup.whois("17.178.96.59", Lookup.WHOIS_HOST);
|
||||
|
||||
assertThat(Arrays.stream(result).anyMatch(m -> m.contains("Apple Inc.")))
|
||||
.as("whois(17.178.96.59/Apple Inc.").isTrue();
|
||||
fun testConvertCurrency() {
|
||||
Assertions.assertThat(convertCurrency("100 USD to EUR").msg)
|
||||
.`as`("100 USD to EUR").matches("100\\.00 USD = \\d{2,3}\\.\\d{2} EUR")
|
||||
Assertions.assertThat(convertCurrency("100 USD to USD").msg)
|
||||
.`as`("100 USD to USD").contains("You're kidding, right?")
|
||||
Assertions.assertThat(convertCurrency("100 USD").msg)
|
||||
.`as`("100 USD").contains("Invalid query.")
|
||||
Assertions.assertThat(currencyRates().size)
|
||||
.`as`("currencyRates().size() == 33").isEqualTo(33)
|
||||
Assertions.assertThat(currencyRates())
|
||||
.`as`("currencyRates().get(EUR)").contains(" EUR: 1")
|
||||
}
|
||||
}
|
52
src/test/java/net/thauvin/erik/mobibot/modules/DiceTest.kt
Normal file
52
src/test/java/net/thauvin/erik/mobibot/modules/DiceTest.kt
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* DiceTest.kt
|
||||
*
|
||||
* Copyright (c) 2004-2020, Erik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of this project nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.thauvin.erik.mobibot.modules
|
||||
|
||||
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.testng.annotations.Test
|
||||
|
||||
class DiceTest {
|
||||
@Test
|
||||
fun testWinLoseOrTie() {
|
||||
assertThat(
|
||||
Dice.winLoseOrTie(6, 6)
|
||||
).`as`("6 vs. 6").isEqualTo(Dice.Result.TIE)
|
||||
assertThat(
|
||||
Dice.winLoseOrTie(6, 5)
|
||||
).`as`("6 vs. 5").isEqualTo(Dice.Result.WIN)
|
||||
assertThat(
|
||||
Dice.winLoseOrTie(5, 6)
|
||||
).`as`("5 vs. 6").isEqualTo(Dice.Result.LOSE)
|
||||
}
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
/*
|
||||
* GoogleSearchTest.java
|
||||
*
|
||||
* Copyright (c) 2004-2020, Erik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of this project nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.thauvin.erik.mobibot.modules;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import net.thauvin.erik.mobibot.LocalProperties;
|
||||
import net.thauvin.erik.mobibot.msg.Message;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
/**
|
||||
* The <code>GoogleSearchTest</code> class.
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2019-04-08
|
||||
* @since 1.0
|
||||
*/
|
||||
public class GoogleSearchTest extends LocalProperties {
|
||||
@Test
|
||||
public void testGoogleSearchImpl() {
|
||||
AbstractModuleTest.testAbstractModule(new GoogleSearch(null));
|
||||
}
|
||||
|
||||
@SuppressFBWarnings("LEST_LOST_EXCEPTION_STACK_TRACE")
|
||||
@SuppressWarnings("PMD.PreserveStackTrace")
|
||||
@Test
|
||||
public void testSearchGoogle() throws ModuleException {
|
||||
final String apiKey = getProperty(GoogleSearch.GOOGLE_API_KEY_PROP);
|
||||
final String cseKey = getProperty(GoogleSearch.GOOGLE_CSE_KEY_PROP);
|
||||
try {
|
||||
List<Message> messages = GoogleSearch.searchGoogle("mobibot site:github.com", apiKey, cseKey);
|
||||
assertThat(messages).as("mobibot results not empty").isNotEmpty();
|
||||
assertThat(messages.get(0).getMsg()).as("found mobitopia").contains("mobibot");
|
||||
|
||||
messages = GoogleSearch.searchGoogle("aapl", apiKey, cseKey);
|
||||
assertThat(messages).as("aapl results not empty").isNotEmpty();
|
||||
assertThat(messages.get(0).getMsg()).as("found apple").containsIgnoringCase("apple");
|
||||
|
||||
assertThatThrownBy(() -> GoogleSearch.searchGoogle("test", "", "apiKey")).as("no API key").isInstanceOf(
|
||||
ModuleException.class).hasNoCause();
|
||||
|
||||
assertThatThrownBy(() -> GoogleSearch.searchGoogle("test", "apiKey", "")).as("no CSE API key").isInstanceOf(
|
||||
ModuleException.class).hasNoCause();
|
||||
|
||||
assertThatThrownBy(() -> GoogleSearch.searchGoogle("", "apikey", "apiKey")).as("no query").isInstanceOf(
|
||||
ModuleException.class).hasNoCause();
|
||||
} catch (ModuleException e) {
|
||||
// Avoid displaying api keys in CI logs
|
||||
if ("true".equals(System.getenv("CI"))) {
|
||||
throw new ModuleException(e.getDebugMessage(), e.getSanitizedMessage(apiKey, cseKey));
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* GoogleSearchTest.kt
|
||||
*
|
||||
* Copyright (c) 2004-2020, Erik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of this project nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.thauvin.erik.mobibot.modules
|
||||
|
||||
import net.thauvin.erik.mobibot.LocalProperties
|
||||
import net.thauvin.erik.mobibot.modules.GoogleSearch.Companion.searchGoogle
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.testng.annotations.Test
|
||||
|
||||
/**
|
||||
* The `GoogleSearchTest` class.
|
||||
*/
|
||||
class GoogleSearchTest : LocalProperties() {
|
||||
@Test
|
||||
@Throws(ModuleException::class)
|
||||
fun testSearchGoogle() {
|
||||
val apiKey = getProperty(GoogleSearch.GOOGLE_API_KEY_PROP)
|
||||
val cseKey = getProperty(GoogleSearch.GOOGLE_CSE_KEY_PROP)
|
||||
try {
|
||||
var messages = searchGoogle("mobibot site:github.com", apiKey, cseKey)
|
||||
Assertions.assertThat(messages).`as`("mobibot results not empty").isNotEmpty
|
||||
Assertions.assertThat(messages[0].msg).`as`("found mobitopia").contains("mobibot")
|
||||
messages = searchGoogle("aapl", apiKey, cseKey)
|
||||
Assertions.assertThat(messages).`as`("aapl results not empty").isNotEmpty
|
||||
Assertions.assertThat(messages[0].msg).`as`("found apple").containsIgnoringCase("apple")
|
||||
Assertions.assertThatThrownBy { searchGoogle("test", "", "apiKey") }
|
||||
.`as`("no API key")
|
||||
.isInstanceOf(ModuleException::class.java).hasNoCause()
|
||||
Assertions.assertThatThrownBy { searchGoogle("test", "apiKey", "") }
|
||||
.`as`("no CSE API key")
|
||||
.isInstanceOf(ModuleException::class.java).hasNoCause()
|
||||
Assertions.assertThatThrownBy { searchGoogle("", "apikey", "apiKey") }
|
||||
.`as`("no query").isInstanceOf(ModuleException::class.java).hasNoCause()
|
||||
} catch (e: ModuleException) {
|
||||
// Avoid displaying api keys in CI logs
|
||||
if ("true" == System.getenv("CI")) {
|
||||
throw ModuleException(e.debugMessage, e.getSanitizedMessage(apiKey, cseKey))
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* JokeTest.java
|
||||
* JokeTest.kt
|
||||
*
|
||||
* Copyright (c) 2004-2019, Erik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
|
@ -29,29 +29,20 @@
|
|||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.thauvin.erik.mobibot.modules
|
||||
|
||||
package net.thauvin.erik.mobibot.modules;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import net.thauvin.erik.mobibot.modules.Joke.Companion.randomJoke
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.testng.annotations.Test
|
||||
|
||||
/**
|
||||
* The <code>JokeTest</code> class.
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2019-04-07
|
||||
* @since 1.0
|
||||
* The `JokeTest` class.
|
||||
*/
|
||||
public class JokeTest {
|
||||
class JokeTest {
|
||||
@Test
|
||||
public void testJokeImpl() {
|
||||
AbstractModuleTest.testAbstractModule(new Joke(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRamdomJoke() throws ModuleException {
|
||||
assertThat(Joke.randomJoke().getMsg().length() > 0).as("randomJoke() > 0").isTrue();
|
||||
assertThat(Joke.randomJoke().getMsg()).as("randomJoke()").containsIgnoringCase("chuck");
|
||||
@Throws(ModuleException::class)
|
||||
fun testRamdomJoke() {
|
||||
Assertions.assertThat(randomJoke().msg.isNotEmpty()).`as`("randomJoke() > 0").isTrue
|
||||
Assertions.assertThat(randomJoke().msg).`as`("randomJoke()").containsIgnoringCase("chuck")
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* WordTimeTest.java
|
||||
* LookupTest.kt
|
||||
*
|
||||
* Copyright (c) 2004-2019, Erik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
|
@ -29,31 +29,30 @@
|
|||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.thauvin.erik.mobibot.modules
|
||||
|
||||
package net.thauvin.erik.mobibot.modules;
|
||||
|
||||
import net.thauvin.erik.mobibot.Utils;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import net.thauvin.erik.mobibot.modules.Lookup.Companion.lookup
|
||||
import net.thauvin.erik.mobibot.modules.Lookup.Companion.whois
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.testng.annotations.Test
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* The <code>WordTimeTest</code> class.
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2019-04-07
|
||||
* @since 1.0
|
||||
* The `Lookup Test` class.
|
||||
*/
|
||||
public class WordTimeTest {
|
||||
class LookupTest {
|
||||
@Test
|
||||
public void testWorldTime() {
|
||||
assertThat(WorldTime.worldTime("PST").getMsg()).as("PST").endsWith(Utils.bold("Los Angeles"));
|
||||
assertThat(WorldTime.worldTime("BLAH").isError()).as("BLAH").isTrue();
|
||||
assertThat(WorldTime.worldTime("BEATS").getMsg()).as("BEATS").contains("@");
|
||||
@Throws(Exception::class)
|
||||
fun testLookup() {
|
||||
val result = lookup("erik.thauvin.net")
|
||||
Assertions.assertThat(result).`as`("lookup(erik.thauvin.net/104.31.77.12)").contains("104.31.77.12")
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWorldTimeImpl() {
|
||||
AbstractModuleTest.testAbstractModule(new Lookup(null));
|
||||
@Throws(Exception::class)
|
||||
fun testWhois() {
|
||||
val result = whois("17.178.96.59", Lookup.WHOIS_HOST)
|
||||
Assertions.assertThat(Arrays.stream(result).anyMatch { m: String -> m.contains("Apple Inc.") })
|
||||
.`as`("whois(17.178.96.59/Apple Inc.").isTrue
|
||||
}
|
||||
}
|
|
@ -42,10 +42,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
|
||||
/**
|
||||
* The <code>ModuleExceptionTest</code> class.
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2019-04-09
|
||||
* @since 1.0
|
||||
*/
|
||||
public class ModuleExceptionTest {
|
||||
static final String debugMessage = "debugMessage";
|
||||
|
@ -53,13 +49,13 @@ public class ModuleExceptionTest {
|
|||
|
||||
@DataProvider(name = "dp")
|
||||
Object[][] createData(final Method m) {
|
||||
return new Object[][]{new Object[]{new ModuleException(debugMessage,
|
||||
message,
|
||||
new IOException("URL http://foobar.com"))},
|
||||
new Object[]{new ModuleException(debugMessage,
|
||||
message,
|
||||
new IOException("URL http://foobar.com?"))},
|
||||
new Object[]{new ModuleException(debugMessage, message)}};
|
||||
return new Object[][]{ new Object[]{ new ModuleException(debugMessage,
|
||||
message,
|
||||
new IOException("URL http://foobar.com")) },
|
||||
new Object[]{ new ModuleException(debugMessage,
|
||||
message,
|
||||
new IOException("URL http://foobar.com?")) },
|
||||
new Object[]{ new ModuleException(debugMessage, message) } };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "dp")
|
||||
|
@ -78,7 +74,7 @@ public class ModuleExceptionTest {
|
|||
final ModuleException e = new ModuleException(debugMessage,
|
||||
message,
|
||||
new IOException(
|
||||
"URL http://foo.com?apiKey=" + apiKey + "&userID=me"));
|
||||
"URL http://foo.com?apiKey=" + apiKey + "&userID=me"));
|
||||
assertThat(e.getSanitizedMessage(apiKey)).as("sanitized url").contains("xxxxxxxxxx").doesNotContain(apiKey);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* PingTest.java
|
||||
* PingTest.kt
|
||||
*
|
||||
* Copyright (c) 2004-2019, Erik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
|
@ -29,28 +29,25 @@
|
|||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.thauvin.erik.mobibot.modules
|
||||
|
||||
package net.thauvin.erik.mobibot.modules;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import net.thauvin.erik.mobibot.modules.Ping.Companion.randomPing
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.testng.annotations.Test
|
||||
|
||||
/**
|
||||
* The <code>PingTest</code> class.
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2019-04-07
|
||||
* @since 1.0
|
||||
* The `PingTest` class.
|
||||
*/
|
||||
public class PingTest {
|
||||
class PingTest {
|
||||
@Test
|
||||
public void testPingImpl() {
|
||||
AbstractModuleTest.testAbstractModule(new Ping(null));
|
||||
fun testPingsArray() {
|
||||
Assertions.assertThat(Ping.PINGS).`as`("Pings array is not empty.").isNotEmpty
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPingsArray() {
|
||||
assertThat(Ping.PINGS).as("Pings array is not empty.").isNotEmpty();
|
||||
fun testRandomPing() {
|
||||
for (i in 0..9) {
|
||||
Assertions.assertThat(randomPing()).`as`("Random ping $i").isIn(Ping.PINGS)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -32,7 +32,6 @@
|
|||
|
||||
package net.thauvin.erik.mobibot.modules
|
||||
|
||||
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.testng.annotations.Test
|
||||
|
||||
|
|
|
@ -1,90 +0,0 @@
|
|||
/*
|
||||
* StockQuoteTest.java
|
||||
*
|
||||
* Copyright (c) 2004-2020, Erik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of this project nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.thauvin.erik.mobibot.modules;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import net.thauvin.erik.mobibot.LocalProperties;
|
||||
import net.thauvin.erik.mobibot.msg.Message;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
/**
|
||||
* The <code>StockQuoteTest</code> class.
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2019-04-07
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
public class StockQuoteTest extends LocalProperties {
|
||||
@SuppressFBWarnings("LEST_LOST_EXCEPTION_STACK_TRACE")
|
||||
@SuppressWarnings("PMD.PreserveStackTrace")
|
||||
@Test
|
||||
public void testGetQuote() throws ModuleException {
|
||||
final String apiKey = LocalProperties.getProperty(StockQuote.ALPHAVANTAGE_API_KEY_PROP);
|
||||
try {
|
||||
final List<Message> messages = StockQuote.getQuote("apple inc", apiKey);
|
||||
assertThat(messages).as("response not empty").isNotEmpty();
|
||||
assertThat(messages.get(0).getMsg()).as("same stock symbol").contains("AAPL").contains("Apple Inc.");
|
||||
|
||||
try {
|
||||
StockQuote.getQuote("blahfoo", apiKey);
|
||||
} catch (ModuleException e) {
|
||||
assertThat(e.getMessage()).as("invalid symbol").containsIgnoringCase(StockQuote.INVALID_SYMBOL);
|
||||
}
|
||||
|
||||
assertThatThrownBy(() -> StockQuote.getQuote("test", "")).as("no API key").isInstanceOf(
|
||||
ModuleException.class).hasNoCause();
|
||||
|
||||
assertThatThrownBy(() -> StockQuote.getQuote("", "apikey")).as("no symbol").isInstanceOf(
|
||||
ModuleException.class).hasNoCause();
|
||||
|
||||
} catch (ModuleException e) {
|
||||
// Avoid displaying api keys in CI logs
|
||||
if ("true".equals(System.getenv("CI"))) {
|
||||
throw new ModuleException(e.getDebugMessage(), e.getSanitizedMessage(apiKey));
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStockQuoteImpl() {
|
||||
AbstractModuleTest.testAbstractModule(new StockQuote(null));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* StockQuoteTest.kt
|
||||
*
|
||||
* Copyright (c) 2004-2020, Erik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of this project nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.thauvin.erik.mobibot.modules
|
||||
|
||||
import net.thauvin.erik.mobibot.LocalProperties
|
||||
import net.thauvin.erik.mobibot.modules.StockQuote.Companion.getQuote
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.testng.annotations.Test
|
||||
|
||||
/**
|
||||
* The `StockQuoteTest` class.
|
||||
*/
|
||||
class StockQuoteTest : LocalProperties() {
|
||||
@Test
|
||||
@Throws(ModuleException::class)
|
||||
fun testGetQuote() {
|
||||
val apiKey = getProperty(StockQuote.ALPHAVANTAGE_API_KEY_PROP)
|
||||
try {
|
||||
val messages = getQuote("apple inc", apiKey)
|
||||
Assertions.assertThat(messages).`as`("response not empty").isNotEmpty
|
||||
Assertions.assertThat(messages[0].msg).`as`("same stock symbol")
|
||||
.isEqualTo("Symbol: AAPL [Apple Inc.]")
|
||||
Assertions.assertThat(messages[1].msg).`as`("price label")
|
||||
.startsWith(" Price: ")
|
||||
try {
|
||||
getQuote("blahfoo", apiKey)
|
||||
} catch (e: ModuleException) {
|
||||
Assertions.assertThat(e.message).`as`("invalid symbol")
|
||||
.containsIgnoringCase(StockQuote.INVALID_SYMBOL)
|
||||
}
|
||||
Assertions.assertThatThrownBy { getQuote("test", "") }.`as`("no API key")
|
||||
.isInstanceOf(ModuleException::class.java).hasNoCause()
|
||||
Assertions.assertThatThrownBy { getQuote("", "apikey") }.`as`("no symbol")
|
||||
.isInstanceOf(ModuleException::class.java).hasNoCause()
|
||||
} catch (e: ModuleException) {
|
||||
// Avoid displaying api keys in CI logs
|
||||
if ("true" == System.getenv("CI")) {
|
||||
throw ModuleException(e.debugMessage, e.getSanitizedMessage(apiKey))
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* TwitterTest.java
|
||||
* TwitterTest.kt
|
||||
*
|
||||
* Copyright (c) 2004-2019, Erik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
|
@ -29,50 +29,43 @@
|
|||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.thauvin.erik.mobibot.modules
|
||||
|
||||
package net.thauvin.erik.mobibot.modules;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import net.thauvin.erik.mobibot.LocalProperties;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import net.thauvin.erik.mobibot.LocalProperties
|
||||
import net.thauvin.erik.mobibot.modules.Twitter.Companion.twitterPost
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.testng.annotations.Test
|
||||
import java.net.InetAddress
|
||||
import java.net.UnknownHostException
|
||||
|
||||
/**
|
||||
* The <code>TwitterTest</code> class.
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2019-04-19
|
||||
* @since 1.0
|
||||
* The `TwitterTest` class.
|
||||
*/
|
||||
public class TwitterTest extends LocalProperties {
|
||||
@SuppressFBWarnings("MDM")
|
||||
private String getCi() {
|
||||
final String ciName = System.getenv("CI_NAME");
|
||||
if (ciName != null) {
|
||||
return ciName;
|
||||
} else {
|
||||
try {
|
||||
return InetAddress.getLocalHost().getHostName();
|
||||
} catch (UnknownHostException e) {
|
||||
return "Unknown Host";
|
||||
class TwitterTest : LocalProperties() {
|
||||
private val ci: String
|
||||
get() {
|
||||
val ciName = System.getenv("CI_NAME")
|
||||
return ciName ?: try {
|
||||
InetAddress.getLocalHost().hostName
|
||||
} catch (e: UnknownHostException) {
|
||||
"Unknown Host"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostTwitter() throws ModuleException {
|
||||
final String msg = "Testing Twitter API from " + getCi();
|
||||
assertThat(Twitter.twitterPost(
|
||||
@Throws(ModuleException::class)
|
||||
fun testPostTwitter() {
|
||||
val msg = "Testing Twitter API from $ci"
|
||||
Assertions.assertThat(
|
||||
twitterPost(
|
||||
getProperty(Twitter.CONSUMER_KEY_PROP),
|
||||
getProperty(Twitter.CONSUMER_SECRET_PROP),
|
||||
getProperty(Twitter.TOKEN_PROP),
|
||||
getProperty(Twitter.TOKEN_SECRET_PROP),
|
||||
getProperty(Twitter.HANDLE_PROP),
|
||||
msg,
|
||||
true).getMsg()).as("twitterPost(" + msg + ')').isEqualTo(msg);
|
||||
true
|
||||
).msg
|
||||
).`as`("twitterPost($msg)").isEqualTo(msg)
|
||||
}
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
/*
|
||||
* Weather2Test.java
|
||||
*
|
||||
* Copyright (c) 2004-2019, Erik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of this project nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.thauvin.erik.mobibot.modules;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import net.aksingh.owmjapis.api.APIException;
|
||||
import net.thauvin.erik.mobibot.LocalProperties;
|
||||
import net.thauvin.erik.mobibot.msg.Message;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
/**
|
||||
* The <code>Weather2Test</code> class.
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2019-04-09
|
||||
* @since 1.0
|
||||
*/
|
||||
public class Weather2Test extends LocalProperties {
|
||||
@SuppressFBWarnings("PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS")
|
||||
@Test
|
||||
public void testWeather() throws ModuleException {
|
||||
List<Message> messages = Weather2.getWeather("98204", getProperty(Weather2.OWM_API_KEY_PROP));
|
||||
assertThat(messages.get(0).getMsg()).as("is Everett").contains("Everett").contains("US");
|
||||
assertThat(messages.get(messages.size() - 1).getMsg()).as("is City Search").endsWith("98204%2CUS");
|
||||
|
||||
messages = Weather2.getWeather("London, UK", getProperty(Weather2.OWM_API_KEY_PROP));
|
||||
assertThat(messages.get(0).getMsg()).as("is UK").contains("London").contains("UK");
|
||||
assertThat(messages.get(messages.size() - 1).getMsg()).as("is City Code").endsWith("4517009");
|
||||
|
||||
assertThatThrownBy(() -> Weather2.getWeather("Montpellier, FR", getProperty(Weather2.OWM_API_KEY_PROP)))
|
||||
.as("Montpellier not found").hasCauseInstanceOf(APIException.class);
|
||||
|
||||
assertThatThrownBy(() -> Weather2.getWeather("test", ""))
|
||||
.as("no API key").isInstanceOf(ModuleException.class).hasNoCause();
|
||||
|
||||
messages = Weather2.getWeather("", "apikey");
|
||||
assertThat(messages.get(0).isError()).as("no query").isTrue();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWeather2Impl() {
|
||||
AbstractModuleTest.testAbstractModule(new Weather2(null));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Weather2Test.kt
|
||||
*
|
||||
* Copyright (c) 2004-2019, Erik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of this project nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.thauvin.erik.mobibot.modules
|
||||
|
||||
import net.aksingh.owmjapis.api.APIException
|
||||
import net.thauvin.erik.mobibot.LocalProperties
|
||||
import net.thauvin.erik.mobibot.modules.Weather2.Companion.getWeather
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.testng.annotations.Test
|
||||
|
||||
/**
|
||||
* The `Weather2Test` class.
|
||||
*/
|
||||
class Weather2Test : LocalProperties() {
|
||||
@Test
|
||||
@Throws(ModuleException::class)
|
||||
fun testWeather() {
|
||||
var messages = getWeather("98204", getProperty(Weather2.OWM_API_KEY_PROP))
|
||||
Assertions.assertThat(messages[0].msg).`as`("is Everett").contains("Everett").contains("US")
|
||||
Assertions.assertThat(messages[messages.size - 1].msg).`as`("is City Search").endsWith("98204%2CUS")
|
||||
messages = getWeather("London, UK", getProperty(Weather2.OWM_API_KEY_PROP))
|
||||
Assertions.assertThat(messages[0].msg).`as`("is UK").contains("London").contains("UK")
|
||||
Assertions.assertThat(messages[messages.size - 1].msg).`as`("is City Code").endsWith("4517009")
|
||||
Assertions.assertThatThrownBy { getWeather("Montpellier, FR", getProperty(Weather2.OWM_API_KEY_PROP)) }
|
||||
.`as`("Montpellier not found").hasCauseInstanceOf(APIException::class.java)
|
||||
Assertions.assertThatThrownBy { getWeather("test", "") }
|
||||
.`as`("no API key").isInstanceOf(ModuleException::class.java).hasNoCause()
|
||||
messages = getWeather("", "apikey")
|
||||
Assertions.assertThat(messages[0].isError).`as`("no query").isTrue
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* WordTimeTest.kt
|
||||
*
|
||||
* Copyright (c) 2004-2019, Erik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of this project nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.thauvin.erik.mobibot.modules
|
||||
|
||||
import net.thauvin.erik.mobibot.Utils
|
||||
import net.thauvin.erik.mobibot.modules.WorldTime.Companion.worldTime
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.testng.annotations.Test
|
||||
|
||||
/**
|
||||
* The `WordTimeTest` class.
|
||||
*/
|
||||
class WordTimeTest {
|
||||
@Test
|
||||
fun testWorldTime() {
|
||||
Assertions.assertThat(worldTime("PST").msg).`as`("PST").endsWith(Utils.bold("Los Angeles"))
|
||||
Assertions.assertThat(worldTime("BLAH").isError).`as`("BLAH").isTrue
|
||||
Assertions.assertThat(worldTime("BEATS").msg).`as`("BEATS").contains("@")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue