Added more tests.

This commit is contained in:
Erik C. Thauvin 2019-04-08 01:42:17 -07:00
parent d592536aca
commit 24a7d5ad56
2 changed files with 6 additions and 7 deletions

View file

@ -88,13 +88,11 @@ public final class Joke extends AbstractModule {
final JSONObject json = new JSONObject(sb.toString()); final JSONObject json = new JSONObject(sb.toString());
return new PublicMessage( return new PublicMessage(
Colors.CYAN json.getJSONObject("value").get("joke").toString().replaceAll("\\'", "'")
+ json.getJSONObject("value").get("joke").toString().replaceAll("\\'", "'") .replaceAll("\\\"", "\""));
.replaceAll("\\\"", "\"")
+ Colors.NORMAL);
} }
} catch (Exception e) { } catch (Exception e) {
throw new ModuleException("An error has occurred retrieving a random joke.", e); throw new ModuleException("randomJoke()", "An error has occurred retrieving a random joke.", e);
} }
} }
@ -120,7 +118,7 @@ public final class Joke extends AbstractModule {
*/ */
private void run(final Mobibot bot, final String sender) { private void run(final Mobibot bot, final String sender) {
try { try {
randomJoke(); bot.send(bot.getChannel(), Colors.CYAN + randomJoke().getMessage() + Colors.NORMAL);
} catch (ModuleException e) { } catch (ModuleException e) {
bot.getLogger().warn(e.getDebugMessage(), e); bot.getLogger().warn(e.getDebugMessage(), e);
bot.send(sender, e.getMessage()); bot.send(sender, e.getMessage());

View file

@ -50,6 +50,7 @@ public class JokeTest {
@Test @Test
public void testRamdomJoke() throws ModuleException { public void testRamdomJoke() throws ModuleException {
assertThat(Joke.randomJoke().getMessage().length() > 0).as("randomJoke()").isTrue(); assertThat(Joke.randomJoke().getMessage().length() > 0).as("randomJoke() > 0").isTrue();
assertThat(Joke.randomJoke().getMessage()).as("randomJoke()").contains("Chuck");
} }
} }