Skip to content

Commit 286ede3

Browse files
committed
* added integration testin g
1 parent 0ab8fb5 commit 286ede3

4 files changed

Lines changed: 71 additions & 10 deletions

File tree

src/main/java/de/linsin/sample/github/rest/domain/Issue.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ public boolean equals(Object o) {
9595

9696
Issue issue = (Issue) o;
9797

98-
if (number != issue.number) return false;
99-
100-
return true;
98+
return number == issue.number;
10199
}
102100

103101
@Override

src/main/java/de/linsin/sample/github/rest/domain/Repository.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ public boolean equals(Object o) {
104104

105105
Repository that = (Repository) o;
106106

107-
if (url != null ? !url.equals(that.url) : that.url != null) return false;
108-
109-
return true;
107+
return !(url != null ? !url.equals(that.url) : that.url != null);
110108
}
111109

112110
@Override

src/main/java/de/linsin/sample/github/rest/service/RepositoryBrowser.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ public class RepositoryBrowser {
2525
* Browse repositories for a user
2626
*
2727
* @param argUsername {@link String} username
28-
* @return {@link List} containing {@link Repository} instances, empty List if no repositories are found
29-
* @throws {@link NullPointerException} in case passed username is null
28+
* @return {@link List} containing {@link Repository} instances, empty List if user exists, but has no repositories
29+
* @throws a {@link NullPointerException} in case passed username is null
30+
* @throws a {@link HttpClientErrorException} in case the user doesn't exist
3031
*/
3132
public List<Repository> browse(String argUsername) {
3233
RestTemplate template = initTemplate();
@@ -43,8 +44,9 @@ public List<Repository> browse(String argUsername) {
4344
*
4445
* @param argUsername {@link String} username
4546
* @param argRepositoryname {@link String} name of repository
46-
* @return {@link Repository} instance denoted by passed user and repository name, null if no repository was found
47-
* @throws {@link NullPointerException} in case passed username or repository name is null
47+
* @return {@link Repository} instance denoted by passed user and repository name
48+
* @throws a {@link NullPointerException} in case passed username or repository name is null
49+
* @throws a {@link HttpClientErrorException} in case passed user or repository doesn't exist
4850
*/
4951
public Repository browse(String argUsername, String argRepositoryname) {
5052
RestTemplate template = initTemplate();
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package de.linsin.sample.github.rest.service;
2+
3+
import java.util.List;
4+
5+
import de.linsin.sample.github.rest.domain.Repository;
6+
import static org.junit.Assert.*;
7+
import org.junit.Before;
8+
import org.junit.Test;
9+
import org.springframework.web.client.HttpClientErrorException;
10+
11+
/**
12+
* Testing {@link RepositoryBrowserIntegration}
13+
*
14+
* @author David Linsin - [email protected]
15+
*/
16+
public class RepositoryBrowserIntegrationTest {
17+
private RepositoryBrowser classUnderTest;
18+
private String username;
19+
private String repoName;
20+
21+
@Before
22+
public void setUp() {
23+
username = "dlinsin";
24+
repoName = "area51";
25+
classUnderTest = new RepositoryBrowser();
26+
}
27+
28+
@Test
29+
public void browse_repos() {
30+
List<Repository> repositoryList = classUnderTest.browse(username);
31+
assertFalse(repositoryList.isEmpty());
32+
assertEquals(repoName, repositoryList.get(0).getName());
33+
assertEquals(username, repositoryList.get(0).getOwner());
34+
}
35+
36+
@Test
37+
public void browse_repo() {
38+
Repository repository = classUnderTest.browse(username, repoName);
39+
assertNotNull(repository);
40+
assertEquals(repoName, repository.getName());
41+
assertEquals(username, repository.getOwner());
42+
}
43+
44+
@Test(expected = HttpClientErrorException.class)
45+
public void browse_user_not_found() {
46+
classUnderTest.browse("dlinsin34323");
47+
}
48+
49+
@Test(expected = HttpClientErrorException.class)
50+
public void browse_repo_user_nothing_found() {
51+
classUnderTest.browse("dlinsin2342", "no_way");
52+
}
53+
54+
@Test(expected = NullPointerException.class)
55+
public void browse_repos_passed_null() {
56+
classUnderTest.browse(null);
57+
}
58+
59+
@Test(expected = NullPointerException.class)
60+
public void browse_repo_passed_null() {
61+
classUnderTest.browse(null, repoName);
62+
}
63+
}

0 commit comments

Comments
 (0)