Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repositories {
}

dependencies {
implementation 'org.javacord:javacord:3.1.1'
implementation 'org.javacord:javacord:3.8.0'
implementation 'net.aksingh:owm-japis:2.5.3.0'
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
implementation 'javax.json:javax.json-api:1.1'
Expand All @@ -21,6 +21,8 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter:5.7.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.4.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.2'
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
}

group = 'org.jointheleague'
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/jointheleague/discord_bot/DiscordBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import org.javacord.api.DiscordApi;
import org.javacord.api.DiscordApiBuilder;
import org.javacord.api.entity.intent.Intent;
import org.jointheleague.features.abstract_classes.Feature;
import org.jointheleague.features.examples.second_features.HighLowGame;
import org.jointheleague.features.examples.third_features.CatFactsApi;
import org.jointheleague.features.examples.third_features.NewsApi;
import org.jointheleague.features.examples.first_features.CurrentTime;
import org.jointheleague.features.examples.first_features.RandomNumber;
import org.jointheleague.features.help_embed.HelpListener;
import org.jointheleague.features.student.third_feature.FeatureThree;

public class DiscordBot {

Expand All @@ -28,7 +30,7 @@ public DiscordBot(String token, String channelName) {

public void connect(boolean printInvite) {

api = new DiscordApiBuilder().setToken(token).login().join();
api = new DiscordApiBuilder().setToken(token).addIntents(Intent.MESSAGE_CONTENT).login().join();

//Print the URL to invite the bot
if (printInvite) {
Expand All @@ -46,7 +48,7 @@ public void connect(boolean printInvite) {
addFeature(new RandomNumber(channelName));
addFeature(new CurrentTime(channelName));
addFeature(new HighLowGame(channelName));
addFeature(new NewsApi(channelName));
addFeature(new FeatureThree(channelName));
addFeature(new CatFactsApi(channelName));
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.jointheleague.features.student.third_feature;

public class lootTableA {

//Minnow(35.7525,4),Sardine(32.5, 7),SeaBass(9, 16),Tuna(15.5, 12.5),ReefShark(12.5, 13.5),Squid(3.5, 75),TriggerFish(5,45),ElectricEel(2.25,115),Striper(6.25, 25),Lobster(1.75, 145),Swordfish(0.975,160),Sunfish(0.675,235),WalkingMinnow(0.0125,126500),GoldMinnowStatue(0.00565,127500);
double value;
double weightOrChanceOfGettingFish;
String name;
lootTableA(double weightOrChanceOfGettingFish, double value, String name) {
this.weightOrChanceOfGettingFish=weightOrChanceOfGettingFish;
this.value = value;
this.name = name;
}

public double getValue() {
return value;
}

public double getChance() {
return weightOrChanceOfGettingFish;
}

public String name(){return name;}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*package org.jointheleague.features.student.third_feature;

public enum lootTableB {
//Telescopefish(25.65,35),Rhinochimaera(20.2575,40),Angler(15.125,55),Barreleye(12.25751,60),Lanternfish(11.524575,70),GlowingMinnow(10.2575,75),FlyingMinnow(8.7525,90),AbyssalGrenadier(5.245,125),MarineHatchetfish(5.65,120),GoblinShark(2.5,165),Jellyfish(1.15, 225),Snailfish(0.000125,35000000);
double value;
double weightOrChanceOfGettingFish;
lootTableB(double weightOrChanceOfGettingFish, double value) {
this.weightOrChanceOfGettingFish=weightOrChanceOfGettingFish;
this.value = value;
}

public double getValue() {
return value;
}

public double getChance() {
return weightOrChanceOfGettingFish;
}
}
*/
package org.jointheleague.features.student.third_feature;

import org.javacord.api.entity.message.MessageDecoration;

public class lootTableB {
double weight;
double multiplier;
String name;
String rankingEmoji;

lootTableB(double weight, double multiplier, String name, String rankingEmoji){
this.weight = weight;
this.multiplier = multiplier;
this.name = name;
this.rankingEmoji = rankingEmoji;
}

public double getMultiplier() {
return multiplier;
}

public double getWeight() {
return weight;
}

public String name(){
return name;
}

public String getRankingEmoji() {
return rankingEmoji;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void itShouldNotHandleMessagesWithoutCommand() {
currentTime.handle(messageCreateEvent);

//Then
verify(textChannel, never()).sendMessage();
verify(textChannel, never()).sendMessage("");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void itShouldNotHandleMessagesWithoutCommand() {
randomNumber.handle(messageCreateEvent);

//Then
verify(textChannel, never()).sendMessage();
verify(textChannel, never()).sendMessage("");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void itShouldNotHandleMessagesWithoutCommand() {
highLowGame.handle(messageCreateEvent);

//Then
verify(textChannel, never()).sendMessage();
verify(textChannel, never()).sendMessage("");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void givenMessageWithoutCommand_whenHandle_thenDoNothing() {
catFactsApi.handle(messageCreateEvent);

//Then
verify(textChannel, never()).sendMessage();
verify(textChannel, never()).sendMessage("");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void givenMessageWithoutCommand_whenHandle_thenDoNothing() {
newsApi.handle(messageCreateEvent);

//Then
verify(textChannel, never()).sendMessage();
verify(textChannel, never()).sendMessage("");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
package org.jointheleague.features.student.third_feature;

import org.javacord.api.entity.channel.TextChannel;
import org.javacord.api.event.message.MessageCreateEvent;
import org.javacord.api.interaction.MessageComponentInteraction;
import org.javacord.api.listener.interaction.MessageComponentCreateListener;
import org.javacord.api.util.event.ListenerManager;
import org.jointheleague.features.help_embed.plain_old_java_objects.help_embed.HelpEmbed;
import org.jointheleague.features.templates.FeatureTemplate;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.never;

public class FeatureThreeTest {
private final String testChannelName = "test";
private final FeatureThree featureThree = new FeatureThree(testChannelName);

private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
private final PrintStream originalOut = System.out;

@Mock
private MessageCreateEvent messageCreateEvent;

@Mock
private TextChannel textChannel;


@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
System.setOut(new PrintStream(outContent));
}

@AfterEach
public void itShouldNotPrintToSystemOut() {
String expected = "";
String actual = outContent.toString();

assertEquals(expected, actual);
System.setOut(originalOut);
}

@Test
void itShouldHaveACommand() {
//Given

//When
String command = featureThree.COMMAND;

//Then

if(!(featureThree instanceof FeatureThree)){
assertNotEquals("!command", command);
}

assertNotEquals("", command);
assertNotEquals("!", command);
assertEquals('!', command.charAt(0));
assertNotNull(command);
}

@Test
void itShouldHandleMessagesWithCommand() {
//Given
HelpEmbed helpEmbed = new HelpEmbed(featureThree.COMMAND, "test");
when(messageCreateEvent.getMessageContent()).thenReturn(featureThree.COMMAND);
when(messageCreateEvent.getChannel()).thenReturn((textChannel));

//When
featureThree.handle(messageCreateEvent);

//Then
verify(textChannel, times(1)).sendMessage(anyString());
}

@Test
void itShouldNotHandleMessagesWithoutCommand() {
//Given
String command = "";
when(messageCreateEvent.getMessageContent()).thenReturn(command);

//When
featureThree.handle(messageCreateEvent);

//Then
verify(textChannel, never()).sendMessage("");
}

@Test
void itShouldHaveAHelpEmbed() {
//Given

//When
HelpEmbed actualHelpEmbed = featureThree.getHelpEmbed();

//Then
assertNotNull(actualHelpEmbed);
}

@Test
void itShouldHaveTheCommandAsTheTitleOfTheHelpEmbed() {
//Given

//When
String helpEmbedTitle = featureThree.getHelpEmbed().getTitle();
String command = featureThree.COMMAND;

//Then
assertEquals(command, helpEmbedTitle);
}

@Test
void itShouldApplyFishEffect(){
featureThree.money = 125.00;
featureThree.location = "The Coveted Coves";
featureThree.luckModifier = 0.0;
featureThree.fishTimes = 1;
double PreMoney = featureThree.money;
when(messageCreateEvent.getChannel()).thenReturn(textChannel);
featureThree.fishEffect("Luckfish", messageCreateEvent);
featureThree.fishEffect("Boatfish", messageCreateEvent);
featureThree.fishEffect("Rodfish", messageCreateEvent);
featureThree.fishEffect("Snarefish", messageCreateEvent);
assert(PreMoney > featureThree.money);
assertEquals(1.25,featureThree.luckModifier, 0);
assert(!featureThree.location.equals("The Coveted Coves"));
assertEquals(2, featureThree.fishTimes);
}

@Test
void itShouldFeedLocationalDataWhenUsingRandomFish(){
//lootTableA[] expected
//System.out.println("TEST");
//System.out.println("TESTEST");
featureThree.location = "Trench";
when(messageCreateEvent.getChannel()).thenReturn(textChannel);
//when(messageCreateEvent.getChannel().sendMessage("")).thenReturn(null);
featureThree.randomFish(featureThree.location, messageCreateEvent);
// lootTableA[] test = {};
//when(featureThree.lootAssigning()).thenReturn(test);
lootTableA[] expected = {new lootTableA(25.65,35,"Telescopefish"),new lootTableA(20.2575,40,"Rhinochimaera"),new lootTableA(15.125,55,"Anglerfish"),new lootTableA(12.25751,60,"Barreleye"),new lootTableA(11.524575,70,"Lanternfish"),new lootTableA(10.2575,75,"Glowing Minnow"),new lootTableA(8.7525,90,"Flying Minnow"),new lootTableA(5.245,125,"Abyssal Grenadier"),new lootTableA(5.65,120,"Marine Hatchetfish"),new lootTableA(2.5,165,"Goblin Shark"),new lootTableA(1.15, 225,"Jellyfish"),new lootTableA(0.75, 345, "Six-Gilled Shark"),new lootTableA(0.000125,35000000,"Snailfish")};
//System.out.println(expected);
// System.out.println(featureThree.testList);
assertNotEquals(featureThree.testList, null);
//assertEquals(expected, featureThree.testList);
//System.err.println(featureThree.testList[0]);
//System.err.println(expected[0]);
for(int i =0; i < featureThree.testList.length; i++) {
assertTrue(expected[i].name().equals(featureThree.testList[i].name()));
assertTrue(expected[i].getValue()==featureThree.testList[i].getValue());
assertTrue(expected[i].getChance()==featureThree.testList[i].getChance());
}
}
//All other features without a test written in this file have been tested manually and have an issue with the way there are coded that makes them unable to have an accurate test written without major rewrites.
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void itShouldNotHandleMessagesWithoutCommand() {
featureTemplate.handle(messageCreateEvent);

//Then
verify(textChannel, never()).sendMessage();
verify(textChannel, never()).sendMessage("");
}

@Test
Expand Down