Changeset View
Changeset View
Standalone View
Standalone View
src/test/java/net/wildfyre/users/UserTest.java
Show All 25 Lines | |||||
import static junit.framework.TestCase.assertEquals; | import static junit.framework.TestCase.assertEquals; | ||||
import static org.junit.Assert.*; | import static org.junit.Assert.*; | ||||
public class UserTest { | public class UserTest { | ||||
@Before | @Before | ||||
public void before() throws Request.CantConnectException { | public void before() throws Request.CantConnectException { | ||||
Internal.setToken(RequestTest.Companion.getToken()); | Internal.setToken(RequestTest.token); | ||||
Internal.init(); | Internal.init(); | ||||
} | } | ||||
@Test | @Test | ||||
public void createTest() { | public void createTest() { | ||||
int id = Users.myID().orElseThrow(RuntimeException::new); | int id = Users.myID().orElseThrow(RuntimeException::new); | ||||
User me = User.create(id); | User me = User.Companion.create(id); | ||||
assertTrue(me.toString(), me instanceof LoggedUser); | assertTrue(me.toString(), me instanceof LoggedUser); | ||||
assertTrue(me.toString(), me.canEdit()); | assertTrue(me.toString(), me.isEditable()); | ||||
int wrongId = id+1; | int wrongId = id+1; | ||||
User wrong = User.create(wrongId); | User wrong = User.Companion.create(wrongId); | ||||
assertFalse(wrong.toString(), wrong instanceof LoggedUser); | assertFalse(wrong.toString(), wrong instanceof LoggedUser); | ||||
assertFalse(wrong.toString(), wrong.canEdit()); | assertFalse(wrong.toString(), wrong.isEditable()); | ||||
} | } | ||||
@Test(timeout = 1000L) | @Test(timeout = 1000L) | ||||
public void query() { | public void query() { | ||||
User me = Users.me(); | User me = Users.me(); | ||||
assertEquals("user", me.name()); | assertEquals("user", me.getName()); | ||||
assertEquals(2, me.getID()); | assertEquals(2, me.getID()); | ||||
assertFalse(me.avatar().isPresent()); | assertNull(me.getAvatar()); | ||||
assertEquals("", me.bio()); | assertEquals("", me.getBio()); | ||||
} | } | ||||
@Test(timeout = 1000L) | @Test(timeout = 1000L) | ||||
public void testNonExistingUser() { | public void testNonExistingUser() { | ||||
Internal.setNoSuchEntityHandler(e -> { | Internal.setNoSuchEntityHandler(e -> { | ||||
throw new RuntimeException("An exception was thrown.", e); | throw new RuntimeException("An exception was thrown.", e); | ||||
}); | }); | ||||
Show All 18 Lines |