Skip to content
This repository has been archived by the owner on Dec 5, 2020. It is now read-only.

Commit

Permalink
unit tests for Notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Oct 27, 2017
1 parent 9940c56 commit d950b3c
Show file tree
Hide file tree
Showing 6 changed files with 312 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
*/
public abstract class Notifications implements Iterable<Notification>{

/**
* All of them.
*/
protected final List<Notification> notifications = new ArrayList<>();
@Override
public Iterator<Notification> iterator() {
return this.notifications.iterator();
}
/**
* All of them.
*/
protected final List<Notification> notifications = new ArrayList<>();
@Override
public Iterator<Notification> iterator() {
return this.notifications.iterator();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
*
*/
public final class SimplifiedNotifications extends Notifications {
/**
* Ctor.
* @param all All notifications as String.
*/
public SimplifiedNotifications(final String all) {
final JsonArray array = Json.createReader(new StringReader(all)).readArray();
for(final JsonValue json : array) {
super.notifications.add(new SimpleJsonNotification((JsonObject) json));
}
}
/**
* Ctor.
* @param all All notifications as String.
*/
public SimplifiedNotifications(final String all) {
final JsonArray array = Json.createReader(new StringReader(all)).readArray();
for(final JsonValue json : array) {
super.notifications.add(new SimpleJsonNotification((JsonObject) json));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

public final class WebhookNotifications extends Notifications {

/**
* Ctor.
* @param all All webhook notifications
*/
public WebhookNotifications(final JsonObject... all) {
for(final JsonObject json : all) {
super.notifications.add(new IssueCommentNotification(json));
}
}
/**
* Ctor.
* @param all All webhook notifications
*/
public WebhookNotifications(final JsonObject... all) {
for(final JsonObject json : all) {
super.notifications.add(new IssueCommentNotification(json));
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* Copyright (c) 2016-2017, Mihai Emil Andronache
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1)Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2)Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3)Neither the name of charles-rest nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.amihaiemil.charles.rest.model;

import javax.json.Json;

import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;

/**
* Unit tests for {@link IssueCommentNotification}
* @author Mihai Andronache ([email protected])
* @version $Id$
* @since 1.0.2
*
*/
public final class IssueCommentNotificationTestCase {

/**
* A IssueCommentNotification has an issue number.
*/
@Test
public void hasIssueNumber() {
final Notification notification = new IssueCommentNotification(
Json.createObjectBuilder()
.add(
"issue",
Json.createObjectBuilder().add("number", 456).build()
)
.build()
);
MatcherAssert.assertThat(notification.issueNumber(), Matchers.is(456));
}

/**
* A IssueCommentNotification has a repository fullname.
*/
@Test
public void hasRepoFullName() {
final Notification notification = new IssueCommentNotification(
Json.createObjectBuilder()
.add(
"repository",
Json.createObjectBuilder().add("full_name", "jeff/test").build()
)
.build()
);
MatcherAssert.assertThat(notification.repoFullName(), Matchers.equalTo("jeff/test"));
}

/**
* A IssueCommentNotification has all its attributes.
*/
@Test
public void isComplete() {
final Notification notification = new IssueCommentNotification(
Json.createObjectBuilder()
.add(
"issue",
Json.createObjectBuilder().add("number", 899).build()
)
.add(
"repository",
Json.createObjectBuilder().add("full_name", "jeff/test").build()
)
.build()
);
MatcherAssert.assertThat(notification.issueNumber(), Matchers.is(899));
MatcherAssert.assertThat(notification.repoFullName(), Matchers.equalTo("jeff/test"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
* Copyright (c) 2016-2017, Mihai Emil Andronache
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1)Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2)Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3)Neither the name of charles-rest nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.amihaiemil.charles.rest.model;

import javax.json.Json;

import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;

/**
* Unit tests for {@link SimplifiedNotifications}
* @author Mihai Andronache ([email protected])
* @version $Id$
* @since 1.0.2
*
*/
@SuppressWarnings("unused")
public final class SimplifiedNotificationsTestCase {


/**
* SimplifiedNotifications can iterate over all of them.
*/
@Test
public void iteratesOverAll() {
final Notifications notifs = new SimplifiedNotifications(
Json.createArrayBuilder()
.add(Json.createObjectBuilder().add("repoFullName", "jeff/test").add("issueNumber", 123).build())
.add(Json.createObjectBuilder().add("repoFullName", "mary/tesla").add("issueNumber", 458).build())
.add(Json.createObjectBuilder().add("repoFullName", "john/doe-repo").add("issueNumber", 142).build())
.build()
.toString()
);
int size = 0;
for(final Notification n : notifs) {
size++;
}
MatcherAssert.assertThat(size, Matchers.is(3));
}

/**
* SimplifiedNotifications can iterate over a single notification.
*/
@Test
public void iteratesOverOne() {
final Notifications notifs = new SimplifiedNotifications(
Json.createArrayBuilder()
.add(Json.createObjectBuilder().add("repoFullName", "mary/tesla").add("issueNumber", 458).build())
.build()
.toString()
);
int size = 0;
for(final Notification n : notifs) {
size++;
}
MatcherAssert.assertThat(size, Matchers.is(1));
}

/**
* SimplifiedNotifications can iterate over no notification (it is empty).
*/
@Test
public void iteratesOverNone() {
final Notifications notifs = new SimplifiedNotifications(
Json.createArrayBuilder()
.build()
.toString()
);
int size = 0;
for(final Notification n : notifs) {
size++;
}
MatcherAssert.assertThat(size, Matchers.is(0));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* Copyright (c) 2016-2017, Mihai Emil Andronache
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1)Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2)Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3)Neither the name of charles-rest nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.amihaiemil.charles.rest.model;

import javax.json.Json;
import javax.json.JsonObject;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;

/**
* Unit tests for {@link WebhookNotifications}
* @author Mihai Andronache ([email protected])
* @version $Id$
* @since 1.0.2
*
*/
@SuppressWarnings("unused")
public final class WebhookNotificationsTestCase {

/**
* WebhookNotifications can iterate over all of them.
*/
@Test
public void iteratesOverAll() {
final Notifications notifs = new WebhookNotifications(
Json.createObjectBuilder().build(),
Json.createObjectBuilder().build(),
Json.createObjectBuilder().build(),
Json.createObjectBuilder().build()
);
int size = 0;
for(final Notification n : notifs) {
size++;
}
MatcherAssert.assertThat(size, Matchers.is(4));
}

/**
* WebhookNotifications can iterate over a single notification.
*/
@Test
public void iteratesOverOne() {
final Notifications notifs = new WebhookNotifications(
Json.createObjectBuilder().build()
);
int size = 0;
for(final Notification n : notifs) {
size++;
}
MatcherAssert.assertThat(size, Matchers.is(1));
}

/**
* WebhookNotifications can iterate over no notification (it is empty).
*/
@Test
public void iteratesOverNone() {
final Notifications notifs = new WebhookNotifications(new JsonObject[]{});
int size = 0;
for(final Notification n : notifs) {
size++;
}
MatcherAssert.assertThat(size, Matchers.is(0));
}
}

7 comments on commit d950b3c

@0pdd
Copy link

@0pdd 0pdd commented on d950b3c Oct 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 150-f4a028a1 disappeared from src/main/java/com/amihaiemil/charles/aws/AmazonEsRepository.java, that's why I closed #157.

@0pdd
Copy link

@0pdd 0pdd commented on d950b3c Oct 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 150-d3633346 disappeared from src/main/java/com/amihaiemil/charles/aws/AmazonEsSuggest.java, that's why I closed #158.

@0pdd
Copy link

@0pdd 0pdd commented on d950b3c Oct 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 150-54535ee7 disappeared from src/main/java/com/amihaiemil/charles/aws/SuggestQuery.java, that's why I closed #159.

@0pdd
Copy link

@0pdd 0pdd commented on d950b3c Oct 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 150-47fee5a9 disappeared from src/main/java/com/amihaiemil/charles/aws/SuggestionsResponseHandler.java, that's why I closed #160.

@0pdd
Copy link

@0pdd 0pdd commented on d950b3c Oct 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 176-a617e601 disappeared from src/main/java/com/amihaiemil/charles/github/Command.java, that's why I closed #185.

@0pdd
Copy link

@0pdd 0pdd commented on d950b3c Oct 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 199-aff84e88 disappeared from src/main/java/com/amihaiemil/charles/aws/SystemProperty.java, that's why I closed #201.

@0pdd
Copy link

@0pdd 0pdd commented on d950b3c Oct 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 250-d7d97575 disappeared from src/main/java/com/amihaiemil/charles/aws/AmazonEsRepository.java, that's why I closed #261.

Please sign in to comment.