This commit is contained in:
Erik C. Thauvin 2020-04-27 23:19:16 -07:00
parent 34636ea9f9
commit aba2633dc4
12 changed files with 145 additions and 164 deletions

View file

@ -58,8 +58,8 @@ public class GoogleSearchTest extends LocalProperties {
@SuppressWarnings("PMD.PreserveStackTrace")
@Test
public void testSearchGoogle() throws ModuleException {
final String apiKey = LocalProperties.getProperty(GoogleSearch.GOOGLE_API_KEY_PROP);
final String cseKey = LocalProperties.getProperty(GoogleSearch.GOOGLE_CSE_KEY_PROP);
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();

View file

@ -40,18 +40,25 @@ class RockPaperScissorsTest {
@Test
fun testWinLoseOrDraw() {
assertThat(
RockPaperScissors.winLoseOrDraw("scissors", "paper")).`as`("scissors vs. paper").isEqualTo("win")
RockPaperScissors.winLoseOrDraw("scissors", "paper")
).`as`("scissors vs. paper").isEqualTo("win")
assertThat(
RockPaperScissors.winLoseOrDraw("paper", "rock")).`as`("paper vs. rock").isEqualTo("win")
RockPaperScissors.winLoseOrDraw("paper", "rock")
).`as`("paper vs. rock").isEqualTo("win")
assertThat(
RockPaperScissors.winLoseOrDraw("rock", "scissors")).`as`("rock vs. scissors").isEqualTo("win")
RockPaperScissors.winLoseOrDraw("rock", "scissors")
).`as`("rock vs. scissors").isEqualTo("win")
assertThat(
RockPaperScissors.winLoseOrDraw("paper", "scissors")).`as`("paper vs. scissors").isEqualTo("lose")
RockPaperScissors.winLoseOrDraw("paper", "scissors")
).`as`("paper vs. scissors").isEqualTo("lose")
assertThat(
RockPaperScissors.winLoseOrDraw("rock", "paper")).`as`("rock vs. paper").isEqualTo("lose")
RockPaperScissors.winLoseOrDraw("rock", "paper")
).`as`("rock vs. paper").isEqualTo("lose")
assertThat(
RockPaperScissors.winLoseOrDraw("scissors", "rock")).`as`("scissors vs. rock").isEqualTo("lose")
RockPaperScissors.winLoseOrDraw("scissors", "rock")
).`as`("scissors vs. rock").isEqualTo("lose")
assertThat(
RockPaperScissors.winLoseOrDraw("scissors", "scissors")).`as`("scissors vs. scissors").isEqualTo("draw")
RockPaperScissors.winLoseOrDraw("scissors", "scissors")
).`as`("scissors vs. scissors").isEqualTo("draw")
}
}

View file

@ -61,7 +61,7 @@ public class StockQuoteTest extends LocalProperties {
assertThat(messages.get(0).getText()).as("same stock symbol").contains("AAPL").contains("Apple Inc.");
try {
StockQuote.getQuote("012", apiKey);
StockQuote.getQuote("blahfoo", apiKey);
} catch (ModuleException e) {
assertThat(e.getMessage()).as("invalid symbol").containsIgnoringCase(StockQuote.INVALID_SYMBOL);
}

View file

@ -48,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @created 2019-04-19
* @since 1.0
*/
public class TwitterTest {
public class TwitterTest extends LocalProperties {
@SuppressFBWarnings("MDM")
private String getCi() {
if ("true".equals(System.getenv("CIRCLECI"))) {
@ -68,12 +68,12 @@ public class TwitterTest {
public void testPostTwitter() throws ModuleException {
final String msg = "Testing Twitter API from " + getCi();
assertThat(Twitter.twitterPost(
LocalProperties.getProperty(Twitter.CONSUMER_KEY_PROP),
LocalProperties.getProperty(Twitter.CONSUMER_SECRET_PROP),
LocalProperties.getProperty(Twitter.TOKEN_PROP),
LocalProperties.getProperty(Twitter.TOKEN_SECRET_PROP),
LocalProperties.getProperty(Constants.TWITTER_HANDLE_PROP),
msg,
true).getText()).as("twitterPost(" + msg + ')').isEqualTo(msg);
getProperty(Twitter.CONSUMER_KEY_PROP),
getProperty(Twitter.CONSUMER_SECRET_PROP),
getProperty(Twitter.TOKEN_PROP),
getProperty(Twitter.TOKEN_SECRET_PROP),
getProperty(Constants.TWITTER_HANDLE_PROP),
msg,
true).getText()).as("twitterPost(" + msg + ')').isEqualTo(msg);
}
}

View file

@ -53,21 +53,19 @@ public class Weather2Test extends LocalProperties {
@SuppressFBWarnings("PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS")
@Test
public void testWeather() throws ModuleException {
List<Message> messages = Weather2.getWeather("98204", LocalProperties.getProperty(Weather2.OWM_API_KEY_PROP));
List<Message> messages = Weather2.getWeather("98204", getProperty(Weather2.OWM_API_KEY_PROP));
assertThat(messages.get(0).getText()).as("is Everett").contains("Everett").contains("US");
assertThat(messages.get(messages.size() - 1).getText()).as("is City Search").endsWith("98204%2CUS");
messages = Weather2.getWeather("London, UK", LocalProperties.getProperty(Weather2.OWM_API_KEY_PROP));
messages = Weather2.getWeather("London, UK", getProperty(Weather2.OWM_API_KEY_PROP));
assertThat(messages.get(0).getText()).as("is UK").contains("London").contains("UK");
assertThat(messages.get(messages.size() - 1).getText()).as("is City Code").endsWith("4517009");
assertThatThrownBy(
() -> Weather2.getWeather("Montpellier, FR", LocalProperties.getProperty(Weather2.OWM_API_KEY_PROP))).as(
"Montpellier not found").hasCauseInstanceOf(APIException.class);
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();
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();