mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
Start adding unit tests via MockBukkit
This commit is contained in:
1 parent
c31229c19e
commit
eddae1051c
15 files changed
+147
-28
No files matched your search
@@ -0,0 +1,12 @@
|
||||
package net.william278.huskhomes;
|
||||
|
||||
/**
|
||||
* Indicates that economy features of the plugin have tried to be accessed when they are not enabled.
|
||||
*/
|
||||
public class EconomyUnsupportedException extends HuskHomesException {
|
||||
|
||||
public EconomyUnsupportedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.william278.huskhomes;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Indicates an exception caused by HuskHomes' plugin logic occurred
|
||||
*/
|
||||
public class HuskHomesException extends RuntimeException {
|
||||
|
||||
public HuskHomesException(@NotNull String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public HuskHomesException(@NotNull String message, @NotNull Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* Indicates an exception occurred while initialising the HuskHomes plugin
|
||||
*/
|
||||
public class HuskHomesInitializationException extends RuntimeException {
|
||||
public class HuskHomesInitializationException extends HuskHomesException {
|
||||
public HuskHomesInitializationException(@NotNull String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
@@ -127,7 +127,13 @@ public class SqLiteDatabase extends Database {
|
||||
statement.setString(8, position.server.name);
|
||||
statement.executeUpdate();
|
||||
|
||||
return statement.getGeneratedKeys().getInt(1);
|
||||
// Return the ID of the newly inserted row
|
||||
try (ResultSet resultSet = statement.getGeneratedKeys()) {
|
||||
if (resultSet.next()) {
|
||||
return resultSet.getInt(1);
|
||||
}
|
||||
}
|
||||
throw new SQLException("No generated key found");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +176,13 @@ public class SqLiteDatabase extends Database {
|
||||
statement.setTimestamp(4, new Timestamp(Instant.ofEpochSecond(position.meta.timestamp).toEpochMilli()));
|
||||
statement.executeUpdate();
|
||||
|
||||
return statement.getGeneratedKeys().getInt(1);
|
||||
// Return the ID of the newly inserted row
|
||||
try (ResultSet resultSet = statement.getGeneratedKeys()) {
|
||||
if (resultSet.next()) {
|
||||
return resultSet.getInt(1);
|
||||
}
|
||||
}
|
||||
throw new SQLException("No generated key found");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -884,6 +896,7 @@ public class SqLiteDatabase extends Database {
|
||||
statement.executeUpdate();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
getLogger().log(Level.SEVERE,
|
||||
"Failed to set a home to the database for " + home.owner.username, e);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import de.themoep.minedown.MineDown;
|
||||
import net.william278.huskhomes.position.Location;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.teleport.TeleportResult;
|
||||
import net.william278.huskhomes.util.EconomyUnsupportedException;
|
||||
import net.william278.huskhomes.EconomyUnsupportedException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -50,7 +50,7 @@ public class SavedPositionManager {
|
||||
cache.homes.putIfAbsent(home.owner.uuid, new ArrayList<>());
|
||||
cache.homes.get(home.owner.uuid).add(home.meta.name);
|
||||
cache.positionLists.clear();
|
||||
return database.setHome(home).thenApply(ignored ->
|
||||
return database.setHome(home).thenApply(value ->
|
||||
new SetResult(SetResult.ResultType.SUCCESS, home)).join();
|
||||
}
|
||||
return new SetResult(SetResult.ResultType.FAILED_DUPLICATE, null);
|
||||
@@ -188,7 +188,12 @@ public class SavedPositionManager {
|
||||
/**
|
||||
* The position was not set; the description uses illegal characters
|
||||
*/
|
||||
FAILED_DESCRIPTION_CHARACTERS(false);
|
||||
FAILED_DESCRIPTION_CHARACTERS(false),
|
||||
|
||||
/**
|
||||
* The position was not set; the position is not in a valid world
|
||||
*/
|
||||
FAILED_ERROR(false);
|
||||
|
||||
public final boolean successful;
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
package net.william278.huskhomes.util;
|
||||
|
||||
/**
|
||||
* Signals that economy features of the plugin have tried to be accessed when they are not enabled.
|
||||
*/
|
||||
public class EconomyUnsupportedException extends IllegalStateException {
|
||||
|
||||
public EconomyUnsupportedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user