- Move console initialization for tests into TestHelper - Remove unused properties in legacy Settings - Add issue number to TODO comments where applicable
72 lines
2.4 KiB
Java
72 lines
2.4 KiB
Java
package fr.xephi.authme.converter;
|
|
|
|
import com.google.common.io.Files;
|
|
import fr.xephi.authme.TestHelper;
|
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
|
import fr.xephi.authme.datasource.DataSource;
|
|
import fr.xephi.authme.datasource.FlatFile;
|
|
import org.junit.Before;
|
|
import org.junit.BeforeClass;
|
|
import org.junit.Rule;
|
|
import org.junit.Test;
|
|
import org.junit.rules.TemporaryFolder;
|
|
import org.mockito.ArgumentCaptor;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.util.List;
|
|
|
|
import static fr.xephi.authme.AuthMeMatchers.hasAuthBasicData;
|
|
import static fr.xephi.authme.AuthMeMatchers.hasAuthLocation;
|
|
import static org.hamcrest.Matchers.hasItem;
|
|
import static org.junit.Assert.assertThat;
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.times;
|
|
import static org.mockito.Mockito.verify;
|
|
|
|
/**
|
|
* Test for {@link ForceFlatToSqlite}.
|
|
*/
|
|
public class ForceFlatToSqliteTest {
|
|
|
|
@Rule
|
|
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
|
|
|
private FlatFile flatFile;
|
|
|
|
@BeforeClass
|
|
public static void setup() {
|
|
TestHelper.setupLogger();
|
|
}
|
|
|
|
@Before
|
|
public void copyFile() throws IOException {
|
|
File source = TestHelper.getJarFile("/datasource-integration/flatfile-test.txt");
|
|
File destination = temporaryFolder.newFile();
|
|
Files.copy(source, destination);
|
|
flatFile = new FlatFile(destination);
|
|
}
|
|
|
|
@Test
|
|
public void shouldConvertToSqlite() {
|
|
// given
|
|
DataSource dataSource = mock(DataSource.class);
|
|
ForceFlatToSqlite converter = new ForceFlatToSqlite(flatFile, dataSource);
|
|
|
|
// when
|
|
converter.run();
|
|
|
|
// then
|
|
ArgumentCaptor<PlayerAuth> authCaptor = ArgumentCaptor.forClass(PlayerAuth.class);
|
|
verify(dataSource, times(7)).saveAuth(authCaptor.capture());
|
|
List<PlayerAuth> auths = authCaptor.getAllValues();
|
|
assertThat(auths, hasItem(hasAuthBasicData("bobby", "Bobby", "your@email.com", "123.45.67.89")));
|
|
assertThat(auths, hasItem(hasAuthLocation(1.05, 2.1, 4.2, "world")));
|
|
assertThat(auths, hasItem(hasAuthBasicData("user", "user", "user@example.org", "34.56.78.90")));
|
|
assertThat(auths, hasItem(hasAuthLocation(124.1, 76.3, -127.8, "nether")));
|
|
assertThat(auths, hasItem(hasAuthBasicData("eightfields", "eightFields", "your@email.com", "6.6.6.66")));
|
|
assertThat(auths, hasItem(hasAuthLocation(8.8, 17.6, 26.4, "eightworld")));
|
|
}
|
|
|
|
}
|