Using List instead of ArrayList (PMD)

This commit is contained in:
Erik C. Thauvin 2019-04-27 02:37:21 -07:00
parent c3d4eb1ab8
commit bb23d7e79d
5 changed files with 15 additions and 10 deletions

View file

@ -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<Message> getQuote(final String symbol, final String apiKey) throws ModuleException {
static List<Message> 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<Message> messages = getQuote(symbol, properties.get(ALPHAVANTAGE_API_KEY_PROP));
final List<Message> messages = getQuote(symbol, properties.get(ALPHAVANTAGE_API_KEY_PROP));
for (final Message msg : messages) {
bot.send(sender, msg);
}

View file

@ -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<Message> getWeather(final String query, final String apiKey) throws ModuleException {
static List<Message> 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<Message> messages = getWeather(args, properties.get(OWM_API_KEY_PROP));
final List<Message> messages = getWeather(args, properties.get(OWM_API_KEY_PROP));
if (messages.get(0).isError()) {
helpResponse(bot, sender, args, true);
} else {

View file

@ -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<Message> messages = GoogleSearch.searchGoogle("mobibot site:github.com", apiKey, cseKey);
List<Message> 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");

View file

@ -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<Message> messages = StockQuote.getQuote("AAPL", apiKey);
List<Message> messages = StockQuote.getQuote("AAPL", apiKey);
assertThat(messages).as("response not empty").isNotEmpty();
assertThat(messages.get(0).getMessage()).as("same stock symbol").contains("AAPL");

View file

@ -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<Message> messages = Weather2.getWeather("98204",
List<Message> 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));