Changeset View
Changeset View
Standalone View
Standalone View
src/test/java/net/wildfyre/posts/PostTest.java
Show All 14 Lines | |||||
*/ | */ | ||||
package net.wildfyre.posts; | package net.wildfyre.posts; | ||||
import net.wildfyre.areas.Area; | import net.wildfyre.areas.Area; | ||||
import net.wildfyre.areas.Areas; | import net.wildfyre.areas.Areas; | ||||
import net.wildfyre.http.RequestTest; | import net.wildfyre.http.RequestTest; | ||||
import net.wildfyre.users.Users; | import net.wildfyre.users.Users; | ||||
import net.wildfyre.posts.Post; | |||||
import org.junit.Before; | import org.junit.Before; | ||||
import org.junit.Test; | import org.junit.Test; | ||||
import java.util.List; | import java.util.List; | ||||
import com.eclipsesource.json.JsonObject; | |||||
import static org.junit.Assert.*; | import static org.junit.Assert.*; | ||||
public class PostTest { | public class PostTest { | ||||
@Before | @Before | ||||
public void before() { | public void before() { | ||||
RequestTest.Companion.connectToTestDB(); | RequestTest.Companion.connectToTestDB(); | ||||
} | } | ||||
Show All 13 Lines | public void myPosts(){ | ||||
assertTrue(p1.toString(), p1.author().isPresent()); | assertTrue(p1.toString(), p1.author().isPresent()); | ||||
assertEquals(p1.toString(), Users.me(), p1.author().get()); | assertEquals(p1.toString(), Users.me(), p1.author().get()); | ||||
Post p2 = posts.stream().filter(PostData::isAnonymous).findFirst().orElseThrow(RuntimeException::new); | Post p2 = posts.stream().filter(PostData::isAnonymous).findFirst().orElseThrow(RuntimeException::new); | ||||
assertTrue(p2.toString(), p2.isAnonymous()); | assertTrue(p2.toString(), p2.isAnonymous()); | ||||
assertTrue(p2.toString(), p2.hasSubscribed()); | assertTrue(p2.toString(), p2.hasSubscribed()); | ||||
assertTrue(p2.toString(), p2.isActive()); | assertTrue(p2.toString(), p2.isActive()); | ||||
assertFalse(p2.toString(), p2.author().isPresent()); | assertFalse(p2.toString(), p2.author().isPresent()); | ||||
assertTrue(p1.equals(p1)); | |||||
assertFalse(p1.equals(p2)); | |||||
WyldBot: Suppose to have a console here? | |||||
Done Inline ActionsOops. My bad. I'll remove tomorrow Hackintosh5: Oops. My bad. I'll remove tomorrow | |||||
assertEquals(new Post((PostData)p1), p1); | |||||
assertEquals(p2.commentsList().size(), 2); | |||||
assertEquals(p2.commentsList().get(0), p2.comments().findFirst().get()); | |||||
Comment c1 = p2.commentsList().get(0); | |||||
JsonObject data = new JsonObject(); | |||||
Done Inline ActionsReplace by: data["id"] = c1.ID() CLOVIS: Replace by:
`data["id"] = c1.ID()` | |||||
Done Inline ActionsThis isn't a Kotlin test. Are you sure that works in Java? Iirc it doesn't, but it's been a while. Hackintosh5: This isn't a Kotlin test. Are you sure that works in Java? Iirc it doesn't, but it's been a… | |||||
Done Inline Actions> Task :compileTestJava FAILED /home/penn/libwf-java/src/test/java/net/wildfyre/posts/PostTest.java:72: error: incompatible types: String cannot be converted to int data["id"] = c1.ID(); ^ /home/penn/libwf-java/src/test/java/net/wildfyre/posts/PostTest.java:72: error: array required, but JsonObject found data["id"] = c1.ID(); ^ 2 errors FAILURE: Build failed with an exception. Hackintosh5: ```
> Task :compileTestJava FAILED
/home/penn/libwf… | |||||
Done Inline ActionsOh I forgot that part wasn't translated yet. My bad. CLOVIS: Oh I forgot that part wasn't translated yet. My bad. | |||||
data.set("id", c1.ID()); | |||||
JsonObject author = new JsonObject(); | |||||
author.set("user", c1.author().getID()); | |||||
data.set("author", author); | |||||
data.set("created", c1.created().toString()); | |||||
data.set("text", c1.text()); | |||||
data.set("imageURL", c1.imageURL().orElse("")); | |||||
Comment c2 = new Comment(p2, data); | |||||
assertEquals(c1, c2); | |||||
assertEquals(c1.hashCode(), c2.ID()); | |||||
assertEquals(c1.area(), p2.area()); | |||||
assertEquals(c1.post(), p2); | |||||
} | } | ||||
@Test | @Test | ||||
public void createDraft(){ | public void createDraft(){ | ||||
Area a = Areas.INSTANCE.get("sample").orElseThrow(RuntimeException::new); | Area a = Areas.INSTANCE.get("sample").orElseThrow(RuntimeException::new); | ||||
Draft d = a.draft() | Draft d = a.draft() | ||||
.setText("This is a test") | .setText("This is a test (1)") | ||||
.setIsAnonymous(false) | .setIsAnonymous(false) | ||||
.subscribe() | .subscribe() | ||||
.save(); | .save(); | ||||
assertNotEquals(-1, d.postID); | assertNotEquals(-1, d.postID); | ||||
// Post p = d.publish(); | |||||
// assertEquals(p.text(), "This is a test (1)"); | |||||
Done Inline ActionsWe can't test this, because the server saves it and there's no Post.delete() Hackintosh5: We can't test this, because the server saves it and there's no Post.delete() | |||||
// p.delete(); | |||||
d = a.draft() | |||||
.setText("This is a test (2)") | |||||
.setIsAnonymous(false) | |||||
.subscribe(); | |||||
// p = d.publish(); | |||||
// assertEquals(p.text(), "This is a test (2)"); | |||||
// p.delete(); | |||||
d = a.draft() | |||||
.setText("This is a test (3)") | |||||
.setIsAnonymous(true) | |||||
.subscribe() | |||||
.save() | |||||
.setText("This is a test (4)") | |||||
.save(); | |||||
assertEquals(d.text(), "This is a test (4)"); | |||||
d.delete(); | d.delete(); | ||||
} | } | ||||
} | } |
Suppose to have a console here?