Skip to content

Commit f1af545

Browse files
committed
Test stubs.
1 parent ad08a49 commit f1af545

File tree

5 files changed

+75
-75
lines changed

5 files changed

+75
-75
lines changed

core/src/test/java/com/github/api/v2/services/BaseGitHubServiceTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
*/
44
package com.github.api.v2.services;
55

6+
import java.io.BufferedReader;
7+
import java.io.IOException;
8+
import java.io.InputStream;
9+
import java.io.InputStreamReader;
610
import java.util.Collection;
711

812
import junit.framework.TestCase;
@@ -54,4 +58,39 @@ protected static void assertNotNullOrEmpty(String message, Collection<?> value)
5458
assertNotNull(message, value);
5559
assertFalse(message, value.isEmpty());
5660
}
61+
62+
/**
63+
* Convert stream to string.
64+
*
65+
* @param is the is
66+
*
67+
* @return the string
68+
*/
69+
protected static String convertStreamToString(InputStream is) {
70+
/*
71+
* To convert the InputStream to String we use the BufferedReader.readLine()
72+
* method. We iterate until the BufferedReader return null which means
73+
* there's no more data to read. Each line will appended to a StringBuilder
74+
* and returned as String.
75+
*/
76+
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
77+
StringBuilder sb = new StringBuilder();
78+
79+
String line = null;
80+
try {
81+
while ((line = reader.readLine()) != null) {
82+
sb.append(line + "\n");
83+
}
84+
} catch (IOException e) {
85+
e.printStackTrace();
86+
} finally {
87+
try {
88+
is.close();
89+
} catch (IOException e) {
90+
e.printStackTrace();
91+
}
92+
}
93+
94+
return sb.toString();
95+
}
5796
}

core/src/test/java/com/github/api/v2/services/GistServiceTest.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package com.github.api.v2.services;
22

3+
import java.io.InputStream;
4+
import java.util.List;
5+
36
import org.junit.After;
47
import org.junit.Before;
58
import org.junit.Test;
69

10+
import com.github.api.v2.schema.Gist;
11+
712
public class GistServiceTest extends BaseGitHubServiceTest {
813
private GistService service;
914

@@ -21,17 +26,19 @@ public void tearDown() throws Exception {
2126

2227
@Test
2328
public void testGetGist() {
24-
fail("Not yet implemented");
29+
Gist gist = service.getGist("");
30+
assertNotNull("Gist cannot be null", gist);
2531
}
2632

2733
@Test
2834
public void testGetGistContent() {
29-
fail("Not yet implemented");
35+
InputStream gistContent = service.getGistContent("", "");
36+
assertNotNullOrEmpty("Gist content cannot be null or empty", convertStreamToString(gistContent));
3037
}
3138

3239
@Test
3340
public void testGetUserGists() {
34-
fail("Not yet implemented");
41+
List<Gist> gists = service.getUserGists("");
42+
assertNotNullOrEmpty("Gists cannot be null or empty.", gists);
3543
}
36-
3744
}

core/src/test/java/com/github/api/v2/services/GitHubJsonServiceTest.java

Lines changed: 0 additions & 63 deletions
This file was deleted.

core/src/test/java/com/github/api/v2/services/NetworkServiceTest.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package com.github.api.v2.services;
22

3+
import java.util.List;
4+
35
import org.junit.After;
46
import org.junit.Before;
57
import org.junit.Test;
68

9+
import com.github.api.v2.schema.Commit;
10+
import com.github.api.v2.schema.Network;
11+
712
public class NetworkServiceTest extends BaseGitHubServiceTest {
813
private NetworkService service;
914

@@ -21,17 +26,20 @@ public void tearDown() throws Exception {
2126

2227
@Test
2328
public void testGetNetworkDataStringStringString() {
24-
fail("Not yet implemented");
29+
List<Commit> commits = service.getNetworkData("", "", "");
30+
assertNotNullOrEmpty("Commits should not be null or empty.", commits);
2531
}
2632

2733
@Test
2834
public void testGetNetworkDataStringStringStringIntInt() {
29-
fail("Not yet implemented");
35+
List<Commit> commits = service.getNetworkData("", "", "", 1, 5);
36+
assertNotNullOrEmpty("Commits should not be null or empty.", commits);
3037
}
3138

3239
@Test
3340
public void testGetNetworkMeta() {
34-
fail("Not yet implemented");
41+
Network networkMeta = service.getNetworkMeta("", "");
42+
assertNotNull("Network cannot be null", networkMeta);
3543
}
3644

3745
}

core/src/test/java/com/github/api/v2/services/ObjectServiceTest.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
package com.github.api.v2.services;
22

3+
import java.io.InputStream;
4+
import java.util.List;
5+
36
import org.junit.After;
47
import org.junit.Before;
58
import org.junit.Test;
69

10+
import com.github.api.v2.schema.Blob;
11+
import com.github.api.v2.schema.Tree;
12+
713
public class ObjectServiceTest extends BaseGitHubServiceTest {
814
private ObjectService service;
915

@@ -21,22 +27,25 @@ public void tearDown() throws Exception {
2127

2228
@Test
2329
public void testGetBlob() {
24-
fail("Not yet implemented");
30+
Blob blob = service.getBlob("", "", "", "");
31+
assertNotNull("Blob cannot be null or empty", blob);
2532
}
2633

2734
@Test
2835
public void testGetBlobs() {
29-
fail("Not yet implemented");
36+
List<Blob> blobs = service.getBlobs("", "", "");
37+
assertNotNullOrEmpty("Blobs cannot be null or empty", blobs);
3038
}
3139

3240
@Test
3341
public void testGetObjectContent() {
34-
fail("Not yet implemented");
42+
InputStream objectContent = service.getObjectContent("", "", "");
43+
assertNotNullOrEmpty("Object content cannot be null or empty", convertStreamToString(objectContent));
3544
}
3645

3746
@Test
3847
public void testGetTree() {
39-
fail("Not yet implemented");
48+
List<Tree> trees = service.getTree("", "", "");
49+
assertNotNullOrEmpty("Tree cannot be null or empty", trees);
4050
}
41-
4251
}

0 commit comments

Comments
 (0)