Skip to content

Commit

Permalink
added StackAPI interface and StackMockAPI alternative
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomis committed Sep 7, 2015
1 parent e8f2a89 commit f672c0d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions grails-app/services/net/zomis/duga/StackAPI.groovy
@@ -0,0 +1,5 @@
package net.zomis.duga

interface StackAPI {
def apiCall(String apiCall, String site, String filter) throws IOException;
}
3 changes: 2 additions & 1 deletion grails-app/services/net/zomis/duga/StackExchangeAPI.groovy
Expand Up @@ -7,7 +7,7 @@ import java.util.zip.GZIPInputStream;

import org.springframework.beans.factory.annotation.Autowired;

class StackExchangeAPI {
class StackExchangeAPI implements StackAPI {

@Autowired
private Environment config;
Expand All @@ -28,6 +28,7 @@ class StackExchangeAPI {
+ "&filter=" + filter + "&key=" + apiKey);
}

@Override
def apiCall(String apiCall, String site, String filter) throws IOException {
final String apiKey = config.getProperty('stackAPI');
URL url = buildURL(apiCall, site, filter, apiKey);
Expand Down
@@ -0,0 +1,21 @@
package net.zomis.duga.tasks.qscan

import net.zomis.duga.StackAPI

class StackMockAPI implements StackAPI {

Map results = [:]

StackMockAPI expect(String apiCall, def result) {
results.put(apiCall, result)
this
}

@Override
def apiCall(String apiCall, String site, String filter) throws IOException {
def result = results.get(apiCall)
assert result : "No mock result defined for $apiCall. Keys are ${results.keySet()}"
result
}

}

0 comments on commit f672c0d

Please sign in to comment.