From 66d1ee92c3273dacf2dcc15a2c8c462ef92949e2 Mon Sep 17 00:00:00 2001 From: HexelDev Date: Thu, 15 Mar 2018 21:45:11 +0100 Subject: [PATCH] QuickCommandsProtectionManager Test class --- .../QuickCommandsProtectionManagerTest.java | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/test/java/fr/xephi/authme/data/QuickCommandsProtectionManagerTest.java diff --git a/src/test/java/fr/xephi/authme/data/QuickCommandsProtectionManagerTest.java b/src/test/java/fr/xephi/authme/data/QuickCommandsProtectionManagerTest.java new file mode 100644 index 000000000..10ef88eb8 --- /dev/null +++ b/src/test/java/fr/xephi/authme/data/QuickCommandsProtectionManagerTest.java @@ -0,0 +1,65 @@ +package fr.xephi.authme.data; + +import fr.xephi.authme.permission.PermissionsManager; +import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.settings.properties.ProtectionSettings; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertThat; +import static org.mockito.BDDMockito.given; + +/** + * Test for {@link QuickCommandsProtectionManager}. + */ +@RunWith(MockitoJUnitRunner.class) +public class QuickCommandsProtectionManagerTest { + + @Mock + private Settings settings; + + @Mock + private PermissionsManager permissionsManager; + + @Test + public void shouldAllowCommand() { + // given + String name1 = "TestName1"; + String name2 = "TestName2"; + given(settings.getProperty(ProtectionSettings.QUICK_COMMANDS_DENIED_BEFORE_MILLISECONDS)).willReturn(0); + + QuickCommandsProtectionManager qcpm = createQuickCommandsProtectioneManager(); + qcpm.setLogin(name2); + + // when + boolean test1 = qcpm.isAllowed(name1); + boolean test2 = qcpm.isAllowed(name2); + + // then + assertThat(test1, equalTo(true)); + assertThat(test2, equalTo(true)); + } + + @Test + public void shouldDenyCommand() { + // given + String name = "TestName1"; + given(settings.getProperty(ProtectionSettings.QUICK_COMMANDS_DENIED_BEFORE_MILLISECONDS)).willReturn(5000); + + QuickCommandsProtectionManager qcpm = createQuickCommandsProtectioneManager(); + qcpm.setLogin(name); + + // when + boolean test = qcpm.isAllowed(name); + + // then + assertThat(test, equalTo(false)); + } + + private QuickCommandsProtectionManager createQuickCommandsProtectioneManager() { + return new QuickCommandsProtectionManager(settings, permissionsManager); + } +}