Workaround for API change for invalid symbol.
This commit is contained in:
parent
8484e2fc0c
commit
1cabb74eb8
2 changed files with 12 additions and 4 deletions
|
@ -113,8 +113,13 @@ public final class StockQuote extends ThreadedModule {
|
||||||
try {
|
try {
|
||||||
final String error = json.getString("Error Message");
|
final String error = json.getString("Error Message");
|
||||||
if (!error.isEmpty()) {
|
if (!error.isEmpty()) {
|
||||||
|
if (error.startsWith("Invalid API call.")) {
|
||||||
|
throw new ModuleException(debugMessage + ": " + Utils.unescapeXml(error),
|
||||||
|
"Invalid symbol.");
|
||||||
|
} else {
|
||||||
throw new ModuleException(debugMessage, Utils.unescapeXml(error));
|
throw new ModuleException(debugMessage, Utils.unescapeXml(error));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (JSONException ignore) {
|
} catch (JSONException ignore) {
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,12 +56,15 @@ public class StockQuoteTest extends LocalProperties {
|
||||||
public void testGetQuote() throws ModuleException {
|
public void testGetQuote() throws ModuleException {
|
||||||
final String apiKey = LocalProperties.getProperty(StockQuote.ALPHAVANTAGE_API_KEY_PROP);
|
final String apiKey = LocalProperties.getProperty(StockQuote.ALPHAVANTAGE_API_KEY_PROP);
|
||||||
try {
|
try {
|
||||||
List<Message> messages = StockQuote.getQuote("AAPL", apiKey);
|
final List<Message> messages = StockQuote.getQuote("AAPL", apiKey);
|
||||||
assertThat(messages).as("response not empty").isNotEmpty();
|
assertThat(messages).as("response not empty").isNotEmpty();
|
||||||
assertThat(messages.get(0).getMessage()).as("same stock symbol").contains("AAPL");
|
assertThat(messages.get(0).getMessage()).as("same stock symbol").contains("AAPL");
|
||||||
|
|
||||||
messages = StockQuote.getQuote("012", apiKey);
|
try {
|
||||||
assertThat(messages.get(0).isError()).as("invalid symbol error").isTrue();
|
StockQuote.getQuote("012", apiKey);
|
||||||
|
} catch (ModuleException e) {
|
||||||
|
assertThat(e.getMessage()).as("invalid symbol").containsIgnoringCase("invalid symbol");
|
||||||
|
}
|
||||||
|
|
||||||
assertThatThrownBy(() -> StockQuote.getQuote("test", "")).as("no API key").isInstanceOf(
|
assertThatThrownBy(() -> StockQuote.getQuote("test", "")).as("no API key").isInstanceOf(
|
||||||
ModuleException.class).hasNoCause();
|
ModuleException.class).hasNoCause();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue