Skip to content

Commit 498acfe

Browse files
committed
* added base classe for browsers
* added TestSuit to run tests * removed dummy class used for start up
1 parent 1acb75b commit 498acfe

5 files changed

Lines changed: 73 additions & 62 deletions

File tree

src/main/java/de/linsin/github/StartUp.java

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2009 David Linsin
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
package de.linsin.github.rest.service;
17+
18+
import org.springframework.web.client.RestTemplate;
19+
import org.springframework.http.converter.HttpMessageConverter;
20+
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
21+
22+
/**
23+
* Base class containing methods used by all flavors of browsers
24+
*
25+
* @author David Linsin - [email protected]
26+
*/
27+
public abstract class Browser {
28+
/**
29+
* Used to initialize the {@link RestTemplate} instance used to browse, with a {@link MappingJacksonHttpMessageConverter}
30+
*
31+
* @return {@link RestTemplate} instance
32+
*/
33+
protected RestTemplate initTemplate() {
34+
RestTemplate template = new RestTemplate();
35+
template.setMessageConverters(new HttpMessageConverter[] {new MappingJacksonHttpMessageConverter()});
36+
return template;
37+
}
38+
}

src/main/java/de/linsin/github/rest/service/IssueBrowser.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020
import java.util.List;
2121

2222
import de.linsin.github.rest.domain.Issue;
23+
import de.linsin.github.rest.domain.Repository;
2324
import de.linsin.github.rest.resource.IssueRequest;
2425
import de.linsin.github.rest.resource.IssueResponse;
2526
import de.linsin.github.rest.resource.IssuesResponse;
2627
import de.linsin.github.rest.resource.OpenIssueRequest;
27-
import de.linsin.github.rest.domain.Repository;
28-
import org.springframework.http.converter.HttpMessageConverter;
29-
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
3028
import org.springframework.util.Assert;
3129
import org.springframework.web.client.RestTemplate;
3230

@@ -36,7 +34,7 @@
3634
*
3735
* @author David Linsin - [email protected]
3836
*/
39-
public class IssueBrowser {
37+
public class IssueBrowser extends Browser {
4038
public static final String BASE_URL = "http://github.com/api/v2/json/";
4139
public static final String ISSUES_BASE_URL = BASE_URL.concat("issues/list/{username}/{repo}");
4240
public static final String ISSUE_BASE_URL = BASE_URL.concat("issues/show/{username}/{repo}");
@@ -182,10 +180,4 @@ protected List<Issue> doBrowse(Repository argRepository, String argUrl) {
182180
return Arrays.asList(resp.getIssues());
183181
}
184182
}
185-
186-
protected RestTemplate initTemplate() {
187-
RestTemplate template = new RestTemplate();
188-
template.setMessageConverters(new HttpMessageConverter[]{new MappingJacksonHttpMessageConverter()});
189-
return template;
190-
}
191183
}

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,17 @@
1919
import java.util.Collections;
2020
import java.util.List;
2121

22-
import de.linsin.github.rest.resource.RepositoriesResponse;
2322
import de.linsin.github.rest.domain.Repository;
23+
import de.linsin.github.rest.resource.RepositoriesResponse;
2424
import de.linsin.github.rest.resource.RepositoryResponse;
25-
import org.springframework.http.converter.HttpMessageConverter;
26-
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
2725
import org.springframework.web.client.RestTemplate;
2826

2927
/**
3028
* Provides methods to browser through a GitHub repository
3129
*
3230
* @author David Linsin - [email protected]
3331
*/
34-
public class RepositoryBrowser {
32+
public class RepositoryBrowser extends Browser {
3533
public static final String BASE_URL = "http://github.com/api/v2/json/";
3634
public static final String REPOSITORIES_URL = BASE_URL.concat("repos/show/{username}");
3735
public static final String REPOSITORY_URL = REPOSITORIES_URL.concat("/{repo}");
@@ -68,12 +66,4 @@ public Repository browse(String argUsername, String argRepositoryname) {
6866
RepositoryResponse resp = template.getForObject(REPOSITORY_URL, RepositoryResponse.class, argUsername, argRepositoryname);
6967
return resp.getRepository();
7068
}
71-
72-
// TODO move to base class
73-
protected RestTemplate initTemplate() {
74-
RestTemplate template = new RestTemplate();
75-
template.setMessageConverters(new HttpMessageConverter[] {new MappingJacksonHttpMessageConverter()});
76-
return template;
77-
}
78-
7969
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2009 David Linsin
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
package de.linsin.github.rest;
17+
18+
import org.junit.runner.RunWith;
19+
import org.junit.runners.Suite;
20+
import de.linsin.github.rest.service.IssueBrowserTest;
21+
import de.linsin.github.rest.service.RepositoryBrowserTest;
22+
23+
/**
24+
* TestSuit running all unit tests
25+
*
26+
* @author David Linsin - [email protected]
27+
*/
28+
@RunWith(Suite.class)
29+
@Suite.SuiteClasses({IssueBrowserTest.class, RepositoryBrowserTest.class})
30+
public class UnitTestSuit {
31+
}

0 commit comments

Comments
 (0)