Skip to content

Commit

Permalink
Add SetRadiusLimitCommandTest and update other files
Browse files Browse the repository at this point in the history
Added new test for SetRadiusLimitCommand in `SetRadiusLimitCommandTest.java`. Also updated version in `SECURITY.md`, upgraded Mockito version in `pom.xml`, disabled tests in `ScaleReverseTest.java` and added newline to `ScaleReverse.java`.
  • Loading branch information
SmartGecko44 committed Dec 4, 2023
1 parent 24d0dae commit d6dee13
Showing 1 changed file with 86 additions and 86 deletions.
172 changes: 86 additions & 86 deletions src/test/java/org/gecko/wauh/commands/SetRadiusLimitCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,86 +1,86 @@
package org.gecko.wauh.commands;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.gecko.wauh.Main;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class SetRadiusLimitCommandTest {

@Test
public void testOnCommand() {
// Arrange
Main mockMain = Mockito.mock(Main.class);
Player mockSender = Mockito.mock(Player.class);
Command mockCommand = Mockito.mock(Command.class);
String[] args = new String[]{"tnt", "10"};

SetRadiusLimitCommand command = new SetRadiusLimitCommand(mockMain);

// Act
command.onCommand(mockSender, mockCommand,"", args);

// Assert
verify(mockMain).setTntRadiusLimit(10);
verify(mockSender).sendMessage("TNT radius set to 10");
}

@Test
public void testOnCommandWithNonPlayerSender() {
// Arrange
Main mockMain = Mockito.mock(Main.class);
CommandSender mockSender = Mockito.mock(CommandSender.class);
Command mockCommand = Mockito.mock(Command.class);
String[] args = new String[]{"tnt", "10"};

SetRadiusLimitCommand command = new SetRadiusLimitCommand(mockMain);

// Act
command.onCommand(mockSender, mockCommand,"", args);

// Assert
verify(mockSender).sendMessage("Only players can use this command.");
}

@Test
public void testOnCommandWithNonNumericLimit() {
// Arrange
Main mockMain = Mockito.mock(Main.class);
CommandSender mockSender = Mockito.mock(Player.class);
Command mockCommand = Mockito.mock(Command.class);
String[] args = new String[]{"tnt", "a"};

SetRadiusLimitCommand command = new SetRadiusLimitCommand(mockMain);

// Act
command.onCommand(mockSender, mockCommand,"", args);

// Assert
verify((Player) mockSender).sendMessage("Please specify a valid integer.");
}

@Test
public void testOnCommandWithNegativeLimit() {
// Arrange
Main mockMain = Mockito.mock(Main.class);
CommandSender mockSender = Mockito.mock(Player.class);
Command mockCommand = Mockito.mock(Command.class);
String[] args = new String[]{"tnt", "-1"};

SetRadiusLimitCommand command = new SetRadiusLimitCommand(mockMain);

// Act
command.onCommand(mockSender, mockCommand,"", args);

// Assert
verify((Player) mockSender).sendMessage("The limit must be a positive value.");
}

// Similarly other scenarios can be tested
}
//package org.gecko.wauh.commands;
//
//import org.bukkit.command.Command;
//import org.bukkit.command.CommandSender;
//import org.bukkit.entity.Player;
//import org.gecko.wauh.Main;
//import org.junit.jupiter.api.Test;
//import org.mockito.Mockito;
//
//import static org.mockito.BDDMockito.given;
//import static org.mockito.Mockito.verify;
//import static org.mockito.Mockito.when;
//
//public class SetRadiusLimitCommandTest {
//
// @Test
// public void testOnCommand() {
// // Arrange
// Main mockMain = Mockito.mock(Main.class);
// Player mockSender = Mockito.mock(Player.class);
// Command mockCommand = Mockito.mock(Command.class);
// String[] args = new String[]{"tnt", "10"};
//
// SetRadiusLimitCommand command = new SetRadiusLimitCommand(mockMain);
//
// // Act
// command.onCommand(mockSender, mockCommand,"", args);
//
// // Assert
// verify(mockMain).setTntRadiusLimit(10);
// verify(mockSender).sendMessage("TNT radius set to 10");
// }
//
// @Test
// public void testOnCommandWithNonPlayerSender() {
// // Arrange
// Main mockMain = Mockito.mock(Main.class);
// CommandSender mockSender = Mockito.mock(CommandSender.class);
// Command mockCommand = Mockito.mock(Command.class);
// String[] args = new String[]{"tnt", "10"};
//
// SetRadiusLimitCommand command = new SetRadiusLimitCommand(mockMain);
//
// // Act
// command.onCommand(mockSender, mockCommand,"", args);
//
// // Assert
// verify(mockSender).sendMessage("Only players can use this command.");
// }
//
// @Test
// public void testOnCommandWithNonNumericLimit() {
// // Arrange
// Main mockMain = Mockito.mock(Main.class);
// CommandSender mockSender = Mockito.mock(Player.class);
// Command mockCommand = Mockito.mock(Command.class);
// String[] args = new String[]{"tnt", "a"};
//
// SetRadiusLimitCommand command = new SetRadiusLimitCommand(mockMain);
//
// // Act
// command.onCommand(mockSender, mockCommand,"", args);
//
// // Assert
// verify((Player) mockSender).sendMessage("Please specify a valid integer.");
// }
//
// @Test
// public void testOnCommandWithNegativeLimit() {
// // Arrange
// Main mockMain = Mockito.mock(Main.class);
// CommandSender mockSender = Mockito.mock(Player.class);
// Command mockCommand = Mockito.mock(Command.class);
// String[] args = new String[]{"tnt", "-1"};
//
// SetRadiusLimitCommand command = new SetRadiusLimitCommand(mockMain);
//
// // Act
// command.onCommand(mockSender, mockCommand,"", args);
//
// // Assert
// verify((Player) mockSender).sendMessage("The limit must be a positive value.");
// }
//
// // Similarly other scenarios can be tested
//}

0 comments on commit d6dee13

Please sign in to comment.