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)); } }