LoginSystem/src/test/java/fr/xephi/authme/data/auth/PlayerAuthTest.java
ljacqu 1df5308e56 #792 #814 Create command to remove NOT NULL constraints
- Create command under /authme debug that allows to change the 'nullable' status of MySQL columns (currently last date and email only)
   - We need to offer a default value for forum integrations that have a NOT NULL email column. Offering a command avoids us from force-migrating existing databases while still offering migrations in both directions
- Change in default value handling: lack of values are not handled by setting default values to the PlayerAuth anymore, and reading a default value from the database into a PlayerAuth will be translated into null by the PlayerAuth builder
- When a new database is created, email and lastlogin are now nullable and lack a default a value

Open points:
- Finish MySqlDefaultChangerTest
- Revise purging logic (#792)
- Allow to have more columns nullable (#814)
2017-10-15 12:56:13 +02:00

64 lines
1.6 KiB
Java

package fr.xephi.authme.data.auth;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.fail;
/**
* Test for {@link PlayerAuth} and its builder.
*/
public class PlayerAuthTest {
@Test
public void shouldRemoveDatabaseDefaults() {
// given / when
PlayerAuth auth = PlayerAuth.builder()
.name("Bobby")
.lastLogin(0L)
.email("your@email.com")
.build();
// then
assertThat(auth.getNickname(), equalTo("bobby"));
assertThat(auth.getLastLogin(), nullValue());
assertThat(auth.getEmail(), nullValue());
}
@Test
public void shouldThrowForMissingName() {
try {
// given / when
PlayerAuth.builder()
.email("test@example.org")
.groupId(3)
.build();
// then
fail("Expected exception to be thrown");
} catch (NullPointerException e) {
// all good
}
}
@Test
public void shouldCreatePlayerAuthWithNullValues() {
// given / when
PlayerAuth auth = PlayerAuth.builder()
.name("Charlie")
.email(null)
.lastLogin(null)
.groupId(19)
.locPitch(123.004f)
.build();
// then
assertThat(auth.getEmail(), nullValue());
assertThat(auth.getLastLogin(), nullValue());
assertThat(auth.getGroupId(), equalTo(19));
assertThat(auth.getPitch(), equalTo(123.004f));
}
}