Skip to content

Commit

Permalink
#876 Fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosmiranda committed Jul 18, 2014
1 parent 366f046 commit f0c319d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 19 deletions.
26 changes: 17 additions & 9 deletions src/test/java/com/jcabi/github/RtDeployKeysTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,24 @@ public void canFetchSingleDeployKey() throws IOException {
@Test
public void canCreateDeployKey() throws IOException {
final int number = 2;
final DeployKeys keys = new RtDeployKeys(
new FakeRequest()
.withStatus(HttpURLConnection.HTTP_CREATED)
.withBody(String.format("{\"id\":%d}", number)),
RtDeployKeysTest.repo()
);
MatcherAssert.assertThat(
keys.create("Title", "Key").number(),
Matchers.equalTo(number)
final MkContainer container = new MkGrizzlyContainer().next(
new MkAnswer.Simple(
HttpURLConnection.HTTP_CREATED,
String.format("{\"id\":%d}", number)
)
);
container.start();
try {
final DeployKeys keys = new RtDeployKeys(
new ApacheRequest(container.home()), RtDeployKeysTest.repo()
);
MatcherAssert.assertThat(
keys.create("Title", "Key").number(),
Matchers.equalTo(number)
);
} finally {
container.stop();
}
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/com/jcabi/github/RtReleaseAssetsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ public void listReleaseAssets() throws Exception {
*/
@Test
public void uploadReleaseAsset() throws Exception {
final String body = "{\"id\":1}";
final ReleaseAssets assets = new RtReleaseAssets(
new FakeRequest().withStatus(HttpURLConnection.HTTP_CREATED)
.withBody("{\"id\":1}"),
.withBody(body),
release()
);
MatcherAssert.assertThat(
assets.upload("blah".getBytes(), "text/plain", "hello.txt")
assets.upload(body.getBytes(), "text/plain", "hello.txt")
.number(),
Matchers.is(1)
);
Expand Down
29 changes: 21 additions & 8 deletions src/test/java/com/jcabi/github/RtUserEmailsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
*/
package com.jcabi.github;

import com.jcabi.http.mock.MkAnswer;
import com.jcabi.http.mock.MkContainer;
import com.jcabi.http.mock.MkGrizzlyContainer;
import com.jcabi.http.request.ApacheRequest;
import com.jcabi.http.request.FakeRequest;
import java.net.HttpURLConnection;
import java.util.Collections;
Expand Down Expand Up @@ -70,15 +74,24 @@ public void fetchesEmails() throws Exception {
@Test
public void addsEmails() throws Exception {
final String email = "[email protected]";
final UserEmails emails = new RtUserEmails(
new FakeRequest()
.withStatus(HttpURLConnection.HTTP_CREATED)
.withBody(String.format("[{\"email\":\"%s\"}]", email))
);
MatcherAssert.assertThat(
emails.add(Collections.singletonList(email)).iterator().next(),
Matchers.equalTo(email)
final MkContainer container = new MkGrizzlyContainer().next(
new MkAnswer.Simple(
HttpURLConnection.HTTP_CREATED,
String.format("[{\"email\":\"%s\"}]", email)
)
);
container.start();
try {
final UserEmails emails = new RtUserEmails(
new ApacheRequest(container.home())
);
MatcherAssert.assertThat(
emails.add(Collections.singletonList(email)).iterator().next(),
Matchers.equalTo(email)
);
} finally {
container.stop();
}
}

/**
Expand Down

0 comments on commit f0c319d

Please sign in to comment.