Converted Message to Kotlin.
This commit is contained in:
parent
bde70343b7
commit
4048636696
17 changed files with 196 additions and 284 deletions
|
@ -970,7 +970,7 @@ public class Mobibot extends PircBot {
|
|||
* @param message The message.
|
||||
*/
|
||||
public final void send(final String who, final Message message) {
|
||||
send(message.isNotice() ? who : getChannel(), message.getMessage(), message.getColor(), message.isPrivate());
|
||||
send(message.isNotice() ? who : getChannel(), message.getText(), message.getColor(), message.isPrivate());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -118,7 +118,7 @@ public final class Joke extends ThreadedModule {
|
|||
@Override
|
||||
void run(final Mobibot bot, final String sender, final String cmd, final String arg, final boolean isPrivate) {
|
||||
try {
|
||||
bot.send(Utils.cyan(randomJoke().getMessage()));
|
||||
bot.send(Utils.cyan(randomJoke().getText()));
|
||||
} catch (ModuleException e) {
|
||||
bot.getLogger().warn(e.getDebugMessage(), e);
|
||||
bot.send(sender, e.getMessage(), isPrivate);
|
||||
|
|
|
@ -142,7 +142,7 @@ public final class Twitter extends ThreadedModule {
|
|||
void run(final Mobibot bot, final String sender, final String cmd, final String message, final boolean isPrivate) {
|
||||
try {
|
||||
bot.send(sender,
|
||||
post(sender, message + " (by " + sender + " on " + bot.getChannel() + ')', false).getMessage(),
|
||||
post(sender, message + " (by " + sender + " on " + bot.getChannel() + ')', false).getText(),
|
||||
isPrivate);
|
||||
} catch (ModuleException e) {
|
||||
bot.getLogger().warn(e.getDebugMessage(), e);
|
||||
|
|
|
@ -229,12 +229,12 @@ public final class WorldTime extends AbstractModule {
|
|||
} else {
|
||||
final Message msg = worldTime(args);
|
||||
if (isPrivate) {
|
||||
bot.send(sender, msg.getMessage(), true);
|
||||
bot.send(sender, msg.getText(), true);
|
||||
} else {
|
||||
if (msg.isError()) {
|
||||
bot.send(sender, msg.getMessage(), false);
|
||||
bot.send(sender, msg.getText(), false);
|
||||
} else {
|
||||
bot.send(msg.getMessage());
|
||||
bot.send(msg.getText());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,41 +29,38 @@
|
|||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.thauvin.erik.mobibot.msg;
|
||||
package net.thauvin.erik.mobibot.msg
|
||||
|
||||
/**
|
||||
* The <code>ErrorMessage</code> class.
|
||||
* The `ErrorMessage` class.
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/" target="_blank">Erik C. Thauvin</a>
|
||||
* @author [Erik C. Thauvin](https://erik.thauvin.net/)
|
||||
* @created 2019-04-07
|
||||
* @since 1.0
|
||||
*/
|
||||
public class ErrorMessage extends Message {
|
||||
class ErrorMessage : Message {
|
||||
/**
|
||||
* Creates a new error message.
|
||||
*
|
||||
* @param message The error message.
|
||||
* @param text The error message.
|
||||
*/
|
||||
public ErrorMessage(final String message) {
|
||||
super();
|
||||
this.setMessage(message);
|
||||
this.setError(true);
|
||||
this.setNotice(true);
|
||||
constructor(text: String) : super() {
|
||||
this.text = text
|
||||
isError = true
|
||||
isNotice = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new error message.
|
||||
*
|
||||
* @param message The message.
|
||||
* @param color The message color.
|
||||
* @param text The message.
|
||||
* @param color The message color.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public ErrorMessage(final String message, final String color) {
|
||||
super();
|
||||
this.setMessage(message);
|
||||
this.setError(true);
|
||||
this.setNotice(true);
|
||||
this.setColor(color);
|
||||
@Suppress("unused")
|
||||
constructor(text: String, color: String) : super() {
|
||||
this.text = text
|
||||
isError = true
|
||||
isNotice = true
|
||||
this.color = color
|
||||
}
|
||||
}
|
|
@ -1,193 +0,0 @@
|
|||
/*
|
||||
* Message.java
|
||||
*
|
||||
* Copyright (c) 2004-2020, Erik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of this project nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.thauvin.erik.mobibot.msg;
|
||||
|
||||
import org.jibble.pircbot.Colors;
|
||||
|
||||
/**
|
||||
* The <code>Message</code> class.
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/" target="_blank">Erik C. Thauvin</a>
|
||||
* @created 2019-04-07
|
||||
* @since 1.0
|
||||
*/
|
||||
public class Message {
|
||||
private String color = Colors.NORMAL;
|
||||
private boolean isError;
|
||||
private boolean isNotice;
|
||||
private boolean isPrivate;
|
||||
private String msg = "";
|
||||
|
||||
/**
|
||||
* Creates a new message.
|
||||
*/
|
||||
public Message() {
|
||||
// This constructor is intentionally empty
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new message.
|
||||
*
|
||||
* @param message The message.
|
||||
* @param isNotice The notice flag.
|
||||
* @param isError The error flag.
|
||||
* @param isPrivate The Private message
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public Message(final String message, final boolean isNotice, final boolean isError, final boolean isPrivate) {
|
||||
msg = message;
|
||||
this.isNotice = isNotice;
|
||||
this.isError = isError;
|
||||
this.isPrivate = isPrivate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new message.
|
||||
*
|
||||
* @param message The message.
|
||||
* @param isNotice The notice flag.
|
||||
* @param isError The error flag.
|
||||
* @param isPrivate The Private message
|
||||
* @param color The color.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public Message(final String message,
|
||||
final boolean isNotice,
|
||||
final boolean isError,
|
||||
final boolean isPrivate,
|
||||
final String color) {
|
||||
msg = message;
|
||||
this.isNotice = isNotice;
|
||||
this.isError = isError;
|
||||
this.isPrivate = isPrivate;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the message color.
|
||||
*
|
||||
* @return The color.
|
||||
*/
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the message.
|
||||
*
|
||||
* @return The message.
|
||||
*/
|
||||
public String getMessage() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the message error flag.
|
||||
*
|
||||
* @return The error flag.
|
||||
*/
|
||||
public boolean isError() {
|
||||
return isError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the message notice flag.
|
||||
*
|
||||
* @return The notice flag.
|
||||
*/
|
||||
public boolean isNotice() {
|
||||
return isNotice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the message private flag.
|
||||
*
|
||||
* @return The private flag.
|
||||
*/
|
||||
public boolean isPrivate() {
|
||||
return isPrivate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the color.
|
||||
*
|
||||
* @param color The new color.
|
||||
*/
|
||||
public void setColor(final String color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the message error flag.
|
||||
*
|
||||
* @param error The error flag.
|
||||
*/
|
||||
public void setError(final boolean error) {
|
||||
isError = error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the message.
|
||||
*
|
||||
* @param message The new message.
|
||||
*/
|
||||
public void setMessage(final String message) {
|
||||
msg = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the message notice flag.
|
||||
*
|
||||
* @param isNotice The notice flag.
|
||||
*/
|
||||
public void setNotice(final boolean isNotice) {
|
||||
this.isNotice = isNotice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the message private flag.
|
||||
*
|
||||
* @param isPrivate The private flag.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public void setPrivate(final boolean isPrivate) {
|
||||
this.isPrivate = isPrivate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Message{" + "color='" + color + '\'' + ", isError=" + isError + ", isNotice=" + isNotice
|
||||
+ ", isPrivate=" + isPrivate + ", msg='" + msg + '\'' + '}';
|
||||
}
|
||||
}
|
105
src/main/java/net/thauvin/erik/mobibot/msg/Message.kt
Normal file
105
src/main/java/net/thauvin/erik/mobibot/msg/Message.kt
Normal file
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* Message.java
|
||||
*
|
||||
* Copyright (c) 2004-2020, Erik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of this project nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.thauvin.erik.mobibot.msg
|
||||
|
||||
import org.jibble.pircbot.Colors
|
||||
|
||||
/**
|
||||
* The `Message` class.
|
||||
*
|
||||
* @author [Erik C. Thauvin](https://erik.thauvin.net/)
|
||||
* @created 2019-04-07
|
||||
* @since 1.0
|
||||
*/
|
||||
open class Message {
|
||||
/** Color */
|
||||
var color = Colors.NORMAL
|
||||
|
||||
/** Error */
|
||||
var isError = false
|
||||
|
||||
/** Notice */
|
||||
var isNotice = false
|
||||
|
||||
/** Private */
|
||||
var isPrivate = false
|
||||
|
||||
/** Message text*/
|
||||
var text = ""
|
||||
|
||||
/** Creates a new message. */
|
||||
constructor() {
|
||||
// This constructor is intentionally empty
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new message.
|
||||
*
|
||||
* @param text The message.
|
||||
* @param isNotice The notice flag.
|
||||
* @param isError The error flag.
|
||||
* @param isPrivate The Private message
|
||||
*/
|
||||
constructor(text: String, isNotice: Boolean, isError: Boolean, isPrivate: Boolean) {
|
||||
this.text = text
|
||||
this.isNotice = isNotice
|
||||
this.isError = isError
|
||||
this.isPrivate = isPrivate
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new message.
|
||||
*
|
||||
* @param text The message.
|
||||
* @param isNotice The notice flag.
|
||||
* @param isError The error flag.
|
||||
* @param isPrivate The Private message
|
||||
* @param color The color.
|
||||
*/
|
||||
constructor(
|
||||
text: String,
|
||||
isNotice: Boolean,
|
||||
isError: Boolean,
|
||||
isPrivate: Boolean,
|
||||
color: String
|
||||
) {
|
||||
this.text = text
|
||||
this.isNotice = isNotice
|
||||
this.isError = isError
|
||||
this.isPrivate = isPrivate
|
||||
this.color = color
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "Message(color='$color', isError=$isError, isNotice=$isNotice, isPrivate=$isPrivate, message='$text')"
|
||||
}
|
||||
}
|
|
@ -29,38 +29,35 @@
|
|||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.thauvin.erik.mobibot.msg;
|
||||
package net.thauvin.erik.mobibot.msg
|
||||
|
||||
/**
|
||||
* The <code>NoticeMessage</code> class.
|
||||
* The `NoticeMessage` class.
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/" target="_blank">Erik C. Thauvin</a>
|
||||
* @author [Erik C. Thauvin](https://erik.thauvin.net/)
|
||||
* @created 2019-04-07
|
||||
* @since 1.0
|
||||
*/
|
||||
public class NoticeMessage extends Message {
|
||||
class NoticeMessage : Message {
|
||||
/**
|
||||
* Creates a new notice.
|
||||
*
|
||||
* @param message The notice's message.
|
||||
* @param text The notice's message.
|
||||
*/
|
||||
public NoticeMessage(final String message) {
|
||||
super();
|
||||
this.setMessage(message);
|
||||
this.setNotice(true);
|
||||
constructor(text: String) : super() {
|
||||
this.text = text
|
||||
isNotice = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new notice.
|
||||
*
|
||||
* @param message The notice's message.
|
||||
* @param color The color.
|
||||
* @param text The notice's message.
|
||||
* @param color The color.
|
||||
*/
|
||||
public NoticeMessage(final String message, final String color) {
|
||||
super();
|
||||
this.setMessage(message);
|
||||
this.setNotice(true);
|
||||
this.setColor(color);
|
||||
constructor(text: String, color: String) : super() {
|
||||
this.text = text
|
||||
isNotice = true
|
||||
this.color = color
|
||||
}
|
||||
}
|
|
@ -29,32 +29,36 @@
|
|||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.thauvin.erik.mobibot.msg;
|
||||
package net.thauvin.erik.mobibot.msg
|
||||
|
||||
/**
|
||||
* The <code>PrivateMessage</code> class.
|
||||
* The `PrivateMessage` class.
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/" target="_blank">Erik C. Thauvin</a>
|
||||
* @author [Erik C. Thauvin](https://erik.thauvin.net/)
|
||||
* @created 2019-04-09
|
||||
* @since 1.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class PrivateMessage extends Message {
|
||||
public PrivateMessage(final String message) {
|
||||
super();
|
||||
this.setMessage(message);
|
||||
@Suppress("unused")
|
||||
class PrivateMessage : Message {
|
||||
/**
|
||||
* Creates a new private message.
|
||||
*
|
||||
* @param text The message.
|
||||
*/
|
||||
constructor(text: String) : super() {
|
||||
this.text = text
|
||||
isPrivate = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new private message.
|
||||
*
|
||||
* @param message The message.
|
||||
* @param color The message color.
|
||||
* @param text The message.
|
||||
* @param color The message color.
|
||||
*/
|
||||
public PrivateMessage(final String message, final String color) {
|
||||
super();
|
||||
this.setMessage(message);
|
||||
this.setColor(color);
|
||||
constructor(text: String, color: String) : super() {
|
||||
this.text = text
|
||||
this.color = color
|
||||
isPrivate = true
|
||||
}
|
||||
}
|
|
@ -29,32 +29,34 @@
|
|||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.thauvin.erik.mobibot.msg;
|
||||
package net.thauvin.erik.mobibot.msg
|
||||
|
||||
/**
|
||||
* The <code>PublicMessage</code> class.
|
||||
* The `PublicMessage` class.
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/" target="_blank">Erik C. Thauvin</a>
|
||||
* @author [Erik C. Thauvin](https://erik.thauvin.net/)
|
||||
* @created 2019-04-07
|
||||
* @since 1.0
|
||||
*/
|
||||
public class PublicMessage extends Message {
|
||||
public PublicMessage(final String message) {
|
||||
super();
|
||||
this.setMessage(message);
|
||||
class PublicMessage : Message {
|
||||
/**
|
||||
* Creates a new public message.
|
||||
*
|
||||
* @param text The message.
|
||||
*/
|
||||
constructor(text: String) : super() {
|
||||
this.text = text
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new public message.
|
||||
*
|
||||
* @param message The message.
|
||||
* @param color The message color.
|
||||
* @param text The message.
|
||||
* @param color The message color.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public PublicMessage(final String message, final String color) {
|
||||
super();
|
||||
this.setMessage(message);
|
||||
this.setColor(color);
|
||||
@Suppress("unused")
|
||||
constructor(text: String, color: String) : super() {
|
||||
this.text = text
|
||||
this.color = color
|
||||
}
|
||||
}
|
|
@ -54,11 +54,11 @@ public class CurrencyConverterTest {
|
|||
@Test
|
||||
@SuppressFBWarnings("PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS")
|
||||
public void testConvertCurrency() {
|
||||
assertThat(CurrencyConverter.convertCurrency("100 USD to EUR").getMessage())
|
||||
assertThat(CurrencyConverter.convertCurrency("100 USD to EUR").getText())
|
||||
.as("100 USD to EUR").matches("100\\.00 USD = \\d{2,3}\\.\\d{2} EUR");
|
||||
assertThat(CurrencyConverter.convertCurrency("100 USD to USD").getMessage())
|
||||
assertThat(CurrencyConverter.convertCurrency("100 USD to USD").getText())
|
||||
.as("100 USD to USD").contains("You're kidding, right?");
|
||||
assertThat(CurrencyConverter.convertCurrency("100 USD").getMessage())
|
||||
assertThat(CurrencyConverter.convertCurrency("100 USD").getText())
|
||||
.as("100 USD").contains("Invalid query.");
|
||||
assertThat(CurrencyConverter.currencyRates().size())
|
||||
.as("currencyRates().size() == 33").isEqualTo(33);
|
||||
|
|
|
@ -63,20 +63,20 @@ public class GoogleSearchTest extends LocalProperties {
|
|||
try {
|
||||
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");
|
||||
assertThat(messages.get(0).getText()).as("found mobitopia").contains("mobibot");
|
||||
|
||||
messages = GoogleSearch.searchGoogle("aapl", apiKey, cseKey);
|
||||
assertThat(messages).as("aapl results not empty").isNotEmpty();
|
||||
assertThat(messages.get(0).getMessage()).as("found apple").containsIgnoringCase("apple");
|
||||
assertThat(messages.get(0).getText()).as("found apple").containsIgnoringCase("apple");
|
||||
|
||||
assertThatThrownBy(() -> GoogleSearch.searchGoogle("test", "", "apiKey")).as("no API key").isInstanceOf(
|
||||
ModuleException.class).hasNoCause();
|
||||
ModuleException.class).hasNoCause();
|
||||
|
||||
assertThatThrownBy(() -> GoogleSearch.searchGoogle("test", "apiKey", "")).as("no CSE API key").isInstanceOf(
|
||||
ModuleException.class).hasNoCause();
|
||||
ModuleException.class).hasNoCause();
|
||||
|
||||
assertThatThrownBy(() -> GoogleSearch.searchGoogle("", "apikey", "apiKey")).as("no query").isInstanceOf(
|
||||
ModuleException.class).hasNoCause();
|
||||
ModuleException.class).hasNoCause();
|
||||
} catch (ModuleException e) {
|
||||
// Avoid displaying api keys in CI logs
|
||||
if ("true".equals(System.getenv("CI"))) {
|
||||
|
|
|
@ -51,7 +51,7 @@ public class JokeTest {
|
|||
|
||||
@Test
|
||||
public void testRamdomJoke() throws ModuleException {
|
||||
assertThat(Joke.randomJoke().getMessage().length() > 0).as("randomJoke() > 0").isTrue();
|
||||
assertThat(Joke.randomJoke().getMessage()).as("randomJoke()").containsIgnoringCase("chuck");
|
||||
assertThat(Joke.randomJoke().getText().length() > 0).as("randomJoke() > 0").isTrue();
|
||||
assertThat(Joke.randomJoke().getText()).as("randomJoke()").containsIgnoringCase("chuck");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ public class StockQuoteTest extends LocalProperties {
|
|||
try {
|
||||
final List<Message> messages = StockQuote.getQuote("apple inc", apiKey);
|
||||
assertThat(messages).as("response not empty").isNotEmpty();
|
||||
assertThat(messages.get(0).getMessage()).as("same stock symbol").contains("AAPL").contains("Apple Inc.");
|
||||
assertThat(messages.get(0).getText()).as("same stock symbol").contains("AAPL").contains("Apple Inc.");
|
||||
|
||||
try {
|
||||
StockQuote.getQuote("012", apiKey);
|
||||
|
|
|
@ -74,6 +74,6 @@ public class TwitterTest {
|
|||
LocalProperties.getProperty(Twitter.TOKEN_SECRET_PROP),
|
||||
LocalProperties.getProperty(Constants.TWITTER_HANDLE_PROP),
|
||||
msg,
|
||||
true).getMessage()).as("twitterPost(" + msg + ')').isEqualTo(msg);
|
||||
true).getText()).as("twitterPost(" + msg + ')').isEqualTo(msg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,12 +54,12 @@ public class Weather2Test extends LocalProperties {
|
|||
@Test
|
||||
public void testWeather() throws ModuleException {
|
||||
List<Message> messages = Weather2.getWeather("98204", LocalProperties.getProperty(Weather2.OWM_API_KEY_PROP));
|
||||
assertThat(messages.get(0).getMessage()).as("is Everett").contains("Everett").contains("US");
|
||||
assertThat(messages.get(messages.size() - 1).getMessage()).as("is City Search").endsWith("98204%2CUS");
|
||||
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));
|
||||
assertThat(messages.get(0).getMessage()).as("is UK").contains("London").contains("UK");
|
||||
assertThat(messages.get(messages.size() - 1).getMessage()).as("is City Code").endsWith("4517009");
|
||||
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(
|
||||
|
|
|
@ -47,9 +47,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
public class WordTimeTest {
|
||||
@Test
|
||||
public void testWorldTime() {
|
||||
assertThat(WorldTime.worldTime("PST").getMessage()).as("PST").endsWith(Utils.bold("Los Angeles"));
|
||||
assertThat(WorldTime.worldTime("PST").getText()).as("PST").endsWith(Utils.bold("Los Angeles"));
|
||||
assertThat(WorldTime.worldTime("BLAH").isError()).as("BLAH").isTrue();
|
||||
assertThat(WorldTime.worldTime("BEATS").getMessage()).as("BEATS").contains("@");
|
||||
assertThat(WorldTime.worldTime("BEATS").getText()).as("BEATS").contains("@");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue