Search in sources :

Example 1 with BeforeInjecting

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;
    });
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) Injector(ch.jalu.injector.Injector) PasswordEncryptionEvent(fr.xephi.authme.events.PasswordEncryptionEvent) Event(org.bukkit.event.Event) PasswordEncryptionEvent(fr.xephi.authme.events.PasswordEncryptionEvent) BeforeClass(org.junit.BeforeClass) InjectorBuilder(ch.jalu.injector.InjectorBuilder) BeforeInjecting(ch.jalu.injector.testing.BeforeInjecting)

Example 2 with BeforeInjecting

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");
}
Also used : File(java.io.File) BeforeInjecting(ch.jalu.injector.testing.BeforeInjecting)

Example 3 with BeforeInjecting

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;
    });
}
Also used : World(org.bukkit.World) File(java.io.File) BeforeInjecting(ch.jalu.injector.testing.BeforeInjecting)

Example 4 with BeforeInjecting

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());
}
Also used : File(java.io.File) BeforeInjecting(ch.jalu.injector.testing.BeforeInjecting)

Example 5 with BeforeInjecting

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();
}
Also used : File(java.io.File) BeforeInjecting(ch.jalu.injector.testing.BeforeInjecting)

Aggregations

BeforeInjecting (ch.jalu.injector.testing.BeforeInjecting)6 File (java.io.File)4 Injector (ch.jalu.injector.Injector)1 InjectorBuilder (ch.jalu.injector.InjectorBuilder)1 PasswordEncryptionEvent (fr.xephi.authme.events.PasswordEncryptionEvent)1 MessageFileHandler (fr.xephi.authme.message.MessageFileHandler)1 Function (java.util.function.Function)1 World (org.bukkit.World)1 Event (org.bukkit.event.Event)1 BeforeClass (org.junit.BeforeClass)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1