From bb23d7e79d1eb6bc9b080b7f660f9fe97ae25f6b Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sat, 27 Apr 2019 02:37:21 -0700 Subject: [PATCH] Using List instead of ArrayList (PMD) --- .../java/net/thauvin/erik/mobibot/modules/StockQuote.java | 6 ++++-- .../java/net/thauvin/erik/mobibot/modules/Weather2.java | 5 +++-- .../net/thauvin/erik/mobibot/modules/GoogleSearchTest.java | 5 +++-- .../net/thauvin/erik/mobibot/modules/StockQuoteTest.java | 5 +++-- .../java/net/thauvin/erik/mobibot/modules/Weather2Test.java | 4 ++-- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/StockQuote.java b/src/main/java/net/thauvin/erik/mobibot/modules/StockQuote.java index 23f0f80..9e09bef 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/StockQuote.java +++ b/src/main/java/net/thauvin/erik/mobibot/modules/StockQuote.java @@ -46,6 +46,7 @@ import org.json.JSONObject; import java.io.IOException; import java.util.ArrayList; +import java.util.List; /** * The StockQuote module. @@ -80,7 +81,7 @@ public final class StockQuote extends ThreadedModule { * @return The {@link Message} array containing the stock quote. * @throws ModuleException If an errors occurs. */ - static ArrayList getQuote(final String symbol, final String apiKey) throws ModuleException { + static List getQuote(final String symbol, final String apiKey) throws ModuleException { if (!Utils.isValidString(apiKey)) { throw new ModuleException(Utils.capitalize(STOCK_CMD) + " is disabled. The API key is missing."); } @@ -166,10 +167,11 @@ public final class StockQuote extends ThreadedModule { /** * Returns the specified stock quote from Alpha Advantage. */ + @Override void run(final Mobibot bot, final String sender, final String symbol) { if (Utils.isValidString(symbol)) { try { - final ArrayList messages = getQuote(symbol, properties.get(ALPHAVANTAGE_API_KEY_PROP)); + final List messages = getQuote(symbol, properties.get(ALPHAVANTAGE_API_KEY_PROP)); for (final Message msg : messages) { bot.send(sender, msg); } diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/Weather2.java b/src/main/java/net/thauvin/erik/mobibot/modules/Weather2.java index a9dae96..92804eb 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/Weather2.java +++ b/src/main/java/net/thauvin/erik/mobibot/modules/Weather2.java @@ -102,7 +102,7 @@ public class Weather2 extends ThreadedModule { * @return The {@link Message} array containing the weather data. * @throws ModuleException If an error occurs while retrieving the weather data. */ - static ArrayList getWeather(final String query, final String apiKey) throws ModuleException { + static List getWeather(final String query, final String apiKey) throws ModuleException { if (!Utils.isValidString(apiKey)) { throw new ModuleException(Utils.capitalize(WEATHER_CMD) + " is disabled. The API key is missing."); } @@ -204,10 +204,11 @@ public class Weather2 extends ThreadedModule { /** * Fetches the weather data from a specific city. */ + @Override void run(final Mobibot bot, final String sender, final String args) { if (Utils.isValidString(args)) { try { - final ArrayList messages = getWeather(args, properties.get(OWM_API_KEY_PROP)); + final List messages = getWeather(args, properties.get(OWM_API_KEY_PROP)); if (messages.get(0).isError()) { helpResponse(bot, sender, args, true); } else { diff --git a/src/test/java/net/thauvin/erik/mobibot/modules/GoogleSearchTest.java b/src/test/java/net/thauvin/erik/mobibot/modules/GoogleSearchTest.java index c81b883..88e005c 100644 --- a/src/test/java/net/thauvin/erik/mobibot/modules/GoogleSearchTest.java +++ b/src/test/java/net/thauvin/erik/mobibot/modules/GoogleSearchTest.java @@ -36,7 +36,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import net.thauvin.erik.mobibot.msg.Message; import org.testng.annotations.Test; -import java.util.ArrayList; +import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @@ -54,12 +54,13 @@ public class GoogleSearchTest extends LocalProperties { } @SuppressFBWarnings("LEST_LOST_EXCEPTION_STACK_TRACE") + @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); try { - ArrayList messages = GoogleSearch.searchGoogle("mobibot site:github.com", apiKey, cseKey); + List messages = GoogleSearch.searchGoogle("mobibot site:github.com", apiKey, cseKey); assertThat(messages).as("mobibot results not empty").isNotEmpty(); assertThat(messages.get(0).getMessage()).as("found mobitopia").contains("mobibot"); diff --git a/src/test/java/net/thauvin/erik/mobibot/modules/StockQuoteTest.java b/src/test/java/net/thauvin/erik/mobibot/modules/StockQuoteTest.java index b4fff14..488de37 100644 --- a/src/test/java/net/thauvin/erik/mobibot/modules/StockQuoteTest.java +++ b/src/test/java/net/thauvin/erik/mobibot/modules/StockQuoteTest.java @@ -36,7 +36,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import net.thauvin.erik.mobibot.msg.Message; import org.testng.annotations.Test; -import java.util.ArrayList; +import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @@ -50,11 +50,12 @@ import static org.assertj.core.api.Assertions.assertThat; 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 { - ArrayList messages = StockQuote.getQuote("AAPL", apiKey); + List messages = StockQuote.getQuote("AAPL", apiKey); assertThat(messages).as("response not empty").isNotEmpty(); assertThat(messages.get(0).getMessage()).as("same stock symbol").contains("AAPL"); diff --git a/src/test/java/net/thauvin/erik/mobibot/modules/Weather2Test.java b/src/test/java/net/thauvin/erik/mobibot/modules/Weather2Test.java index 2ac1b0a..6f549dc 100644 --- a/src/test/java/net/thauvin/erik/mobibot/modules/Weather2Test.java +++ b/src/test/java/net/thauvin/erik/mobibot/modules/Weather2Test.java @@ -36,7 +36,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import net.thauvin.erik.mobibot.msg.Message; import org.testng.annotations.Test; -import java.util.ArrayList; +import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @@ -51,7 +51,7 @@ public class Weather2Test extends LocalProperties { @SuppressFBWarnings("PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS") @Test public void testWeather() throws ModuleException { - ArrayList messages = Weather2.getWeather("98204", + List messages = Weather2.getWeather("98204", LocalProperties.getProperty(Weather2.OWM_API_KEY_PROP)); assertThat(messages.get(0).getMessage()).as("is Everett").contains("Everett"); messages = Weather2.getWeather("London, UK", LocalProperties.getProperty(Weather2.OWM_API_KEY_PROP));