Reworked exception testing.
This commit is contained in:
parent
65b61aa5a3
commit
65dcbcc4e3
3 changed files with 24 additions and 42 deletions
|
@ -39,6 +39,7 @@ 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.
|
||||
|
@ -68,26 +69,14 @@ public class GoogleSearchTest extends LocalProperties {
|
|||
assertThat(messages).as("aapl results not empty").isNotEmpty();
|
||||
assertThat(messages.get(0).getMessage()).as("found apple").containsIgnoringCase("apple");
|
||||
|
||||
try {
|
||||
GoogleSearch.searchGoogle("test", "", "apiKey");
|
||||
} catch (Exception e) {
|
||||
assertThat(e).as("no API key").isInstanceOf(ModuleException.class);
|
||||
assertThat(e).as("no API key exception has no cause").hasNoCause();
|
||||
}
|
||||
assertThatThrownBy(() -> GoogleSearch.searchGoogle("test", "", "apiKey")).as("no API key").isInstanceOf(
|
||||
ModuleException.class).hasNoCause();
|
||||
|
||||
try {
|
||||
GoogleSearch.searchGoogle("test", "apiKey", "");
|
||||
} catch (Exception e) {
|
||||
assertThat(e).as("no CSE API key").isInstanceOf(ModuleException.class);
|
||||
assertThat(e).as("no CSE API key exception has no cause").hasNoCause();
|
||||
}
|
||||
assertThatThrownBy(() -> GoogleSearch.searchGoogle("test", "apiKey", "")).as("no CSE API key").isInstanceOf(
|
||||
ModuleException.class).hasNoCause();
|
||||
|
||||
try {
|
||||
GoogleSearch.searchGoogle("", "apikey", "apiKey");
|
||||
} catch (Exception e) {
|
||||
assertThat(e).as("no query").isInstanceOf(ModuleException.class);
|
||||
assertThat(e).as("no query exception has no cause").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"))) {
|
||||
|
|
|
@ -39,6 +39,7 @@ 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.
|
||||
|
@ -62,19 +63,11 @@ public class StockQuoteTest extends LocalProperties {
|
|||
messages = StockQuote.getQuote("012", apiKey);
|
||||
assertThat(messages.get(0).isError()).as("invalid symbol error").isTrue();
|
||||
|
||||
try {
|
||||
StockQuote.getQuote("test", "");
|
||||
} catch (Exception e) {
|
||||
assertThat(e).as("no API key").isInstanceOf(ModuleException.class);
|
||||
assertThat(e).as("no API key exception has no cause").hasNoCause();
|
||||
}
|
||||
assertThatThrownBy(() -> StockQuote.getQuote("test", "")).as("no API key").isInstanceOf(
|
||||
ModuleException.class).hasNoCause();
|
||||
|
||||
try {
|
||||
StockQuote.getQuote("", "apikey");
|
||||
} catch (Exception e) {
|
||||
assertThat(e).as("no symbol").isInstanceOf(ModuleException.class);
|
||||
assertThat(e).as("no symbol exception has no cause").hasNoCause();
|
||||
}
|
||||
assertThatThrownBy(() -> StockQuote.getQuote("", "apikey")).as("no symbol").isInstanceOf(
|
||||
ModuleException.class).hasNoCause();
|
||||
|
||||
} catch (ModuleException e) {
|
||||
// Avoid displaying api keys in CI logs.
|
||||
|
|
|
@ -33,12 +33,14 @@
|
|||
package net.thauvin.erik.mobibot.modules;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import net.aksingh.owmjapis.api.APIException;
|
||||
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.
|
||||
|
@ -59,19 +61,17 @@ public class Weather2Test extends LocalProperties {
|
|||
assertThat(messages.get(0).getMessage()).as("is UK").contains("UK");
|
||||
assertThat(messages.get(messages.size() - 1).getMessage()).as("is City Code").endsWith("4298960");
|
||||
|
||||
try {
|
||||
Weather2.getWeather("test", "");
|
||||
} catch (Exception e) {
|
||||
assertThat(e).as("no API key").isInstanceOf(ModuleException.class);
|
||||
assertThat(e).as("no API key exception has no cause").hasNoCause();
|
||||
}
|
||||
assertThatThrownBy(
|
||||
() -> Weather2.getWeather("Montpellier, FR", LocalProperties.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 api key.").isTrue();
|
||||
|
||||
try {
|
||||
Weather2.getWeather("", "apikey");
|
||||
} catch (Exception e) {
|
||||
assertThat(e).as("no query").isInstanceOf(ModuleException.class);
|
||||
assertThat(e).as("no query exception has no cause").hasNoCause();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue