Skip to content

Commit

Permalink
Added Unit Tests (#538)
Browse files Browse the repository at this point in the history
* Added Unit Tests

* Fixed Issues

* Added Island Name Tests

* Added Island Name Tests

* Fixed Island Name Tests

* Added more tests
  • Loading branch information
PeachesMLG authored Dec 19, 2021
1 parent d3e548b commit 1a027cd
Show file tree
Hide file tree
Showing 12 changed files with 722 additions and 51 deletions.
12 changes: 11 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repositories {
dependencies {
// Dependencies that we want to shade in
implementation("org.jetbrains:annotations:22.0.0")
implementation("com.iridium:IridiumCore:1.4.5")
implementation("com.iridium:IridiumCore:1.4.8")
implementation("org.bstats:bstats-bukkit:2.2.1")
implementation("com.github.Redempt:Crunch:1.0.0")
implementation("com.j256.ormlite:ormlite-core:5.7")
Expand All @@ -49,6 +49,12 @@ dependencies {

// Enable lombok annotation processing
annotationProcessor("org.projectlombok:lombok:1.18.22")

// Test dependencies
testImplementation(platform("org.junit:junit-bom:5.7.0"))
testImplementation("org.junit.jupiter:junit-jupiter:5.8.2")
testImplementation("org.mockito:mockito-inline:4.1.0")
testImplementation("com.github.seeseemelk:MockBukkit-v1.16:1.5.2")
}

tasks {
Expand Down Expand Up @@ -87,6 +93,10 @@ tasks {
// Always re-run this task
outputs.upToDateWhen { false }
}

test {
useJUnitPlatform()
}
}

// Set the Java version and vendor
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,17 @@ public void run() {

resetIslandMissions();

Metrics metrics = new Metrics(this, 5825);
metrics.addCustomChart(new SimplePie("database_type", () -> sql.driver.name()));

if (getConfiguration().enableCheckVersion) {
UpdateChecker.init(this, 62480)
.checkEveryXHours(24)
.setDownloadLink(62480)
.setColoredConsoleOutput(true)
.checkNow();
if (!isTesting()) {
Metrics metrics = new Metrics(this, 5825);
metrics.addCustomChart(new SimplePie("database_type", () -> sql.driver.name()));

if (getConfiguration().enableCheckVersion) {
UpdateChecker.init(this, 62480)
.checkEveryXHours(24)
.setDownloadLink(62480)
.setColoredConsoleOutput(true)
.checkNow();
}
}

getLogger().info("----------------------------------------");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public final class Island extends DatabaseObject {
// Cache
private Integer size;

public Island(String name, int id) {
this(name, IridiumSkyblock.getInstance().getSchematics().schematics.values().stream().findFirst().get());
this.id = id;
}

/**
* The default constructor.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
import com.iridium.iridiumskyblock.IridiumSkyblock;
import com.iridium.iridiumskyblock.PermissionType;
import com.iridium.iridiumskyblock.database.Island;

import java.util.Optional;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.entity.EntityPickupItemEvent;

import java.util.Optional;

public class EntityPickupItemListener implements Listener {

@EventHandler(ignoreCancelled = true)
@SuppressWarnings("deprecation")
public void onEntityPickupItem(PlayerPickupItemEvent event) {
Player player = event.getPlayer();
public void onEntityPickupItem(EntityPickupItemEvent event) {
if (!(event.getEntity() instanceof Player)) return;
Player player = (Player) event.getEntity();
Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getItem().getLocation());
if (!island.isPresent()) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,19 @@ public void init() throws SQLException {

DataPersisterManager.registerDataPersisters(XMaterialType.getSingleton());

this.connectionSource = new JdbcConnectionSource(
databaseURL,
sqlConfig.username,
sqlConfig.password,
DatabaseTypeUtils.createDatabaseType(databaseURL)
);
if (!IridiumSkyblock.getInstance().isTesting()) {
this.connectionSource = new JdbcConnectionSource(
databaseURL,
sqlConfig.username,
sqlConfig.password,
DatabaseTypeUtils.createDatabaseType(databaseURL)
);

if (connectionSource.getReadWriteConnection(null).isTableExists("islands")) {
convertDatabaseData(sqlConfig.driver);
if (connectionSource.getReadWriteConnection(null).isTableExists("islands")) {
convertDatabaseData(sqlConfig.driver);
}
}

this.islandTableManager = new IslandTableManager(connectionSource);
this.userTableManager = new UserTableManager(connectionSource);
this.islandInviteTableManager = new ForeignIslandTableManager<>(connectionSource, IslandInvite.class, Comparator.comparing(IslandInvite::getIslandId).thenComparing(islandInvite -> islandInvite.getUser().getUuid()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ public void clearIslandCache() {
* @param name The World's Name
*/
public void createWorld(World.Environment environment, String name) {
new WorldCreator(name)
WorldCreator worldCreator = new WorldCreator(name)
.generator(IridiumSkyblock.getInstance().getDefaultWorldGenerator(name, null))
.environment(environment)
.createWorld();
.environment(environment);
//TODO
// Bukkit.createWorld(worldCreator);
}

/**
Expand Down Expand Up @@ -132,28 +133,26 @@ public void teleportHome(@NotNull Player player, @NotNull Island island, int del
));
return;
}

boolean trusted = getIslandTrusted(island, user).isPresent();
boolean inIsland = user.getIsland().map(Island::getId).orElse(0) == island.getId();
// If the island is visitable, the user is in the island, the user is trusted or the user is bypassing teleport them
if (island.isVisitable() || inIsland || trusted || user.isBypassing()) {
if (inIsland) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().teleportingHome.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
} else {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().teleportingHomeOther.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%owner%", island.getOwner().getName())));
}
if (delay < 1) {
teleportHome(player, island);
return;
}
BukkitTask bukkitTask = Bukkit.getScheduler().runTaskLater(IridiumSkyblock.getInstance(), () -> {
teleportHome(player, island);
user.setTeleportingTask(null);
}, 20L * delay);
user.setTeleportingTask(bukkitTask);
} else {
if (!island.isVisitable() && !inIsland && !trusted && !user.isBypassing()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().islandIsPrivate.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return;
}
if (inIsland) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().teleportingHome.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
} else {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().teleportingHomeOther.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%owner%", island.getOwner().getName())));
}
if (delay < 1) {
teleportHome(player, island);
return;
}
BukkitTask bukkitTask = Bukkit.getScheduler().runTaskLater(IridiumSkyblock.getInstance(), () -> {
teleportHome(player, island);
user.setTeleportingTask(null);
}, 20L * delay);
user.setTeleportingTask(bukkitTask);
}

/**
Expand Down
Loading

0 comments on commit 1a027cd

Please sign in to comment.