Skip to content

Commit

Permalink
Fix few maintainability issues
Browse files Browse the repository at this point in the history
  • Loading branch information
utarwyn committed Feb 20, 2025
1 parent 216a706 commit 356e4c8
Show file tree
Hide file tree
Showing 69 changed files with 384 additions and 383 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Works with Bukkit/Spigot 1.8 to 1.21!

<p align="center">
<a href="https://github.com/utarwyn/EnderContainers/actions">
<img src="https://github.com/utarwyn/EnderContainers/workflows/Java%20Integration/badge.svg" alt="Java CI">
<img src="https://github.com/utarwyn/EnderContainers/workflows/Build/badge.svg" alt="Build CI">
</a>
<a href="https://sonarcloud.io/dashboard?id=fr.utarwyn%3Aendercontainers">
<img src="https://sonarcloud.io/api/project_badges/measure?project=fr.utarwyn%3Aendercontainers&metric=alert_status" alt="SonarQube Quality gate">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class LocalizedExceptionTest {

@Test
public void createWithoutParameter() {
void createWithoutParameter() {
try {
throw new LocalizedException(LocaleKey.CMD_UPDATE);
} catch (LocalizedException e) {
Expand All @@ -19,7 +19,7 @@ public void createWithoutParameter() {
}

@Test
public void createWithParameters() {
void createWithParameters() {
try {
throw new LocalizedException(LocaleKey.CMD_NO_UPDATE, Collections.singletonMap("key", "value"));
} catch (LocalizedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
public class PlotSquaredDependencyTest {
class PlotSquaredDependencyTest {

private PlotSquaredDependency dependency;

Expand Down Expand Up @@ -70,7 +70,7 @@ public void setUp() throws ReflectiveOperationException {
}

@Test
public void invalidateIfPlotProtected() {
void invalidateIfPlotProtected() {
try {
this.dependency.validateBlockChestOpening(this.block, this.player);
fail("should throw block chest opening exception when not in plot");
Expand All @@ -81,7 +81,7 @@ public void invalidateIfPlotProtected() {
}

@Test
public void validateNotInPlot() {
void validateNotInPlot() {
try {
when(this.plotArea.getPlot(any(com.plotsquared.core.location.Location.class))).thenReturn(null);
this.dependency.validateBlockChestOpening(this.block, this.player);
Expand All @@ -91,7 +91,7 @@ public void validateNotInPlot() {
}

@Test
public void validateIfOperator() {
void validateIfOperator() {
try {
when(this.player.isOp()).thenReturn(true);
this.dependency.validateBlockChestOpening(this.block, this.player);
Expand All @@ -101,7 +101,7 @@ public void validateIfOperator() {
}

@Test
public void validateIfPermGranted() {
void validateIfPermGranted() {
try {
when(this.plot.isAdded(this.player.getUniqueId())).thenReturn(true);
this.dependency.validateBlockChestOpening(this.block, this.player);
Expand All @@ -111,7 +111,7 @@ public void validateIfPermGranted() {
}

@Test
public void validateIfNoProtection() {
void validateIfNoProtection() {
try {
when(this.plot.getFlag(UseFlag.class)).thenReturn(new ArrayList<>());
this.dependency.validateBlockChestOpening(this.block, this.player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
public class WorldGuard6DependencyTest {
class WorldGuard6DependencyTest {

private WorldGuard6Dependency dependency;

Expand All @@ -49,7 +49,7 @@ public void setUp() {
}

@Test
public void validateIfOperator() {
void validateIfOperator() {
try {
when(this.player.isOp()).thenReturn(true);
this.dependency.validateBlockChestOpening(this.block, this.player);
Expand All @@ -59,7 +59,7 @@ public void validateIfOperator() {
}

@Test
public void validateIfCanBuildSucceed() {
void validateIfCanBuildSucceed() {
try {
when(this.regionQuery.testBuild(eq(this.block.getLocation()), any(LocalPlayer.class), eq(DefaultFlag.CHEST_ACCESS)))
.thenReturn(true);
Expand All @@ -70,13 +70,14 @@ public void validateIfCanBuildSucceed() {
}

@Test
public void invalidateIfCanBuildErrored() {
void invalidateIfCanBuildErrored() {
try {
when(this.regionQuery.testBuild(eq(this.block.getLocation()), any(LocalPlayer.class), eq(DefaultFlag.CHEST_ACCESS)))
.thenReturn(false);
this.dependency.validateBlockChestOpening(this.block, this.player);
fail("should throw block chest opening exception because build is forbidden by WorldGuard");
} catch (BlockChestOpeningException ignored) {
// ignored
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
public class WorldGuard7DependencyTest {
class WorldGuard7DependencyTest {

private static boolean serverReplaced = false;

Expand Down Expand Up @@ -93,7 +93,7 @@ public void setUp() {
}

@Test
public void validateIfOperator() {
void validateIfOperator() {
try {
when(this.player.isOp()).thenReturn(true);
this.dependency.validateBlockChestOpening(this.block, this.player);
Expand All @@ -103,7 +103,7 @@ public void validateIfOperator() {
}

@Test
public void validateIfCanBuildSucceed() {
void validateIfCanBuildSucceed() {
try {
when(this.regionQuery.testBuild(any(com.sk89q.worldedit.util.Location.class), eq(this.localPlayer), eq(Flags.CHEST_ACCESS)))
.thenReturn(true);
Expand All @@ -114,13 +114,14 @@ public void validateIfCanBuildSucceed() {
}

@Test
public void invalidateIfCanBuildErrored() {
void invalidateIfCanBuildErrored() {
try {
when(this.regionQuery.testBuild(any(com.sk89q.worldedit.util.Location.class), eq(this.localPlayer), eq(Flags.CHEST_ACCESS)))
.thenReturn(false);
this.dependency.validateBlockChestOpening(this.block, this.player);
fail("should throw block chest opening exception because build is forbidden by WorldGuard");
} catch (BlockChestOpeningException ignored) {
// ignored
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public static Sound searchSound(String... names) throws IllegalArgumentException
try {
return Sound.valueOf(soundKey);
} catch (IllegalArgumentException ignored) {
// ignored
}
}
throw new IllegalArgumentException(String.format("no sound found using key %s", names[0]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
public class AbstractManagerTest {
class AbstractManagerTest {

@Mock(answer = Answers.CALLS_REAL_METHODS)
private AbstractManager manager;
Expand All @@ -24,7 +24,7 @@ public class AbstractManagerTest {
private EnderContainers plugin;

@Test
public void registerListener() {
void registerListener() {
Server server = mock(Server.class);
PluginManager pluginManager = mock(PluginManager.class);

Expand All @@ -40,7 +40,7 @@ public void registerListener() {
}

@Test
public void setPlugin() {
void setPlugin() {
Logger logger = mock(Logger.class);
when(this.plugin.getLogger()).thenReturn(logger);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
public class EnderContainersTest {
class EnderContainersTest {

private EnderContainers plugin;

Expand All @@ -34,7 +34,7 @@ public void setUp() throws TestInitializationException {
}

@Test
public void enable() {
void enable() {
Map instances = mock(Map.class);
CommandManager commandManager = mock(CommandManager.class);

Expand All @@ -52,13 +52,13 @@ public void enable() {
}

@Test
public void disable() {
void disable() {
this.plugin.onDisable();
assertThat(Managers.instances).isEmpty();
}

@Test
public void executeTaskOnMainThread() {
void executeTaskOnMainThread() {
Runnable run = mock(Runnable.class);

// Primary thread
Expand All @@ -74,7 +74,7 @@ public void executeTaskOnMainThread() {
}

@Test
public void executeTaskOnOtherThread() {
void executeTaskOnOtherThread() {
Runnable run = mock(Runnable.class);
this.plugin.executeTaskOnOtherThread(run);
verify(this.plugin.getServer().getScheduler()).runTaskAsynchronously(this.plugin, run);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import static org.mockito.Mockito.verify;

@ExtendWith(MockitoExtension.class)
public class ManagersTest {
class ManagersTest {

@Mock
private AbstractManager manager;
Expand All @@ -22,7 +22,7 @@ public void setUp() {
}

@Test
public void register() throws TestInitializationException {
void register() throws TestInitializationException {
EnderContainers plugin = TestHelper.getPlugin();

assertThat(Managers.instances).isEmpty();
Expand All @@ -39,7 +39,7 @@ public void register() throws TestInitializationException {
}

@Test
public void get() {
void get() {
Managers.instances.put(this.manager.getClass(), this.manager);

assertThat(Managers.get(this.manager.getClass())).isNotNull()
Expand All @@ -55,7 +55,7 @@ public void get() {
}

@Test
public void reload() {
void reload() {
Managers.instances.put(this.manager.getClass(), this.manager);

assertThat(Managers.reload(this.manager.getClass())).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@
import org.bukkit.plugin.PluginManager;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
import org.mockito.stubbing.Answer;

import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.net.URL;
import java.util.*;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.logging.Logger;

import static org.mockito.Mockito.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
public class BackupManagerTest {
class BackupManagerTest {

private BackupManager manager;

Expand All @@ -30,7 +30,7 @@ public void setUp() {
}

@Test
public void loadAndGetters() throws TestInitializationException {
void loadAndGetters() throws TestInitializationException {
StorageManager storageManager = mock(StorageManager.class);
BackupsData storage = mock(BackupsData.class);
List<Backup> backupList = new ArrayList<>();
Expand All @@ -43,13 +43,13 @@ public void loadAndGetters() throws TestInitializationException {
}

@Test
public void unload() {
void unload() {
this.manager.unload();
assertThat(this.manager.getStorage()).isNull();
}

@Test
public void getBackupByName() throws TestInitializationException {
void getBackupByName() throws TestInitializationException {
Backup backup = mock(Backup.class);
List<Backup> backupList = new ArrayList<>();

Expand All @@ -63,7 +63,7 @@ public void getBackupByName() throws TestInitializationException {
}

@Test
public void createBackup() throws TestInitializationException {
void createBackup() throws TestInitializationException {
List<Backup> backupList = new ArrayList<>();

TestHelper.setUpServer();
Expand All @@ -87,7 +87,7 @@ public void createBackup() throws TestInitializationException {
}

@Test
public void applyBackup() throws TestInitializationException {
void applyBackup() throws TestInitializationException {
List<Backup> backupList = new ArrayList<>();

TestHelper.setUpServer();
Expand All @@ -110,7 +110,7 @@ public void applyBackup() throws TestInitializationException {
}

@Test
public void removeBackup() throws TestInitializationException {
void removeBackup() throws TestInitializationException {
List<Backup> backupList = new ArrayList<>();

TestHelper.setUpServer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import static org.assertj.core.api.Assertions.assertThat;

public class BackupTest {
class BackupTest {

@Test
public void backupCreation() {
void backupCreation() {
String name = "test";
Timestamp date = new Timestamp(1);
String createdBy = "Utarwyn";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
public class BackupApplyTaskTest {
class BackupApplyTaskTest {

private EnderChestManager enderChestManager;

Expand All @@ -29,7 +29,7 @@ public void setUp() throws TestInitializationException {
}

@Test
public void run() throws TestInitializationException {
void run() throws TestInitializationException {
EnderContainers plugin = TestHelper.getPlugin();
BackupManager manager = mock(BackupManager.class);
Backup backup = mock(Backup.class);
Expand Down
Loading

0 comments on commit 356e4c8

Please sign in to comment.