mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-02-02 04:51:27 +01:00
Add a couple tests
This commit is contained in:
parent
cfbb3f9a7f
commit
ed0126d06c
@ -1,24 +1,27 @@
|
||||
package fr.xephi.authme.service;
|
||||
|
||||
import ch.jalu.injector.testing.BeforeInjecting;
|
||||
import ch.jalu.injector.testing.DelayedInjectionRunner;
|
||||
import ch.jalu.injector.testing.InjectDelayed;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.mail.EmailService;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.message.Messages;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import org.junit.Ignore;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Tests for {@link PasswordRecoveryService}.
|
||||
*/
|
||||
@Ignore
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@RunWith(DelayedInjectionRunner.class)
|
||||
public class PasswordRecoveryServiceTest {
|
||||
|
||||
@InjectDelayed
|
||||
@ -39,16 +42,32 @@ public class PasswordRecoveryServiceTest {
|
||||
@Mock
|
||||
private PasswordSecurity passwordSecurity;
|
||||
|
||||
@Mock
|
||||
private RecoveryCodeService recoveryCodeService;
|
||||
|
||||
@Mock
|
||||
private Messages messages;
|
||||
|
||||
@BeforeInjecting
|
||||
public void initSettings() {
|
||||
given(commonService.getProperty(SecuritySettings.EMAIL_RECOVERY_COOLDOWN_SECONDS)).willReturn(40);
|
||||
given(commonService.getProperty(SecuritySettings.PASSWORD_CHANGE_TIMEOUT)).willReturn(2);
|
||||
}
|
||||
|
||||
//TODO: Write tests
|
||||
@Test
|
||||
public void shouldSendRecoveryCode() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
String name = "Carl";
|
||||
given(player.getName()).willReturn(name);
|
||||
String email = "test@example.com";
|
||||
String code = "qwerty";
|
||||
given(codeService.generateCode(name)).willReturn(code);
|
||||
given(emailService.sendRecoveryCode(player.getName(), email, code)).willReturn(true);
|
||||
|
||||
// when
|
||||
recoveryService.createAndSendRecoveryCode(player, email);
|
||||
|
||||
// then
|
||||
verify(codeService).generateCode(name);
|
||||
verify(emailService).sendRecoveryCode(name, email, code);
|
||||
verify(commonService).send(player, MessageKey.RECOVERY_CODE_SENT);
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,21 @@ public class TimedCounterTest {
|
||||
assertThat(counter.get("moto"), equalTo(13));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDecrementCount() {
|
||||
// given
|
||||
TimedCounter<String> counter = new TimedCounter<>(10, TimeUnit.MINUTES);
|
||||
counter.put("moto", 12);
|
||||
|
||||
// when
|
||||
counter.decrement("hello");
|
||||
counter.decrement("moto");
|
||||
|
||||
// then
|
||||
assertThat(counter.get("hello"), equalTo(0));
|
||||
assertThat(counter.get("moto"), equalTo(11));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSumUpEntries() {
|
||||
// given
|
||||
|
Loading…
Reference in New Issue
Block a user