use of ch.jalu.injector.testing.BeforeInjecting in project AuthMeReloaded by AuthMe.
the class PasswordSecurityTest method setUpMocks.
@BeforeInjecting
public void setUpMocks() {
caughtClassInEvent = null;
// When the password encryption event is emitted, replace the encryption method with our mock.
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
Object[] arguments = invocation.getArguments();
if (arguments[0] instanceof PasswordEncryptionEvent) {
PasswordEncryptionEvent event = (PasswordEncryptionEvent) arguments[0];
caughtClassInEvent = event.getMethod() == null ? null : event.getMethod().getClass();
event.setMethod(method);
}
return null;
}
}).when(pluginManager).callEvent(any(Event.class));
given(settings.getProperty(SecuritySettings.PASSWORD_HASH)).willReturn(HashAlgorithm.BCRYPT);
given(settings.getProperty(SecuritySettings.LEGACY_HASHES)).willReturn(Collections.emptySet());
given(settings.getProperty(HooksSettings.BCRYPT_LOG2_ROUND)).willReturn(8);
Injector injector = new InjectorBuilder().addDefaultHandlers("fr.xephi.authme.security.crypts").create();
injector.register(Settings.class, settings);
given(hashAlgorithmFactory.newInstance(any(Class.class))).willAnswer(invocation -> {
Object o = injector.createIfHasDependencies(invocation.getArgument(0));
if (o == null) {
throw new IllegalArgumentException("Cannot create object of class '" + invocation.getArgument(0) + "': missing class that needs to be provided?");
}
return o;
});
}
use of ch.jalu.injector.testing.BeforeInjecting in project AuthMeReloaded by AuthMe.
the class SpawnLoaderTest method setup.
@BeforeInjecting
public void setup() throws IOException {
// Copy test config into a new temporary folder
testFolder = temporaryFolder.newFolder();
File source = TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "settings/spawn-firstspawn.yml");
File destination = new File(testFolder, "spawn.yml");
Files.copy(source, destination);
// Create a settings mock with default values
given(settings.getProperty(RestrictionSettings.SPAWN_PRIORITY)).willReturn("authme, essentials, multiverse, default");
}
use of ch.jalu.injector.testing.BeforeInjecting in project AuthMeReloaded by AuthMe.
the class DistributedFilesPersistenceHandlerTest method setUpClasses.
@BeforeInjecting
public void setUpClasses() throws IOException {
given(settings.getProperty(LimboSettings.DISTRIBUTION_SIZE)).willReturn(SegmentSize.SIXTEEN);
dataFolder = temporaryFolder.newFolder();
playerDataFolder = new File(dataFolder, "playerdata");
playerDataFolder.mkdir();
File limboFilesFolder = new File("src/test/resources/fr/xephi/authme/data/limbo");
for (File file : limboFilesFolder.listFiles()) {
File from = new File(playerDataFolder, file.getName());
Files.copy(file, from);
}
given(bukkitService.getWorld(anyString())).willAnswer(invocation -> {
World world = mock(World.class);
given(world.getName()).willReturn(invocation.getArgument(0));
return world;
});
}
use of ch.jalu.injector.testing.BeforeInjecting in project AuthMeReloaded by AuthMe.
the class IndividualFilesPersistenceHandlerTest method copyTestFiles.
@BeforeInjecting
public void copyTestFiles() throws IOException {
dataFolder = temporaryFolder.newFolder();
File playerFolder = new File(dataFolder, FileUtils.makePath("playerdata", SAMPLE_UUID.toString()));
if (!playerFolder.mkdirs()) {
throw new IllegalStateException("Cannot create '" + playerFolder.getAbsolutePath() + "'");
}
Files.copy(TestHelper.getJarPath(FileUtils.makePath(SOURCE_FOLDER, "sample-folder", "data.json")), new File(playerFolder, "data.json").toPath());
}
use of ch.jalu.injector.testing.BeforeInjecting in project AuthMeReloaded by AuthMe.
the class WelcomeMessageConfigurationTest method createPluginFolder.
@BeforeInjecting
public void createPluginFolder() throws IOException {
testPluginFolder = temporaryFolder.newFolder();
welcomeFile = new File(testPluginFolder, "welcome.txt");
welcomeFile.createNewFile();
}
Aggregations