Skip to content

Commit

Permalink
(#1417) Added tests for MkNotifications + fixed bugs in iterate() and
Browse files Browse the repository at this point in the history
get()
  • Loading branch information
llorllale committed Jun 6, 2018
1 parent dfe7f7c commit 95fa3ee
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/jcabi/github/mock/MkNotifications.java
Expand Up @@ -80,7 +80,7 @@ public Iterable<Notification> iterate() {
@Override
public Notification map(final XML xml) {
return MkNotifications.this.get(
Integer.valueOf(xml.xpath("id").get(0))
Integer.valueOf(xml.xpath("id/text()").get(0))
);
}
}
Expand All @@ -92,7 +92,7 @@ public Notification get(final int number) {
try {
return new MkNotification(
this.storage.xml().nodes(
this.xpath.concat(String.format("[%s]", number))
this.xpath.concat(String.format("[id = %s]", number))
).get(0)
);
} catch (final IOException ex) {
Expand Down
70 changes: 62 additions & 8 deletions src/test/java/com/jcabi/github/mock/MkNotificationsTest.java
Expand Up @@ -32,16 +32,14 @@
import com.jcabi.github.Notification;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Ignore;
import org.junit.Test;
import org.xembly.Directives;

/**
* Test case for {@link MkNotifications}.
*
* @author Piotr Pradzynski (prondzyn@gmail.com)
* @version $Id$
* @todo #1407:30min Implement more tests for MkNotifications. Also,
* un-ignore and refactor the fetchesNonEmptyListOfNotifications test.
*/
public final class MkNotificationsTest {

Expand All @@ -64,17 +62,73 @@ public void fetchesEmptyListOfNotifications() throws Exception {
* MkNotifications can fetch non empty list of Notifications.
* @throws Exception If some problem inside
*/
@Ignore
@Test
public void fetchesNonEmptyListOfNotifications() throws Exception {
final int size = 5;
final MkStorage storage = new MkStorage.InFile();
storage.apply(
new Directives().xpath("/github")
.add("notifications")
.add("notification")
.add("id").set("1").up().up()
.add("notification")
.add("id").set("2").up().up()
.add("notification")
.add("id").set("3").up().up()
);
MatcherAssert.assertThat(
new MkNotifications(
new MkStorage.InFile(),
"test"
storage,
"/github/notifications/notification"
).iterate(),
Matchers.<Notification>iterableWithSize(size)
Matchers.<Notification>iterableWithSize(3)
);
}

/**
* MkNotifications can fetch a notification by id.
* @throws Exception If something goes wrong
*/
@Test
public void fetchesNotificationById() throws Exception {
final MkStorage storage = new MkStorage.InFile();
storage.apply(
new Directives().xpath("/github")
.add("notifications")
.add("notification")
.add("id").set("1").up().up()
.add("notification")
.add("id").set("2").up().up()
);
MatcherAssert.assertThat(
new MkNotifications(
storage,
"/github/notifications/notification"
).get(2),
Matchers.notNullValue()
);
}

/**
* MkNotifications can fetch a notification by id.
* @throws Exception If something goes wrong
*/
@Test(expected = IndexOutOfBoundsException.class)
public void cannotFetchNotificationByNonExistentId() throws Exception {
final MkStorage storage = new MkStorage.InFile();
storage.apply(
new Directives().xpath("/github")
.add("notifications")
.add("notification")
.add("id").set("1").up().up()
.add("notification")
.add("id").set("3").up().up()
);
MatcherAssert.assertThat(
new MkNotifications(
storage,
"/github/notifications/notification"
).get(2),
Matchers.notNullValue()
);
}
}

0 comments on commit 95fa3ee

Please sign in to comment.