Final account tests

This commit is contained in:
Stuart Boston
2015-02-23 10:13:42 +00:00
parent 9ea18f546d
commit e9ef62d031
7 changed files with 69 additions and 279 deletions
@@ -22,6 +22,9 @@ package com.omertron.themoviedbapi.methods;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.model.list.MovieFavorite;
import com.omertron.themoviedbapi.model.list.TVFavorite;
import com.omertron.themoviedbapi.model.list.UserList;
import com.omertron.themoviedbapi.tools.HttpTools;
import com.omertron.themoviedbapi.wrapper.WrapperGenericList;
import java.io.IOException;
@@ -46,6 +49,12 @@ public class AbstractMethod {
protected static final ObjectMapper MAPPER = new ObjectMapper();
// Logger
protected static final Logger LOG = LoggerFactory.getLogger(TmdbAccount.class);
protected static final TypeReference<WrapperGenericList<MovieFavorite>> TR_MOVIE_FAV = new TypeReference<WrapperGenericList<MovieFavorite>>() {
};
protected static final TypeReference<WrapperGenericList<TVFavorite>> TR_TV_FAV = new TypeReference<WrapperGenericList<TVFavorite>>() {
};
protected static final TypeReference<WrapperGenericList<UserList>> TR_USER_LIST = new TypeReference<WrapperGenericList<UserList>>() {
};
/**
* Default constructor for the methods
@@ -62,22 +71,23 @@ public class AbstractMethod {
* Process the wrapper list and return the results
*
* @param <T> Type of list to process
* @param typeRef
* @param url URL of the page (Error output only)
* @param errorMessageSuffix Error message to output (Error output only)
* @return
* @throws MovieDbException
*/
public <T> List<T> processWrapperList(URL url, String errorMessageSuffix) throws MovieDbException {
public <T> List<T> processWrapperList(TypeReference typeRef, URL url, String errorMessageSuffix) throws MovieDbException {
String webpage = httpTools.getRequest(url);
try {
TypeReference<WrapperGenericList<T>> ref = new TypeReference<WrapperGenericList<T>>() {
};
WrapperGenericList<T> results = MAPPER.readValue(webpage, ref);
// Due to type erasure, this doesn't work
// TypeReference<WrapperGenericList<T>> typeRef = new TypeReference<WrapperGenericList<T>>() {};
WrapperGenericList<T> results = MAPPER.readValue(webpage, typeRef);
return results.getResults();
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get " + errorMessageSuffix, url, ex);
}
}
}