repo_name stringlengths 7 104 | file_path stringlengths 13 198 | context stringlengths 67 7.15k | import_statement stringlengths 16 4.43k | code stringlengths 40 6.98k | prompt stringlengths 227 8.27k | next_line stringlengths 8 795 |
|---|---|---|---|---|---|---|
jandy-team/jandy | jandy-server/src/main/java/io/jandy/util/api/GitHubApi.java | // Path: jandy-server/src/main/java/io/jandy/domain/cache/HttpCacheEntry.java
// public class HttpCacheEntry<T> implements Serializable {
// private String etag;
// private T body;
// private List<String> link;
//
// public String getEtag() {
// return etag;
// }
//
// public HttpCacheEntry setEtag(String etag) {
// this.etag = etag;
// return this;
// }
//
// public T getBody() {
// return body;
// }
//
// public HttpCacheEntry setBody(T body) {
// this.body = body;
// return this;
// }
//
//
// public void setLink(List<String> link) {
// this.link = link;
// }
//
// public List<String> getLink() {
// return link;
// }
// }
//
// Path: jandy-server/src/main/java/io/jandy/util/api/json/GHOrg.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// @Data
// public class GHOrg implements Serializable {
// @JsonProperty("login")
// private String login;
//
// @JsonProperty("id")
// private Long id;
//
// @JsonProperty("public_repos")
// private Integer publicRepos;
// }
//
// Path: jandy-server/src/main/java/io/jandy/util/api/json/GHRepo.java
// @Data
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class GHRepo implements Serializable {
// @JsonProperty("id")
// private Long id;
//
// @JsonProperty("owner")
// private GHUser owner;
//
// @JsonProperty("name")
// private String name;
//
// @JsonProperty("full_name")
// private String fullName;
//
// @JsonProperty("description")
// private String description;
//
// @JsonProperty("default_branch")
// private String defaultBranch;
//
// public Long getId() {
// return id;
// }
//
// public GHRepo setId(Long id) {
// this.id = id;
// return this;
// }
//
// public GHUser getOwner() {
// return owner;
// }
//
// public GHRepo setOwner(GHUser owner) {
// this.owner = owner;
// return this;
// }
//
// public String getName() {
// return name;
// }
//
// public GHRepo setName(String name) {
// this.name = name;
// return this;
// }
//
// public String getFullName() {
// return fullName;
// }
//
// public GHRepo setFullName(String fullName) {
// this.fullName = fullName;
// return this;
// }
//
// public String getDescription() {
// return description;
// }
//
// public GHRepo setDescription(String description) {
// this.description = description;
// return this;
// }
//
// public String getDefaultBranch() {
// return defaultBranch;
// }
//
// public GHRepo setDefaultBranch(String defaultBranch) {
// this.defaultBranch = defaultBranch;
// return this;
// }
// }
//
// Path: jandy-server/src/main/java/io/jandy/util/api/json/GHUser.java
// @Data
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class GHUser implements Serializable {
// @JsonProperty("id")
// private long id;
//
// @JsonProperty("login")
// private String login;
//
// @JsonProperty("avatar_url")
// private String avatarUrl;
//
// @JsonProperty("public_repos")
// private Integer publicRepos;
//
// private String email;
// }
| import io.jandy.domain.cache.HttpCacheEntry;
import io.jandy.util.api.json.GHOrg;
import io.jandy.util.api.json.GHRepo;
import io.jandy.util.api.json.GHUser;
import io.jandy.util.CachedRestTemplate;
import org.apache.commons.lang3.StringUtils;
import org.javatuples.KeyValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cache.CacheManager;
import org.springframework.security.oauth2.client.OAuth2ClientContext;
import org.springframework.stereotype.Component;
import org.springframework.web.client.*;
import java.net.URI;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern; | .build(CachedRestTemplate.class);
this.restTemplate.setAccept("application/vnd.github.v3+json");
}
public boolean isAnonymous() {
return clientContext.getAccessToken() == null;
}
public GHUser getUser() {
return getForObject("https://api.github.com/user", GHUser.class);
}
public GHUser getUser(String login) {
try {
return getForObject("https://api.github.com/users/{login}", GHUser.class, login);
} catch (HttpClientErrorException e) {
logger.error(e.getMessage(), e);
return null;
}
}
public List<GHOrg> getUserOrgs(String login) {
return Arrays.asList(getForObject("https://api.github.com/users/{login}/orgs", GHOrg[].class, login));
}
public GHOrg getOrg(String org) {
return getForObject("https://api.github.com/orgs/{org}", GHOrg.class, org);
}
| // Path: jandy-server/src/main/java/io/jandy/domain/cache/HttpCacheEntry.java
// public class HttpCacheEntry<T> implements Serializable {
// private String etag;
// private T body;
// private List<String> link;
//
// public String getEtag() {
// return etag;
// }
//
// public HttpCacheEntry setEtag(String etag) {
// this.etag = etag;
// return this;
// }
//
// public T getBody() {
// return body;
// }
//
// public HttpCacheEntry setBody(T body) {
// this.body = body;
// return this;
// }
//
//
// public void setLink(List<String> link) {
// this.link = link;
// }
//
// public List<String> getLink() {
// return link;
// }
// }
//
// Path: jandy-server/src/main/java/io/jandy/util/api/json/GHOrg.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// @Data
// public class GHOrg implements Serializable {
// @JsonProperty("login")
// private String login;
//
// @JsonProperty("id")
// private Long id;
//
// @JsonProperty("public_repos")
// private Integer publicRepos;
// }
//
// Path: jandy-server/src/main/java/io/jandy/util/api/json/GHRepo.java
// @Data
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class GHRepo implements Serializable {
// @JsonProperty("id")
// private Long id;
//
// @JsonProperty("owner")
// private GHUser owner;
//
// @JsonProperty("name")
// private String name;
//
// @JsonProperty("full_name")
// private String fullName;
//
// @JsonProperty("description")
// private String description;
//
// @JsonProperty("default_branch")
// private String defaultBranch;
//
// public Long getId() {
// return id;
// }
//
// public GHRepo setId(Long id) {
// this.id = id;
// return this;
// }
//
// public GHUser getOwner() {
// return owner;
// }
//
// public GHRepo setOwner(GHUser owner) {
// this.owner = owner;
// return this;
// }
//
// public String getName() {
// return name;
// }
//
// public GHRepo setName(String name) {
// this.name = name;
// return this;
// }
//
// public String getFullName() {
// return fullName;
// }
//
// public GHRepo setFullName(String fullName) {
// this.fullName = fullName;
// return this;
// }
//
// public String getDescription() {
// return description;
// }
//
// public GHRepo setDescription(String description) {
// this.description = description;
// return this;
// }
//
// public String getDefaultBranch() {
// return defaultBranch;
// }
//
// public GHRepo setDefaultBranch(String defaultBranch) {
// this.defaultBranch = defaultBranch;
// return this;
// }
// }
//
// Path: jandy-server/src/main/java/io/jandy/util/api/json/GHUser.java
// @Data
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class GHUser implements Serializable {
// @JsonProperty("id")
// private long id;
//
// @JsonProperty("login")
// private String login;
//
// @JsonProperty("avatar_url")
// private String avatarUrl;
//
// @JsonProperty("public_repos")
// private Integer publicRepos;
//
// private String email;
// }
// Path: jandy-server/src/main/java/io/jandy/util/api/GitHubApi.java
import io.jandy.domain.cache.HttpCacheEntry;
import io.jandy.util.api.json.GHOrg;
import io.jandy.util.api.json.GHRepo;
import io.jandy.util.api.json.GHUser;
import io.jandy.util.CachedRestTemplate;
import org.apache.commons.lang3.StringUtils;
import org.javatuples.KeyValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cache.CacheManager;
import org.springframework.security.oauth2.client.OAuth2ClientContext;
import org.springframework.stereotype.Component;
import org.springframework.web.client.*;
import java.net.URI;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
.build(CachedRestTemplate.class);
this.restTemplate.setAccept("application/vnd.github.v3+json");
}
public boolean isAnonymous() {
return clientContext.getAccessToken() == null;
}
public GHUser getUser() {
return getForObject("https://api.github.com/user", GHUser.class);
}
public GHUser getUser(String login) {
try {
return getForObject("https://api.github.com/users/{login}", GHUser.class, login);
} catch (HttpClientErrorException e) {
logger.error(e.getMessage(), e);
return null;
}
}
public List<GHOrg> getUserOrgs(String login) {
return Arrays.asList(getForObject("https://api.github.com/users/{login}/orgs", GHOrg[].class, login));
}
public GHOrg getOrg(String org) {
return getForObject("https://api.github.com/orgs/{org}", GHOrg.class, org);
}
| public List<GHRepo> getUserRepos(String login) { |
jandy-team/jandy | jandy-server/src/main/java/io/jandy/util/api/GitHubApi.java | // Path: jandy-server/src/main/java/io/jandy/domain/cache/HttpCacheEntry.java
// public class HttpCacheEntry<T> implements Serializable {
// private String etag;
// private T body;
// private List<String> link;
//
// public String getEtag() {
// return etag;
// }
//
// public HttpCacheEntry setEtag(String etag) {
// this.etag = etag;
// return this;
// }
//
// public T getBody() {
// return body;
// }
//
// public HttpCacheEntry setBody(T body) {
// this.body = body;
// return this;
// }
//
//
// public void setLink(List<String> link) {
// this.link = link;
// }
//
// public List<String> getLink() {
// return link;
// }
// }
//
// Path: jandy-server/src/main/java/io/jandy/util/api/json/GHOrg.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// @Data
// public class GHOrg implements Serializable {
// @JsonProperty("login")
// private String login;
//
// @JsonProperty("id")
// private Long id;
//
// @JsonProperty("public_repos")
// private Integer publicRepos;
// }
//
// Path: jandy-server/src/main/java/io/jandy/util/api/json/GHRepo.java
// @Data
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class GHRepo implements Serializable {
// @JsonProperty("id")
// private Long id;
//
// @JsonProperty("owner")
// private GHUser owner;
//
// @JsonProperty("name")
// private String name;
//
// @JsonProperty("full_name")
// private String fullName;
//
// @JsonProperty("description")
// private String description;
//
// @JsonProperty("default_branch")
// private String defaultBranch;
//
// public Long getId() {
// return id;
// }
//
// public GHRepo setId(Long id) {
// this.id = id;
// return this;
// }
//
// public GHUser getOwner() {
// return owner;
// }
//
// public GHRepo setOwner(GHUser owner) {
// this.owner = owner;
// return this;
// }
//
// public String getName() {
// return name;
// }
//
// public GHRepo setName(String name) {
// this.name = name;
// return this;
// }
//
// public String getFullName() {
// return fullName;
// }
//
// public GHRepo setFullName(String fullName) {
// this.fullName = fullName;
// return this;
// }
//
// public String getDescription() {
// return description;
// }
//
// public GHRepo setDescription(String description) {
// this.description = description;
// return this;
// }
//
// public String getDefaultBranch() {
// return defaultBranch;
// }
//
// public GHRepo setDefaultBranch(String defaultBranch) {
// this.defaultBranch = defaultBranch;
// return this;
// }
// }
//
// Path: jandy-server/src/main/java/io/jandy/util/api/json/GHUser.java
// @Data
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class GHUser implements Serializable {
// @JsonProperty("id")
// private long id;
//
// @JsonProperty("login")
// private String login;
//
// @JsonProperty("avatar_url")
// private String avatarUrl;
//
// @JsonProperty("public_repos")
// private Integer publicRepos;
//
// private String email;
// }
| import io.jandy.domain.cache.HttpCacheEntry;
import io.jandy.util.api.json.GHOrg;
import io.jandy.util.api.json.GHRepo;
import io.jandy.util.api.json.GHUser;
import io.jandy.util.CachedRestTemplate;
import org.apache.commons.lang3.StringUtils;
import org.javatuples.KeyValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cache.CacheManager;
import org.springframework.security.oauth2.client.OAuth2ClientContext;
import org.springframework.stereotype.Component;
import org.springframework.web.client.*;
import java.net.URI;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern; | return Arrays.asList(restTemplate.getForObject("https://api.github.com/orgs/{login}/repos", GHRepo[].class, login));
}
public GHRepo getRepo(String owner, String repo) {
return restTemplate.getForObject("https://api.github.com/repos/{owner}/{repo}", GHRepo.class, owner, repo);
}
private URI uri(String url, Object... uriParams) {
final String accessToken = clientContext.getAccessToken() != null ? clientContext.getAccessToken().getValue() : null;
if (accessToken != null) {
url = url + (url.indexOf('?') > 0 ? "&" : "?") + "access_token=" + accessToken;
}
return restTemplate.getUriTemplateHandler().expand(url, uriParams);
}
private <T> T getForObject(String url, Class<T> cls, Object ...uriParams) {
return restTemplate.getForObject(
cacheManager.getCache(namespace()),
uri(url, uriParams),
cls
);
}
private String namespace() {
return this.getClass().getName();
}
private <R> List<R> getForAll(String url, Class<R[]> cls, Object ...uriParams) { | // Path: jandy-server/src/main/java/io/jandy/domain/cache/HttpCacheEntry.java
// public class HttpCacheEntry<T> implements Serializable {
// private String etag;
// private T body;
// private List<String> link;
//
// public String getEtag() {
// return etag;
// }
//
// public HttpCacheEntry setEtag(String etag) {
// this.etag = etag;
// return this;
// }
//
// public T getBody() {
// return body;
// }
//
// public HttpCacheEntry setBody(T body) {
// this.body = body;
// return this;
// }
//
//
// public void setLink(List<String> link) {
// this.link = link;
// }
//
// public List<String> getLink() {
// return link;
// }
// }
//
// Path: jandy-server/src/main/java/io/jandy/util/api/json/GHOrg.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// @Data
// public class GHOrg implements Serializable {
// @JsonProperty("login")
// private String login;
//
// @JsonProperty("id")
// private Long id;
//
// @JsonProperty("public_repos")
// private Integer publicRepos;
// }
//
// Path: jandy-server/src/main/java/io/jandy/util/api/json/GHRepo.java
// @Data
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class GHRepo implements Serializable {
// @JsonProperty("id")
// private Long id;
//
// @JsonProperty("owner")
// private GHUser owner;
//
// @JsonProperty("name")
// private String name;
//
// @JsonProperty("full_name")
// private String fullName;
//
// @JsonProperty("description")
// private String description;
//
// @JsonProperty("default_branch")
// private String defaultBranch;
//
// public Long getId() {
// return id;
// }
//
// public GHRepo setId(Long id) {
// this.id = id;
// return this;
// }
//
// public GHUser getOwner() {
// return owner;
// }
//
// public GHRepo setOwner(GHUser owner) {
// this.owner = owner;
// return this;
// }
//
// public String getName() {
// return name;
// }
//
// public GHRepo setName(String name) {
// this.name = name;
// return this;
// }
//
// public String getFullName() {
// return fullName;
// }
//
// public GHRepo setFullName(String fullName) {
// this.fullName = fullName;
// return this;
// }
//
// public String getDescription() {
// return description;
// }
//
// public GHRepo setDescription(String description) {
// this.description = description;
// return this;
// }
//
// public String getDefaultBranch() {
// return defaultBranch;
// }
//
// public GHRepo setDefaultBranch(String defaultBranch) {
// this.defaultBranch = defaultBranch;
// return this;
// }
// }
//
// Path: jandy-server/src/main/java/io/jandy/util/api/json/GHUser.java
// @Data
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class GHUser implements Serializable {
// @JsonProperty("id")
// private long id;
//
// @JsonProperty("login")
// private String login;
//
// @JsonProperty("avatar_url")
// private String avatarUrl;
//
// @JsonProperty("public_repos")
// private Integer publicRepos;
//
// private String email;
// }
// Path: jandy-server/src/main/java/io/jandy/util/api/GitHubApi.java
import io.jandy.domain.cache.HttpCacheEntry;
import io.jandy.util.api.json.GHOrg;
import io.jandy.util.api.json.GHRepo;
import io.jandy.util.api.json.GHUser;
import io.jandy.util.CachedRestTemplate;
import org.apache.commons.lang3.StringUtils;
import org.javatuples.KeyValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cache.CacheManager;
import org.springframework.security.oauth2.client.OAuth2ClientContext;
import org.springframework.stereotype.Component;
import org.springframework.web.client.*;
import java.net.URI;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
return Arrays.asList(restTemplate.getForObject("https://api.github.com/orgs/{login}/repos", GHRepo[].class, login));
}
public GHRepo getRepo(String owner, String repo) {
return restTemplate.getForObject("https://api.github.com/repos/{owner}/{repo}", GHRepo.class, owner, repo);
}
private URI uri(String url, Object... uriParams) {
final String accessToken = clientContext.getAccessToken() != null ? clientContext.getAccessToken().getValue() : null;
if (accessToken != null) {
url = url + (url.indexOf('?') > 0 ? "&" : "?") + "access_token=" + accessToken;
}
return restTemplate.getUriTemplateHandler().expand(url, uriParams);
}
private <T> T getForObject(String url, Class<T> cls, Object ...uriParams) {
return restTemplate.getForObject(
cacheManager.getCache(namespace()),
uri(url, uriParams),
cls
);
}
private String namespace() {
return this.getClass().getName();
}
private <R> List<R> getForAll(String url, Class<R[]> cls, Object ...uriParams) { | HttpCacheEntry<R[]> entry = restTemplate.getForCacheEntry( |
scalyr/Scalyr-Java-Client | src/test/com/scalyr/api/tests/JsonParserForTests.java | // Path: src/main/com/scalyr/api/json/JSONArray.java
// public class JSONArray extends ArrayList<Object> implements JSONStreamAware {
// public JSONArray(Object ... values) {
// for (Object value : values)
// add(value);
// }
//
// @Override public void writeJSONBytes(OutputStream out) throws IOException {
// out.write('[');
//
// boolean first = true;
//
// for (Object value : this) {
// if (first)
// first = false;
// else
// out.write(',');
//
// if (value == null) {
// out.write("null".getBytes(ScalyrUtil.utf8));
// continue;
// }
//
// if (value instanceof JSONStreamAware) {
// ((JSONStreamAware)value).writeJSONBytes(out);
// } else {
// JSONValue.writeJSONBytes(value, out);
// }
// }
//
// out.write(']');
// }
//
// @Override public String toString() {
// return JSONValue.toJSONString(this);
// }
//
// }
//
// Path: src/main/com/scalyr/api/json/JSONObject.java
// public class JSONObject extends HashMap<String, Object> implements JSONStreamAware {
// public JSONObject() {
// super();
// }
//
// /**
// * Set the specified key to the specified value, and return this object. Useful for builder-style coding, i.e.
// *
// * JSONObject object = new JSONObject().set("foo", 1).set("bar", 2);
// */
// public JSONObject set(String key, Object value) {
// super.put(key, value);
// return this;
// }
//
// @Override public void writeJSONBytes(OutputStream out) throws IOException {
// out.write('{');
//
// boolean first = true;
//
// for (Map.Entry<String, Object> entry : entrySet()) {
// if (first)
// first = false;
// else
// out.write(',');
//
// out.write('\"');
// JSONValue.escape(String.valueOf(entry.getKey()), out);
// out.write('\"');
// out.write(':');
//
// if (entry.getValue() instanceof JSONStreamAware) {
// ((JSONStreamAware)entry.getValue()).writeJSONBytes(out);
// } else {
// JSONValue.writeJSONBytes(entry.getValue(), out);
// }
// }
//
// out.write('}');
// }
//
// @Override public String toString() {
// return JSONValue.toJSONString(this);
// }
// }
//
// Path: src/test/com/scalyr/api/tests/JsonTokenizerForTests.java
// public static class Token {
// /**
// * Character position in the input text where this token begins.
// */
// public final int pos;
//
// /**
// * Number of input text characters corresponding to this token.
// */
// public final int len;
//
// public final TokenType type;
//
// /**
// * Logical "value" of this token. Interpretation is type-specific.
// */
// public final String value;
//
// public Token(String value, int pos, int len, TokenType type) {
// this.value = value;
// this.pos = pos;
// this.len = len;
// this.type = type;
// }
//
// /**
// * Return true if this is an operator token with the given value.
// */
// public boolean isOp(String s) {
// return (type == TokenType.operator && value.equals(s));
// }
//
// /**
// * Return true if this is an identifier token with the given value.
// */
// public boolean isId(String s) {
// return (type == TokenType.identifier && value.equals(s));
// }
//
// @Override public boolean equals(Object obj) {
// if (!(obj instanceof Token))
// return false;
//
// Token t = (Token)obj;
// return t.pos == pos && t.len == len && t.type == type && t.value.equals(value);
// }
//
// @Override public String toString() {
// return "Token <" + type + ", " + pos + ":" + len + ", [" + value + "]>";
// }
// }
//
// Path: src/test/com/scalyr/api/tests/JsonTokenizerForTests.java
// public static enum TokenType {
// operator,
// stringLit,
// numLit,
// identifier
// }
| import java.util.List;
import com.scalyr.api.json.JSONArray;
import com.scalyr.api.json.JSONObject;
import com.scalyr.api.tests.JsonTokenizerForTests.Token;
import com.scalyr.api.tests.JsonTokenizerForTests.TokenType; | /*
* Scalyr client library
* Copyright 2012 Scalyr, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.scalyr.api.tests;
/**
* Quick-and-dirty JSON parser. Only intended for use in tests.
*/
public class JsonParserForTests {
/**
* The text to be parsed.
*/
private final String input;
/**
* A tokenizer for the input string.
*/
private final JsonTokenizerForTests tokenizer;
/**
* Tokenization of the input string.
*/ | // Path: src/main/com/scalyr/api/json/JSONArray.java
// public class JSONArray extends ArrayList<Object> implements JSONStreamAware {
// public JSONArray(Object ... values) {
// for (Object value : values)
// add(value);
// }
//
// @Override public void writeJSONBytes(OutputStream out) throws IOException {
// out.write('[');
//
// boolean first = true;
//
// for (Object value : this) {
// if (first)
// first = false;
// else
// out.write(',');
//
// if (value == null) {
// out.write("null".getBytes(ScalyrUtil.utf8));
// continue;
// }
//
// if (value instanceof JSONStreamAware) {
// ((JSONStreamAware)value).writeJSONBytes(out);
// } else {
// JSONValue.writeJSONBytes(value, out);
// }
// }
//
// out.write(']');
// }
//
// @Override public String toString() {
// return JSONValue.toJSONString(this);
// }
//
// }
//
// Path: src/main/com/scalyr/api/json/JSONObject.java
// public class JSONObject extends HashMap<String, Object> implements JSONStreamAware {
// public JSONObject() {
// super();
// }
//
// /**
// * Set the specified key to the specified value, and return this object. Useful for builder-style coding, i.e.
// *
// * JSONObject object = new JSONObject().set("foo", 1).set("bar", 2);
// */
// public JSONObject set(String key, Object value) {
// super.put(key, value);
// return this;
// }
//
// @Override public void writeJSONBytes(OutputStream out) throws IOException {
// out.write('{');
//
// boolean first = true;
//
// for (Map.Entry<String, Object> entry : entrySet()) {
// if (first)
// first = false;
// else
// out.write(',');
//
// out.write('\"');
// JSONValue.escape(String.valueOf(entry.getKey()), out);
// out.write('\"');
// out.write(':');
//
// if (entry.getValue() instanceof JSONStreamAware) {
// ((JSONStreamAware)entry.getValue()).writeJSONBytes(out);
// } else {
// JSONValue.writeJSONBytes(entry.getValue(), out);
// }
// }
//
// out.write('}');
// }
//
// @Override public String toString() {
// return JSONValue.toJSONString(this);
// }
// }
//
// Path: src/test/com/scalyr/api/tests/JsonTokenizerForTests.java
// public static class Token {
// /**
// * Character position in the input text where this token begins.
// */
// public final int pos;
//
// /**
// * Number of input text characters corresponding to this token.
// */
// public final int len;
//
// public final TokenType type;
//
// /**
// * Logical "value" of this token. Interpretation is type-specific.
// */
// public final String value;
//
// public Token(String value, int pos, int len, TokenType type) {
// this.value = value;
// this.pos = pos;
// this.len = len;
// this.type = type;
// }
//
// /**
// * Return true if this is an operator token with the given value.
// */
// public boolean isOp(String s) {
// return (type == TokenType.operator && value.equals(s));
// }
//
// /**
// * Return true if this is an identifier token with the given value.
// */
// public boolean isId(String s) {
// return (type == TokenType.identifier && value.equals(s));
// }
//
// @Override public boolean equals(Object obj) {
// if (!(obj instanceof Token))
// return false;
//
// Token t = (Token)obj;
// return t.pos == pos && t.len == len && t.type == type && t.value.equals(value);
// }
//
// @Override public String toString() {
// return "Token <" + type + ", " + pos + ":" + len + ", [" + value + "]>";
// }
// }
//
// Path: src/test/com/scalyr/api/tests/JsonTokenizerForTests.java
// public static enum TokenType {
// operator,
// stringLit,
// numLit,
// identifier
// }
// Path: src/test/com/scalyr/api/tests/JsonParserForTests.java
import java.util.List;
import com.scalyr.api.json.JSONArray;
import com.scalyr.api.json.JSONObject;
import com.scalyr.api.tests.JsonTokenizerForTests.Token;
import com.scalyr.api.tests.JsonTokenizerForTests.TokenType;
/*
* Scalyr client library
* Copyright 2012 Scalyr, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.scalyr.api.tests;
/**
* Quick-and-dirty JSON parser. Only intended for use in tests.
*/
public class JsonParserForTests {
/**
* The text to be parsed.
*/
private final String input;
/**
* A tokenizer for the input string.
*/
private final JsonTokenizerForTests tokenizer;
/**
* Tokenization of the input string.
*/ | protected List<Token> tokens; |
scalyr/Scalyr-Java-Client | src/test/com/scalyr/api/tests/JsonParserForTests.java | // Path: src/main/com/scalyr/api/json/JSONArray.java
// public class JSONArray extends ArrayList<Object> implements JSONStreamAware {
// public JSONArray(Object ... values) {
// for (Object value : values)
// add(value);
// }
//
// @Override public void writeJSONBytes(OutputStream out) throws IOException {
// out.write('[');
//
// boolean first = true;
//
// for (Object value : this) {
// if (first)
// first = false;
// else
// out.write(',');
//
// if (value == null) {
// out.write("null".getBytes(ScalyrUtil.utf8));
// continue;
// }
//
// if (value instanceof JSONStreamAware) {
// ((JSONStreamAware)value).writeJSONBytes(out);
// } else {
// JSONValue.writeJSONBytes(value, out);
// }
// }
//
// out.write(']');
// }
//
// @Override public String toString() {
// return JSONValue.toJSONString(this);
// }
//
// }
//
// Path: src/main/com/scalyr/api/json/JSONObject.java
// public class JSONObject extends HashMap<String, Object> implements JSONStreamAware {
// public JSONObject() {
// super();
// }
//
// /**
// * Set the specified key to the specified value, and return this object. Useful for builder-style coding, i.e.
// *
// * JSONObject object = new JSONObject().set("foo", 1).set("bar", 2);
// */
// public JSONObject set(String key, Object value) {
// super.put(key, value);
// return this;
// }
//
// @Override public void writeJSONBytes(OutputStream out) throws IOException {
// out.write('{');
//
// boolean first = true;
//
// for (Map.Entry<String, Object> entry : entrySet()) {
// if (first)
// first = false;
// else
// out.write(',');
//
// out.write('\"');
// JSONValue.escape(String.valueOf(entry.getKey()), out);
// out.write('\"');
// out.write(':');
//
// if (entry.getValue() instanceof JSONStreamAware) {
// ((JSONStreamAware)entry.getValue()).writeJSONBytes(out);
// } else {
// JSONValue.writeJSONBytes(entry.getValue(), out);
// }
// }
//
// out.write('}');
// }
//
// @Override public String toString() {
// return JSONValue.toJSONString(this);
// }
// }
//
// Path: src/test/com/scalyr/api/tests/JsonTokenizerForTests.java
// public static class Token {
// /**
// * Character position in the input text where this token begins.
// */
// public final int pos;
//
// /**
// * Number of input text characters corresponding to this token.
// */
// public final int len;
//
// public final TokenType type;
//
// /**
// * Logical "value" of this token. Interpretation is type-specific.
// */
// public final String value;
//
// public Token(String value, int pos, int len, TokenType type) {
// this.value = value;
// this.pos = pos;
// this.len = len;
// this.type = type;
// }
//
// /**
// * Return true if this is an operator token with the given value.
// */
// public boolean isOp(String s) {
// return (type == TokenType.operator && value.equals(s));
// }
//
// /**
// * Return true if this is an identifier token with the given value.
// */
// public boolean isId(String s) {
// return (type == TokenType.identifier && value.equals(s));
// }
//
// @Override public boolean equals(Object obj) {
// if (!(obj instanceof Token))
// return false;
//
// Token t = (Token)obj;
// return t.pos == pos && t.len == len && t.type == type && t.value.equals(value);
// }
//
// @Override public String toString() {
// return "Token <" + type + ", " + pos + ":" + len + ", [" + value + "]>";
// }
// }
//
// Path: src/test/com/scalyr/api/tests/JsonTokenizerForTests.java
// public static enum TokenType {
// operator,
// stringLit,
// numLit,
// identifier
// }
| import java.util.List;
import com.scalyr.api.json.JSONArray;
import com.scalyr.api.json.JSONObject;
import com.scalyr.api.tests.JsonTokenizerForTests.Token;
import com.scalyr.api.tests.JsonTokenizerForTests.TokenType; | /*
* Scalyr client library
* Copyright 2012 Scalyr, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.scalyr.api.tests;
/**
* Quick-and-dirty JSON parser. Only intended for use in tests.
*/
public class JsonParserForTests {
/**
* The text to be parsed.
*/
private final String input;
/**
* A tokenizer for the input string.
*/
private final JsonTokenizerForTests tokenizer;
/**
* Tokenization of the input string.
*/
protected List<Token> tokens;
/**
* Index, in the tokens list, of the next unconsumed token.
*/
protected int pos;
public JsonParserForTests(String input) {
this.input = input;
tokenizer = new JsonTokenizerForTests(input);
tokenizer.tokenize();
tokens = tokenizer.tokens;
}
/**
* Parse a JSON value.
*/
public Object parse() {
Token token = match("value expected");
if (token.isId("true"))
return true;
else if (token.isId("false"))
return false;
else if (token.isId("null"))
return null;
else if (token.isOp("{"))
return parseObjectCompletion();
else if (token.isOp("["))
return parseArrayCompletion(); | // Path: src/main/com/scalyr/api/json/JSONArray.java
// public class JSONArray extends ArrayList<Object> implements JSONStreamAware {
// public JSONArray(Object ... values) {
// for (Object value : values)
// add(value);
// }
//
// @Override public void writeJSONBytes(OutputStream out) throws IOException {
// out.write('[');
//
// boolean first = true;
//
// for (Object value : this) {
// if (first)
// first = false;
// else
// out.write(',');
//
// if (value == null) {
// out.write("null".getBytes(ScalyrUtil.utf8));
// continue;
// }
//
// if (value instanceof JSONStreamAware) {
// ((JSONStreamAware)value).writeJSONBytes(out);
// } else {
// JSONValue.writeJSONBytes(value, out);
// }
// }
//
// out.write(']');
// }
//
// @Override public String toString() {
// return JSONValue.toJSONString(this);
// }
//
// }
//
// Path: src/main/com/scalyr/api/json/JSONObject.java
// public class JSONObject extends HashMap<String, Object> implements JSONStreamAware {
// public JSONObject() {
// super();
// }
//
// /**
// * Set the specified key to the specified value, and return this object. Useful for builder-style coding, i.e.
// *
// * JSONObject object = new JSONObject().set("foo", 1).set("bar", 2);
// */
// public JSONObject set(String key, Object value) {
// super.put(key, value);
// return this;
// }
//
// @Override public void writeJSONBytes(OutputStream out) throws IOException {
// out.write('{');
//
// boolean first = true;
//
// for (Map.Entry<String, Object> entry : entrySet()) {
// if (first)
// first = false;
// else
// out.write(',');
//
// out.write('\"');
// JSONValue.escape(String.valueOf(entry.getKey()), out);
// out.write('\"');
// out.write(':');
//
// if (entry.getValue() instanceof JSONStreamAware) {
// ((JSONStreamAware)entry.getValue()).writeJSONBytes(out);
// } else {
// JSONValue.writeJSONBytes(entry.getValue(), out);
// }
// }
//
// out.write('}');
// }
//
// @Override public String toString() {
// return JSONValue.toJSONString(this);
// }
// }
//
// Path: src/test/com/scalyr/api/tests/JsonTokenizerForTests.java
// public static class Token {
// /**
// * Character position in the input text where this token begins.
// */
// public final int pos;
//
// /**
// * Number of input text characters corresponding to this token.
// */
// public final int len;
//
// public final TokenType type;
//
// /**
// * Logical "value" of this token. Interpretation is type-specific.
// */
// public final String value;
//
// public Token(String value, int pos, int len, TokenType type) {
// this.value = value;
// this.pos = pos;
// this.len = len;
// this.type = type;
// }
//
// /**
// * Return true if this is an operator token with the given value.
// */
// public boolean isOp(String s) {
// return (type == TokenType.operator && value.equals(s));
// }
//
// /**
// * Return true if this is an identifier token with the given value.
// */
// public boolean isId(String s) {
// return (type == TokenType.identifier && value.equals(s));
// }
//
// @Override public boolean equals(Object obj) {
// if (!(obj instanceof Token))
// return false;
//
// Token t = (Token)obj;
// return t.pos == pos && t.len == len && t.type == type && t.value.equals(value);
// }
//
// @Override public String toString() {
// return "Token <" + type + ", " + pos + ":" + len + ", [" + value + "]>";
// }
// }
//
// Path: src/test/com/scalyr/api/tests/JsonTokenizerForTests.java
// public static enum TokenType {
// operator,
// stringLit,
// numLit,
// identifier
// }
// Path: src/test/com/scalyr/api/tests/JsonParserForTests.java
import java.util.List;
import com.scalyr.api.json.JSONArray;
import com.scalyr.api.json.JSONObject;
import com.scalyr.api.tests.JsonTokenizerForTests.Token;
import com.scalyr.api.tests.JsonTokenizerForTests.TokenType;
/*
* Scalyr client library
* Copyright 2012 Scalyr, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.scalyr.api.tests;
/**
* Quick-and-dirty JSON parser. Only intended for use in tests.
*/
public class JsonParserForTests {
/**
* The text to be parsed.
*/
private final String input;
/**
* A tokenizer for the input string.
*/
private final JsonTokenizerForTests tokenizer;
/**
* Tokenization of the input string.
*/
protected List<Token> tokens;
/**
* Index, in the tokens list, of the next unconsumed token.
*/
protected int pos;
public JsonParserForTests(String input) {
this.input = input;
tokenizer = new JsonTokenizerForTests(input);
tokenizer.tokenize();
tokens = tokenizer.tokens;
}
/**
* Parse a JSON value.
*/
public Object parse() {
Token token = match("value expected");
if (token.isId("true"))
return true;
else if (token.isId("false"))
return false;
else if (token.isId("null"))
return null;
else if (token.isOp("{"))
return parseObjectCompletion();
else if (token.isOp("["))
return parseArrayCompletion(); | else if (token.type == TokenType.stringLit) |
scalyr/Scalyr-Java-Client | src/test/com/scalyr/api/tests/JsonParserForTests.java | // Path: src/main/com/scalyr/api/json/JSONArray.java
// public class JSONArray extends ArrayList<Object> implements JSONStreamAware {
// public JSONArray(Object ... values) {
// for (Object value : values)
// add(value);
// }
//
// @Override public void writeJSONBytes(OutputStream out) throws IOException {
// out.write('[');
//
// boolean first = true;
//
// for (Object value : this) {
// if (first)
// first = false;
// else
// out.write(',');
//
// if (value == null) {
// out.write("null".getBytes(ScalyrUtil.utf8));
// continue;
// }
//
// if (value instanceof JSONStreamAware) {
// ((JSONStreamAware)value).writeJSONBytes(out);
// } else {
// JSONValue.writeJSONBytes(value, out);
// }
// }
//
// out.write(']');
// }
//
// @Override public String toString() {
// return JSONValue.toJSONString(this);
// }
//
// }
//
// Path: src/main/com/scalyr/api/json/JSONObject.java
// public class JSONObject extends HashMap<String, Object> implements JSONStreamAware {
// public JSONObject() {
// super();
// }
//
// /**
// * Set the specified key to the specified value, and return this object. Useful for builder-style coding, i.e.
// *
// * JSONObject object = new JSONObject().set("foo", 1).set("bar", 2);
// */
// public JSONObject set(String key, Object value) {
// super.put(key, value);
// return this;
// }
//
// @Override public void writeJSONBytes(OutputStream out) throws IOException {
// out.write('{');
//
// boolean first = true;
//
// for (Map.Entry<String, Object> entry : entrySet()) {
// if (first)
// first = false;
// else
// out.write(',');
//
// out.write('\"');
// JSONValue.escape(String.valueOf(entry.getKey()), out);
// out.write('\"');
// out.write(':');
//
// if (entry.getValue() instanceof JSONStreamAware) {
// ((JSONStreamAware)entry.getValue()).writeJSONBytes(out);
// } else {
// JSONValue.writeJSONBytes(entry.getValue(), out);
// }
// }
//
// out.write('}');
// }
//
// @Override public String toString() {
// return JSONValue.toJSONString(this);
// }
// }
//
// Path: src/test/com/scalyr/api/tests/JsonTokenizerForTests.java
// public static class Token {
// /**
// * Character position in the input text where this token begins.
// */
// public final int pos;
//
// /**
// * Number of input text characters corresponding to this token.
// */
// public final int len;
//
// public final TokenType type;
//
// /**
// * Logical "value" of this token. Interpretation is type-specific.
// */
// public final String value;
//
// public Token(String value, int pos, int len, TokenType type) {
// this.value = value;
// this.pos = pos;
// this.len = len;
// this.type = type;
// }
//
// /**
// * Return true if this is an operator token with the given value.
// */
// public boolean isOp(String s) {
// return (type == TokenType.operator && value.equals(s));
// }
//
// /**
// * Return true if this is an identifier token with the given value.
// */
// public boolean isId(String s) {
// return (type == TokenType.identifier && value.equals(s));
// }
//
// @Override public boolean equals(Object obj) {
// if (!(obj instanceof Token))
// return false;
//
// Token t = (Token)obj;
// return t.pos == pos && t.len == len && t.type == type && t.value.equals(value);
// }
//
// @Override public String toString() {
// return "Token <" + type + ", " + pos + ":" + len + ", [" + value + "]>";
// }
// }
//
// Path: src/test/com/scalyr/api/tests/JsonTokenizerForTests.java
// public static enum TokenType {
// operator,
// stringLit,
// numLit,
// identifier
// }
| import java.util.List;
import com.scalyr.api.json.JSONArray;
import com.scalyr.api.json.JSONObject;
import com.scalyr.api.tests.JsonTokenizerForTests.Token;
import com.scalyr.api.tests.JsonTokenizerForTests.TokenType; | tokenizer.tokenize();
tokens = tokenizer.tokens;
}
/**
* Parse a JSON value.
*/
public Object parse() {
Token token = match("value expected");
if (token.isId("true"))
return true;
else if (token.isId("false"))
return false;
else if (token.isId("null"))
return null;
else if (token.isOp("{"))
return parseObjectCompletion();
else if (token.isOp("["))
return parseArrayCompletion();
else if (token.type == TokenType.stringLit)
return token.value;
else if (token.type == TokenType.numLit)
return Double.parseDouble(token.value);
else
return error("unparseable JSON value", token);
}
/**
* Parse a JSON object literal. We assume that the initial '{' has already been consumed.
*/ | // Path: src/main/com/scalyr/api/json/JSONArray.java
// public class JSONArray extends ArrayList<Object> implements JSONStreamAware {
// public JSONArray(Object ... values) {
// for (Object value : values)
// add(value);
// }
//
// @Override public void writeJSONBytes(OutputStream out) throws IOException {
// out.write('[');
//
// boolean first = true;
//
// for (Object value : this) {
// if (first)
// first = false;
// else
// out.write(',');
//
// if (value == null) {
// out.write("null".getBytes(ScalyrUtil.utf8));
// continue;
// }
//
// if (value instanceof JSONStreamAware) {
// ((JSONStreamAware)value).writeJSONBytes(out);
// } else {
// JSONValue.writeJSONBytes(value, out);
// }
// }
//
// out.write(']');
// }
//
// @Override public String toString() {
// return JSONValue.toJSONString(this);
// }
//
// }
//
// Path: src/main/com/scalyr/api/json/JSONObject.java
// public class JSONObject extends HashMap<String, Object> implements JSONStreamAware {
// public JSONObject() {
// super();
// }
//
// /**
// * Set the specified key to the specified value, and return this object. Useful for builder-style coding, i.e.
// *
// * JSONObject object = new JSONObject().set("foo", 1).set("bar", 2);
// */
// public JSONObject set(String key, Object value) {
// super.put(key, value);
// return this;
// }
//
// @Override public void writeJSONBytes(OutputStream out) throws IOException {
// out.write('{');
//
// boolean first = true;
//
// for (Map.Entry<String, Object> entry : entrySet()) {
// if (first)
// first = false;
// else
// out.write(',');
//
// out.write('\"');
// JSONValue.escape(String.valueOf(entry.getKey()), out);
// out.write('\"');
// out.write(':');
//
// if (entry.getValue() instanceof JSONStreamAware) {
// ((JSONStreamAware)entry.getValue()).writeJSONBytes(out);
// } else {
// JSONValue.writeJSONBytes(entry.getValue(), out);
// }
// }
//
// out.write('}');
// }
//
// @Override public String toString() {
// return JSONValue.toJSONString(this);
// }
// }
//
// Path: src/test/com/scalyr/api/tests/JsonTokenizerForTests.java
// public static class Token {
// /**
// * Character position in the input text where this token begins.
// */
// public final int pos;
//
// /**
// * Number of input text characters corresponding to this token.
// */
// public final int len;
//
// public final TokenType type;
//
// /**
// * Logical "value" of this token. Interpretation is type-specific.
// */
// public final String value;
//
// public Token(String value, int pos, int len, TokenType type) {
// this.value = value;
// this.pos = pos;
// this.len = len;
// this.type = type;
// }
//
// /**
// * Return true if this is an operator token with the given value.
// */
// public boolean isOp(String s) {
// return (type == TokenType.operator && value.equals(s));
// }
//
// /**
// * Return true if this is an identifier token with the given value.
// */
// public boolean isId(String s) {
// return (type == TokenType.identifier && value.equals(s));
// }
//
// @Override public boolean equals(Object obj) {
// if (!(obj instanceof Token))
// return false;
//
// Token t = (Token)obj;
// return t.pos == pos && t.len == len && t.type == type && t.value.equals(value);
// }
//
// @Override public String toString() {
// return "Token <" + type + ", " + pos + ":" + len + ", [" + value + "]>";
// }
// }
//
// Path: src/test/com/scalyr/api/tests/JsonTokenizerForTests.java
// public static enum TokenType {
// operator,
// stringLit,
// numLit,
// identifier
// }
// Path: src/test/com/scalyr/api/tests/JsonParserForTests.java
import java.util.List;
import com.scalyr.api.json.JSONArray;
import com.scalyr.api.json.JSONObject;
import com.scalyr.api.tests.JsonTokenizerForTests.Token;
import com.scalyr.api.tests.JsonTokenizerForTests.TokenType;
tokenizer.tokenize();
tokens = tokenizer.tokens;
}
/**
* Parse a JSON value.
*/
public Object parse() {
Token token = match("value expected");
if (token.isId("true"))
return true;
else if (token.isId("false"))
return false;
else if (token.isId("null"))
return null;
else if (token.isOp("{"))
return parseObjectCompletion();
else if (token.isOp("["))
return parseArrayCompletion();
else if (token.type == TokenType.stringLit)
return token.value;
else if (token.type == TokenType.numLit)
return Double.parseDouble(token.value);
else
return error("unparseable JSON value", token);
}
/**
* Parse a JSON object literal. We assume that the initial '{' has already been consumed.
*/ | private JSONObject parseObjectCompletion() { |
scalyr/Scalyr-Java-Client | src/test/com/scalyr/api/tests/JsonParserForTests.java | // Path: src/main/com/scalyr/api/json/JSONArray.java
// public class JSONArray extends ArrayList<Object> implements JSONStreamAware {
// public JSONArray(Object ... values) {
// for (Object value : values)
// add(value);
// }
//
// @Override public void writeJSONBytes(OutputStream out) throws IOException {
// out.write('[');
//
// boolean first = true;
//
// for (Object value : this) {
// if (first)
// first = false;
// else
// out.write(',');
//
// if (value == null) {
// out.write("null".getBytes(ScalyrUtil.utf8));
// continue;
// }
//
// if (value instanceof JSONStreamAware) {
// ((JSONStreamAware)value).writeJSONBytes(out);
// } else {
// JSONValue.writeJSONBytes(value, out);
// }
// }
//
// out.write(']');
// }
//
// @Override public String toString() {
// return JSONValue.toJSONString(this);
// }
//
// }
//
// Path: src/main/com/scalyr/api/json/JSONObject.java
// public class JSONObject extends HashMap<String, Object> implements JSONStreamAware {
// public JSONObject() {
// super();
// }
//
// /**
// * Set the specified key to the specified value, and return this object. Useful for builder-style coding, i.e.
// *
// * JSONObject object = new JSONObject().set("foo", 1).set("bar", 2);
// */
// public JSONObject set(String key, Object value) {
// super.put(key, value);
// return this;
// }
//
// @Override public void writeJSONBytes(OutputStream out) throws IOException {
// out.write('{');
//
// boolean first = true;
//
// for (Map.Entry<String, Object> entry : entrySet()) {
// if (first)
// first = false;
// else
// out.write(',');
//
// out.write('\"');
// JSONValue.escape(String.valueOf(entry.getKey()), out);
// out.write('\"');
// out.write(':');
//
// if (entry.getValue() instanceof JSONStreamAware) {
// ((JSONStreamAware)entry.getValue()).writeJSONBytes(out);
// } else {
// JSONValue.writeJSONBytes(entry.getValue(), out);
// }
// }
//
// out.write('}');
// }
//
// @Override public String toString() {
// return JSONValue.toJSONString(this);
// }
// }
//
// Path: src/test/com/scalyr/api/tests/JsonTokenizerForTests.java
// public static class Token {
// /**
// * Character position in the input text where this token begins.
// */
// public final int pos;
//
// /**
// * Number of input text characters corresponding to this token.
// */
// public final int len;
//
// public final TokenType type;
//
// /**
// * Logical "value" of this token. Interpretation is type-specific.
// */
// public final String value;
//
// public Token(String value, int pos, int len, TokenType type) {
// this.value = value;
// this.pos = pos;
// this.len = len;
// this.type = type;
// }
//
// /**
// * Return true if this is an operator token with the given value.
// */
// public boolean isOp(String s) {
// return (type == TokenType.operator && value.equals(s));
// }
//
// /**
// * Return true if this is an identifier token with the given value.
// */
// public boolean isId(String s) {
// return (type == TokenType.identifier && value.equals(s));
// }
//
// @Override public boolean equals(Object obj) {
// if (!(obj instanceof Token))
// return false;
//
// Token t = (Token)obj;
// return t.pos == pos && t.len == len && t.type == type && t.value.equals(value);
// }
//
// @Override public String toString() {
// return "Token <" + type + ", " + pos + ":" + len + ", [" + value + "]>";
// }
// }
//
// Path: src/test/com/scalyr/api/tests/JsonTokenizerForTests.java
// public static enum TokenType {
// operator,
// stringLit,
// numLit,
// identifier
// }
| import java.util.List;
import com.scalyr.api.json.JSONArray;
import com.scalyr.api.json.JSONObject;
import com.scalyr.api.tests.JsonTokenizerForTests.Token;
import com.scalyr.api.tests.JsonTokenizerForTests.TokenType; | }
/**
* Parse a JSON object literal. We assume that the initial '{' has already been consumed.
*/
private JSONObject parseObjectCompletion() {
JSONObject object = new JSONObject();
if (tryMatchOp("}"))
return object;
while (true) {
Token token = match("field name expected");
if (token.type != TokenType.stringLit)
tokenizer.error("field name expected", prevToken());
String fieldName = token.value;
matchOp(":");
Object fieldValue = parse();
object.put(fieldName, fieldValue);
if (tryMatchOp("}"))
return object;
matchOp(",");
}
}
/**
* Parse a JSON array literal. We assume that the initial '[' has already been consumed.
*/ | // Path: src/main/com/scalyr/api/json/JSONArray.java
// public class JSONArray extends ArrayList<Object> implements JSONStreamAware {
// public JSONArray(Object ... values) {
// for (Object value : values)
// add(value);
// }
//
// @Override public void writeJSONBytes(OutputStream out) throws IOException {
// out.write('[');
//
// boolean first = true;
//
// for (Object value : this) {
// if (first)
// first = false;
// else
// out.write(',');
//
// if (value == null) {
// out.write("null".getBytes(ScalyrUtil.utf8));
// continue;
// }
//
// if (value instanceof JSONStreamAware) {
// ((JSONStreamAware)value).writeJSONBytes(out);
// } else {
// JSONValue.writeJSONBytes(value, out);
// }
// }
//
// out.write(']');
// }
//
// @Override public String toString() {
// return JSONValue.toJSONString(this);
// }
//
// }
//
// Path: src/main/com/scalyr/api/json/JSONObject.java
// public class JSONObject extends HashMap<String, Object> implements JSONStreamAware {
// public JSONObject() {
// super();
// }
//
// /**
// * Set the specified key to the specified value, and return this object. Useful for builder-style coding, i.e.
// *
// * JSONObject object = new JSONObject().set("foo", 1).set("bar", 2);
// */
// public JSONObject set(String key, Object value) {
// super.put(key, value);
// return this;
// }
//
// @Override public void writeJSONBytes(OutputStream out) throws IOException {
// out.write('{');
//
// boolean first = true;
//
// for (Map.Entry<String, Object> entry : entrySet()) {
// if (first)
// first = false;
// else
// out.write(',');
//
// out.write('\"');
// JSONValue.escape(String.valueOf(entry.getKey()), out);
// out.write('\"');
// out.write(':');
//
// if (entry.getValue() instanceof JSONStreamAware) {
// ((JSONStreamAware)entry.getValue()).writeJSONBytes(out);
// } else {
// JSONValue.writeJSONBytes(entry.getValue(), out);
// }
// }
//
// out.write('}');
// }
//
// @Override public String toString() {
// return JSONValue.toJSONString(this);
// }
// }
//
// Path: src/test/com/scalyr/api/tests/JsonTokenizerForTests.java
// public static class Token {
// /**
// * Character position in the input text where this token begins.
// */
// public final int pos;
//
// /**
// * Number of input text characters corresponding to this token.
// */
// public final int len;
//
// public final TokenType type;
//
// /**
// * Logical "value" of this token. Interpretation is type-specific.
// */
// public final String value;
//
// public Token(String value, int pos, int len, TokenType type) {
// this.value = value;
// this.pos = pos;
// this.len = len;
// this.type = type;
// }
//
// /**
// * Return true if this is an operator token with the given value.
// */
// public boolean isOp(String s) {
// return (type == TokenType.operator && value.equals(s));
// }
//
// /**
// * Return true if this is an identifier token with the given value.
// */
// public boolean isId(String s) {
// return (type == TokenType.identifier && value.equals(s));
// }
//
// @Override public boolean equals(Object obj) {
// if (!(obj instanceof Token))
// return false;
//
// Token t = (Token)obj;
// return t.pos == pos && t.len == len && t.type == type && t.value.equals(value);
// }
//
// @Override public String toString() {
// return "Token <" + type + ", " + pos + ":" + len + ", [" + value + "]>";
// }
// }
//
// Path: src/test/com/scalyr/api/tests/JsonTokenizerForTests.java
// public static enum TokenType {
// operator,
// stringLit,
// numLit,
// identifier
// }
// Path: src/test/com/scalyr/api/tests/JsonParserForTests.java
import java.util.List;
import com.scalyr.api.json.JSONArray;
import com.scalyr.api.json.JSONObject;
import com.scalyr.api.tests.JsonTokenizerForTests.Token;
import com.scalyr.api.tests.JsonTokenizerForTests.TokenType;
}
/**
* Parse a JSON object literal. We assume that the initial '{' has already been consumed.
*/
private JSONObject parseObjectCompletion() {
JSONObject object = new JSONObject();
if (tryMatchOp("}"))
return object;
while (true) {
Token token = match("field name expected");
if (token.type != TokenType.stringLit)
tokenizer.error("field name expected", prevToken());
String fieldName = token.value;
matchOp(":");
Object fieldValue = parse();
object.put(fieldName, fieldValue);
if (tryMatchOp("}"))
return object;
matchOp(",");
}
}
/**
* Parse a JSON array literal. We assume that the initial '[' has already been consumed.
*/ | private JSONArray parseArrayCompletion() { |
scalyr/Scalyr-Java-Client | src/main/com/scalyr/api/internal/JavaNetHttpClient.java | // Path: src/main/com/scalyr/api/internal/ScalyrService.java
// public static class RpcOptions {
// /**
// * If not empty/null, then we add a "?" and this string to the URL. Should be of the form "name=value" or "name=value&name=value".
// */
// public String queryParameters;
//
// /**
// * HTTP connextion timeout (see HttpURLConnection.setConnectTimeout).
// */
// public int connectionTimeoutMs = TuningConstants.HTTP_CONNECT_TIMEOUT_MS;
//
// /**
// * HTTP read timeout (see HttpURLConnection.setReadTimeout).
// */
// public int readTimeoutMs = TuningConstants.MAXIMUM_RETRY_PERIOD_MS;
//
// /**
// * Time span during which API operations may be retried (e.g. in response to a network
// * error). Once this many milliseconds have elapsed from the initial API invocation, we
// * no longer issue retries.
// */
// public int maxRetryIntervalMs = TuningConstants.MAXIMUM_RETRY_PERIOD_MS;
// }
| import com.scalyr.api.internal.ScalyrService.RpcOptions;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.zip.GZIPOutputStream;
import java.util.zip.GZIPInputStream; | package com.scalyr.api.internal;
/**
* AbstractHttpClient implementation based on java.net.HttpURLConnection.
* Has Gzip compression capability.
*/
public class JavaNetHttpClient extends AbstractHttpClient {
private HttpURLConnection connection;
private InputStream responseStream;
private boolean enableGzip;
/**
* Version of constructor with desired Content-Encoding passed in.
*/ | // Path: src/main/com/scalyr/api/internal/ScalyrService.java
// public static class RpcOptions {
// /**
// * If not empty/null, then we add a "?" and this string to the URL. Should be of the form "name=value" or "name=value&name=value".
// */
// public String queryParameters;
//
// /**
// * HTTP connextion timeout (see HttpURLConnection.setConnectTimeout).
// */
// public int connectionTimeoutMs = TuningConstants.HTTP_CONNECT_TIMEOUT_MS;
//
// /**
// * HTTP read timeout (see HttpURLConnection.setReadTimeout).
// */
// public int readTimeoutMs = TuningConstants.MAXIMUM_RETRY_PERIOD_MS;
//
// /**
// * Time span during which API operations may be retried (e.g. in response to a network
// * error). Once this many milliseconds have elapsed from the initial API invocation, we
// * no longer issue retries.
// */
// public int maxRetryIntervalMs = TuningConstants.MAXIMUM_RETRY_PERIOD_MS;
// }
// Path: src/main/com/scalyr/api/internal/JavaNetHttpClient.java
import com.scalyr.api.internal.ScalyrService.RpcOptions;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.zip.GZIPOutputStream;
import java.util.zip.GZIPInputStream;
package com.scalyr.api.internal;
/**
* AbstractHttpClient implementation based on java.net.HttpURLConnection.
* Has Gzip compression capability.
*/
public class JavaNetHttpClient extends AbstractHttpClient {
private HttpURLConnection connection;
private InputStream responseStream;
private boolean enableGzip;
/**
* Version of constructor with desired Content-Encoding passed in.
*/ | public JavaNetHttpClient(URL url, int requestLength, boolean closeConnections, RpcOptions options, |
scalyr/Scalyr-Java-Client | src/test/com/scalyr/api/tests/AtomicDoubleTest.java | // Path: src/main/com/scalyr/api/logs/AtomicDouble.java
// public class AtomicDouble {
// private volatile long bits;
//
// private static final AtomicLongFieldUpdater<AtomicDouble> updater =
// AtomicLongFieldUpdater.newUpdater(AtomicDouble.class, "bits");
//
// public AtomicDouble() {
// this(0.0);
// }
//
// public AtomicDouble(double initialValue) {
// bits = Double.doubleToRawLongBits(initialValue);
// }
//
// public double get() {
// return Double.longBitsToDouble(bits);
// }
//
// public void set(double newValue) {
// bits = Double.doubleToRawLongBits(newValue);
// }
//
// public double add(double delta) {
// while (true) {
// long currentBits = bits;
// double currentValue = Double.longBitsToDouble(currentBits);
// double newValue = currentValue + delta;
// if (updater.compareAndSet(this, currentBits, Double.doubleToRawLongBits(newValue))) {
// return newValue;
// }
// }
// }
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import org.junit.Test;
import com.scalyr.api.logs.AtomicDouble; | /*
* Scalyr client library
* Copyright 2012 Scalyr, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.scalyr.api.tests;
/**
* Tests for AtomicDouble.
*/
public class AtomicDoubleTest {
/**
* Simple tests of each method.
*/
@Test public void basicTests() { | // Path: src/main/com/scalyr/api/logs/AtomicDouble.java
// public class AtomicDouble {
// private volatile long bits;
//
// private static final AtomicLongFieldUpdater<AtomicDouble> updater =
// AtomicLongFieldUpdater.newUpdater(AtomicDouble.class, "bits");
//
// public AtomicDouble() {
// this(0.0);
// }
//
// public AtomicDouble(double initialValue) {
// bits = Double.doubleToRawLongBits(initialValue);
// }
//
// public double get() {
// return Double.longBitsToDouble(bits);
// }
//
// public void set(double newValue) {
// bits = Double.doubleToRawLongBits(newValue);
// }
//
// public double add(double delta) {
// while (true) {
// long currentBits = bits;
// double currentValue = Double.longBitsToDouble(currentBits);
// double newValue = currentValue + delta;
// if (updater.compareAndSet(this, currentBits, Double.doubleToRawLongBits(newValue))) {
// return newValue;
// }
// }
// }
// }
// Path: src/test/com/scalyr/api/tests/AtomicDoubleTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import org.junit.Test;
import com.scalyr.api.logs.AtomicDouble;
/*
* Scalyr client library
* Copyright 2012 Scalyr, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.scalyr.api.tests;
/**
* Tests for AtomicDouble.
*/
public class AtomicDoubleTest {
/**
* Simple tests of each method.
*/
@Test public void basicTests() { | AtomicDouble x = new AtomicDouble(); |
olami-developers/olami-java-client-sdk | lib/src/main/java/ai/olami/cloudService/APIResponse.java | // Path: lib/src/main/java/ai/olami/util/GsonFactory.java
// public class GsonFactory {
//
// private static Gson mDefaultGson = new GsonBuilder()
// .excludeFieldsWithoutExposeAnnotation().create();
//
// private static Gson mDebugGson = new GsonBuilder()
// .setPrettyPrinting()
// .create();
//
// private static Gson mDebugGsonWithoutEA = new GsonBuilder()
// .setPrettyPrinting()
// .excludeFieldsWithoutExposeAnnotation()
// .create();
//
// /**
// * Create a new Gson instance with excludeFieldsWithoutExposeAnnotation().
// *
// * @return GsonBuilder.
// */
// public static Gson getNormalGson() {
// return mDefaultGson;
// }
//
// /**
// * Create a new Gson instance with PrettyPrinting.
// *
// * @param exposeAll - TRUE to create without excludeFieldsWithoutExposeAnnotation().
// * @return Gson
// */
// public static Gson getDebugGson(boolean exposeAll) {
//
// if (exposeAll) {
// return mDebugGson;
// }
//
// return mDebugGsonWithoutEA;
// }
//
// }
| import com.google.gson.annotations.SerializedName;
import ai.olami.util.GsonFactory;
import com.google.gson.Gson;
import com.google.gson.annotations.Expose; | /*
Copyright 2017, VIA Technologies, Inc. & OLAMI Team.
http://olami.ai
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package ai.olami.cloudService;
public class APIResponse {
public static final String STATUS_OK = "ok";
public static final String STATUS_ERROR = "error";
public static final int ERROR_CODE_INVALID_CONTENT = -1000000;
@Expose(serialize = false, deserialize = false)
@SerializedName("original_json_string_for_debug")
private String mSourceJsonString = null;
@Expose(serialize = false, deserialize = false) | // Path: lib/src/main/java/ai/olami/util/GsonFactory.java
// public class GsonFactory {
//
// private static Gson mDefaultGson = new GsonBuilder()
// .excludeFieldsWithoutExposeAnnotation().create();
//
// private static Gson mDebugGson = new GsonBuilder()
// .setPrettyPrinting()
// .create();
//
// private static Gson mDebugGsonWithoutEA = new GsonBuilder()
// .setPrettyPrinting()
// .excludeFieldsWithoutExposeAnnotation()
// .create();
//
// /**
// * Create a new Gson instance with excludeFieldsWithoutExposeAnnotation().
// *
// * @return GsonBuilder.
// */
// public static Gson getNormalGson() {
// return mDefaultGson;
// }
//
// /**
// * Create a new Gson instance with PrettyPrinting.
// *
// * @param exposeAll - TRUE to create without excludeFieldsWithoutExposeAnnotation().
// * @return Gson
// */
// public static Gson getDebugGson(boolean exposeAll) {
//
// if (exposeAll) {
// return mDebugGson;
// }
//
// return mDebugGsonWithoutEA;
// }
//
// }
// Path: lib/src/main/java/ai/olami/cloudService/APIResponse.java
import com.google.gson.annotations.SerializedName;
import ai.olami.util.GsonFactory;
import com.google.gson.Gson;
import com.google.gson.annotations.Expose;
/*
Copyright 2017, VIA Technologies, Inc. & OLAMI Team.
http://olami.ai
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package ai.olami.cloudService;
public class APIResponse {
public static final String STATUS_OK = "ok";
public static final String STATUS_ERROR = "error";
public static final int ERROR_CODE_INVALID_CONTENT = -1000000;
@Expose(serialize = false, deserialize = false)
@SerializedName("original_json_string_for_debug")
private String mSourceJsonString = null;
@Expose(serialize = false, deserialize = false) | private Gson mGson = GsonFactory.getNormalGson(); |
olami-developers/olami-java-client-sdk | lib/src/main/java/ai/olami/nli/DescObject.java | // Path: lib/src/main/java/ai/olami/ids/IDSResult.java
// public class IDSResult {
//
// /**
// * IDS Modules
// */
// public static enum Types {
// QUESTION ("question", null),
// CONFIRMATION ("confirmation", null),
// SELECTION ("selection", null),
// DATE ("date", null),
// NONSENSE ("nonsense", null),
// ZIP_CODE ("zipcode", null),
// MATH_24 ("math24", null),
// WEATHER ("weather", (new TypeToken<ArrayList<WeatherData>>() {}).getType()),
// BAIKE ("baike", (new TypeToken<ArrayList<BaikeData>>() {}).getType()),
// NEWS ("news", (new TypeToken<ArrayList<NewsData>>() {}).getType()),
// KKBOX ("kkbox", (new TypeToken<ArrayList<KKBOXData>>() {}).getType()),
// MUSIC_CONTROL ("MusicControl", (new TypeToken<ArrayList<MusicControlData>>() {}).getType()),
// TV_PROGRAM ("tvprogram", (new TypeToken<ArrayList<TVProgramData>>() {}).getType()),
// POEM ("poem", (new TypeToken<ArrayList<PoemData>>() {}).getType()),
// JOKE ("joke", (new TypeToken<ArrayList<JokeData>>() {}).getType()),
// STOCK_MARKET ("stock", (new TypeToken<ArrayList<StockMarketData>>() {}).getType()),
// MATH ("math", (new TypeToken<ArrayList<MathData>>() {}).getType()),
// UNIT_CONVERT ("unitconvert", (new TypeToken<ArrayList<UnitConvertData>>() {}).getType()),
// EXCHANGE_RATE ("exchangerate", (new TypeToken<ArrayList<ExchangeRateData>>() {}).getType()),
// COOKING ("cooking", (new TypeToken<ArrayList<CookingData>>() {}).getType()),
// OPEN_WEB ("openweb", (new TypeToken<ArrayList<OpenWebData>>() {}).getType());
//
// private String name;
// private Type dataObjArrayListType;
//
// private Types(
// String name,
// Type dataObjArrayListType
// ) {
// this.name = name;
// this.dataObjArrayListType = dataObjArrayListType;
// }
//
// /**
// * @return Module name
// */
// public String getName() {
// return this.name;
// }
//
// /**
// * @return Type of the DataObject ArrayList.
// */
// public Type getDataArrayListType() {
// return this.dataObjArrayListType;
// }
//
// /**
// * Check if the given name exists in module type list.
// *
// * @param moduleName - Module name you want to check.
// * @return TRUE if the given name exists in module type list.
// */
// public static boolean contains(String moduleName) {
// Object[] list = Types.class.getEnumConstants();
// for (Object t : list) {
// if (((Types) t).getName().equals(moduleName)) {
// return true;
// }
// }
// return false;
// }
//
// /**
// * Get enum by mdoule name.
// * @param moduleName - Module name you want to find.
// * @return Module enum.
// */
// public static Types getByName(String moduleName) {
// Object[] list = Types.class.getEnumConstants();
// for (Object t : list) {
// if (((Types) t).getName().equals(moduleName)) {
// return ((Types) t);
// }
// }
// return null;
// }
//
// /**
// * Get DataObject array type by the specified module name.
// *
// * @param moduleName - Module name you want to find.
// * @return Type of the DataObject ArrayList.
// */
// public static Type getDataArrayListType(String moduleName) {
// Object[] list = Types.class.getEnumConstants();
// for (Object t : list) {
// if (((Types) t).getName().equals(moduleName)) {
// return ((Types) t).getDataArrayListType();
// }
// }
// return null;
// }
// }
//
// }
| import ai.olami.ids.IDSResult;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName; | /*
Copyright 2017, VIA Technologies, Inc. & OLAMI Team.
http://olami.ai
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package ai.olami.nli;
public class DescObject {
public static final int STATUS_SUCCESS = 0;
public static final int STATUS_SELECTION_OVERFLOW = 1001;
public static final int STATUS_NO_MATCHED_GRAMMAR = 1003;
public static final int STATUS_INPUT_LENGTH_TOO_LONG = 1005;
public static final int STATUS_TIMEOUT = 3001;
public static final int STATUS_SERVER_ERROR= 3003;
public static final int STATUS_EXCEPTION= 3004;
| // Path: lib/src/main/java/ai/olami/ids/IDSResult.java
// public class IDSResult {
//
// /**
// * IDS Modules
// */
// public static enum Types {
// QUESTION ("question", null),
// CONFIRMATION ("confirmation", null),
// SELECTION ("selection", null),
// DATE ("date", null),
// NONSENSE ("nonsense", null),
// ZIP_CODE ("zipcode", null),
// MATH_24 ("math24", null),
// WEATHER ("weather", (new TypeToken<ArrayList<WeatherData>>() {}).getType()),
// BAIKE ("baike", (new TypeToken<ArrayList<BaikeData>>() {}).getType()),
// NEWS ("news", (new TypeToken<ArrayList<NewsData>>() {}).getType()),
// KKBOX ("kkbox", (new TypeToken<ArrayList<KKBOXData>>() {}).getType()),
// MUSIC_CONTROL ("MusicControl", (new TypeToken<ArrayList<MusicControlData>>() {}).getType()),
// TV_PROGRAM ("tvprogram", (new TypeToken<ArrayList<TVProgramData>>() {}).getType()),
// POEM ("poem", (new TypeToken<ArrayList<PoemData>>() {}).getType()),
// JOKE ("joke", (new TypeToken<ArrayList<JokeData>>() {}).getType()),
// STOCK_MARKET ("stock", (new TypeToken<ArrayList<StockMarketData>>() {}).getType()),
// MATH ("math", (new TypeToken<ArrayList<MathData>>() {}).getType()),
// UNIT_CONVERT ("unitconvert", (new TypeToken<ArrayList<UnitConvertData>>() {}).getType()),
// EXCHANGE_RATE ("exchangerate", (new TypeToken<ArrayList<ExchangeRateData>>() {}).getType()),
// COOKING ("cooking", (new TypeToken<ArrayList<CookingData>>() {}).getType()),
// OPEN_WEB ("openweb", (new TypeToken<ArrayList<OpenWebData>>() {}).getType());
//
// private String name;
// private Type dataObjArrayListType;
//
// private Types(
// String name,
// Type dataObjArrayListType
// ) {
// this.name = name;
// this.dataObjArrayListType = dataObjArrayListType;
// }
//
// /**
// * @return Module name
// */
// public String getName() {
// return this.name;
// }
//
// /**
// * @return Type of the DataObject ArrayList.
// */
// public Type getDataArrayListType() {
// return this.dataObjArrayListType;
// }
//
// /**
// * Check if the given name exists in module type list.
// *
// * @param moduleName - Module name you want to check.
// * @return TRUE if the given name exists in module type list.
// */
// public static boolean contains(String moduleName) {
// Object[] list = Types.class.getEnumConstants();
// for (Object t : list) {
// if (((Types) t).getName().equals(moduleName)) {
// return true;
// }
// }
// return false;
// }
//
// /**
// * Get enum by mdoule name.
// * @param moduleName - Module name you want to find.
// * @return Module enum.
// */
// public static Types getByName(String moduleName) {
// Object[] list = Types.class.getEnumConstants();
// for (Object t : list) {
// if (((Types) t).getName().equals(moduleName)) {
// return ((Types) t);
// }
// }
// return null;
// }
//
// /**
// * Get DataObject array type by the specified module name.
// *
// * @param moduleName - Module name you want to find.
// * @return Type of the DataObject ArrayList.
// */
// public static Type getDataArrayListType(String moduleName) {
// Object[] list = Types.class.getEnumConstants();
// for (Object t : list) {
// if (((Types) t).getName().equals(moduleName)) {
// return ((Types) t).getDataArrayListType();
// }
// }
// return null;
// }
// }
//
// }
// Path: lib/src/main/java/ai/olami/nli/DescObject.java
import ai.olami.ids.IDSResult;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/*
Copyright 2017, VIA Technologies, Inc. & OLAMI Team.
http://olami.ai
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package ai.olami.nli;
public class DescObject {
public static final int STATUS_SUCCESS = 0;
public static final int STATUS_SELECTION_OVERFLOW = 1001;
public static final int STATUS_NO_MATCHED_GRAMMAR = 1003;
public static final int STATUS_INPUT_LENGTH_TOO_LONG = 1005;
public static final int STATUS_TIMEOUT = 3001;
public static final int STATUS_SERVER_ERROR= 3003;
public static final int STATUS_EXCEPTION= 3004;
| public static final String TYPE_WEATHER = IDSResult.Types.WEATHER.getName(); |
olami-developers/olami-java-client-sdk | lib/src/main/java/ai/olami/cloudService/APIResponseBuilder.java | // Path: lib/src/main/java/ai/olami/util/GsonFactory.java
// public class GsonFactory {
//
// private static Gson mDefaultGson = new GsonBuilder()
// .excludeFieldsWithoutExposeAnnotation().create();
//
// private static Gson mDebugGson = new GsonBuilder()
// .setPrettyPrinting()
// .create();
//
// private static Gson mDebugGsonWithoutEA = new GsonBuilder()
// .setPrettyPrinting()
// .excludeFieldsWithoutExposeAnnotation()
// .create();
//
// /**
// * Create a new Gson instance with excludeFieldsWithoutExposeAnnotation().
// *
// * @return GsonBuilder.
// */
// public static Gson getNormalGson() {
// return mDefaultGson;
// }
//
// /**
// * Create a new Gson instance with PrettyPrinting.
// *
// * @param exposeAll - TRUE to create without excludeFieldsWithoutExposeAnnotation().
// * @return Gson
// */
// public static Gson getDebugGson(boolean exposeAll) {
//
// if (exposeAll) {
// return mDebugGson;
// }
//
// return mDebugGsonWithoutEA;
// }
//
// }
| import ai.olami.util.GsonFactory; | /*
Copyright 2017, VIA Technologies, Inc. & OLAMI Team.
http://olami.ai
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package ai.olami.cloudService;
public class APIResponseBuilder {
/**
* Create API response instance by the specified response JSON string.
*
* @param jsonString - API Response JSON string.
* @return The instance mapped to the specified response JSON string.
*/
public static APIResponse create(String jsonString) {
APIResponse response = null;
try { | // Path: lib/src/main/java/ai/olami/util/GsonFactory.java
// public class GsonFactory {
//
// private static Gson mDefaultGson = new GsonBuilder()
// .excludeFieldsWithoutExposeAnnotation().create();
//
// private static Gson mDebugGson = new GsonBuilder()
// .setPrettyPrinting()
// .create();
//
// private static Gson mDebugGsonWithoutEA = new GsonBuilder()
// .setPrettyPrinting()
// .excludeFieldsWithoutExposeAnnotation()
// .create();
//
// /**
// * Create a new Gson instance with excludeFieldsWithoutExposeAnnotation().
// *
// * @return GsonBuilder.
// */
// public static Gson getNormalGson() {
// return mDefaultGson;
// }
//
// /**
// * Create a new Gson instance with PrettyPrinting.
// *
// * @param exposeAll - TRUE to create without excludeFieldsWithoutExposeAnnotation().
// * @return Gson
// */
// public static Gson getDebugGson(boolean exposeAll) {
//
// if (exposeAll) {
// return mDebugGson;
// }
//
// return mDebugGsonWithoutEA;
// }
//
// }
// Path: lib/src/main/java/ai/olami/cloudService/APIResponseBuilder.java
import ai.olami.util.GsonFactory;
/*
Copyright 2017, VIA Technologies, Inc. & OLAMI Team.
http://olami.ai
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package ai.olami.cloudService;
public class APIResponseBuilder {
/**
* Create API response instance by the specified response JSON string.
*
* @param jsonString - API Response JSON string.
* @return The instance mapped to the specified response JSON string.
*/
public static APIResponse create(String jsonString) {
APIResponse response = null;
try { | response = (APIResponse) GsonFactory.getNormalGson().fromJson(jsonString, APIResponse.class); |
olami-developers/olami-java-client-sdk | lib/src/main/java/ai/olami/cloudService/APIResponseData.java | // Path: lib/src/main/java/ai/olami/nli/NLIResult.java
// public class NLIResult {
//
// private Gson mGson = GsonFactory.getNormalGson();
//
// @Expose
// @SerializedName("desc_obj")
// private DescObject mDescObject = null;
//
// /**
// * @return Description of the analysis results.
// */
// public DescObject getDescObject() {
// return mDescObject;
// }
//
// /**
// * @return TRUE if contains description information.
// */
// public boolean hasDescObject() {
// return (mDescObject != null);
// }
//
// @Expose
// @SerializedName("semantic")
// private Semantic[] mSemantics = null;
//
// /**
// * Get the semantics of input text.
// *
// * @return Semantic array
// */
// public Semantic[] getSemantics() {
// return mSemantics;
// }
//
// /**
// * @return TRUE if contains semantics information.
// */
// public boolean hasSemantics() {
// return ((mSemantics != null) && (mSemantics.length > 0));
// }
//
// @Expose
// @SerializedName("type")
// private String mType = null;
//
// /**
// * @return Type information.
// */
// public String getType() {
// return mType;
// }
//
// /**
// * @return TRUE if contains type information.
// */
// public boolean hasType() {
// return ((mType != null) && (!mType.equals("")));
// }
//
// /**
// * Check if this result is actually a IDS response.
// *
// * @return TRUE if this result is provided by the IDS.
// */
// public boolean isFromIDS() {
// return (IDSResult.Types.contains(mType));
// }
//
// @Expose
// @SerializedName("data_obj")
// private JsonElement mDataObjs = null;
//
// /**
// * @return List of data object
// * or list of JsonElement if the object type is not defined.
// */
// public <T> ArrayList<T> getDataObjects() {
// if (isFromIDS()) {
// String typeName = mType;
// switch (IDSResult.Types.getByName(mType)) {
// case QUESTION:
// typeName = this.getDescObject().getType();
// break;
// case CONFIRMATION:
// typeName = this.getDescObject().getType();
// break;
// case SELECTION:
// typeName = this.getDescObject().getType();
// break;
// default:
// break;
// }
// return mGson.fromJson(mDataObjs,
// IDSResult.Types.getDataArrayListType(typeName));
// } else if (hasDataObjects()) {
// return mGson.fromJson(mDataObjs,
// new TypeToken<ArrayList<JsonElement>>() {}.getType());
// }
// return null;
// }
//
// /**
// * @return TRUE if contains data contents.
// */
// public boolean hasDataObjects() {
// return (mDataObjs != null);
// }
//
// }
| import ai.olami.nli.NLIResult;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName; | /*
Copyright 2017, VIA Technologies, Inc. & OLAMI Team.
http://olami.ai
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package ai.olami.cloudService;
public class APIResponseData {
@Expose
@SerializedName("seg")
private String mSegResult = null;
@Expose
@SerializedName("nli") | // Path: lib/src/main/java/ai/olami/nli/NLIResult.java
// public class NLIResult {
//
// private Gson mGson = GsonFactory.getNormalGson();
//
// @Expose
// @SerializedName("desc_obj")
// private DescObject mDescObject = null;
//
// /**
// * @return Description of the analysis results.
// */
// public DescObject getDescObject() {
// return mDescObject;
// }
//
// /**
// * @return TRUE if contains description information.
// */
// public boolean hasDescObject() {
// return (mDescObject != null);
// }
//
// @Expose
// @SerializedName("semantic")
// private Semantic[] mSemantics = null;
//
// /**
// * Get the semantics of input text.
// *
// * @return Semantic array
// */
// public Semantic[] getSemantics() {
// return mSemantics;
// }
//
// /**
// * @return TRUE if contains semantics information.
// */
// public boolean hasSemantics() {
// return ((mSemantics != null) && (mSemantics.length > 0));
// }
//
// @Expose
// @SerializedName("type")
// private String mType = null;
//
// /**
// * @return Type information.
// */
// public String getType() {
// return mType;
// }
//
// /**
// * @return TRUE if contains type information.
// */
// public boolean hasType() {
// return ((mType != null) && (!mType.equals("")));
// }
//
// /**
// * Check if this result is actually a IDS response.
// *
// * @return TRUE if this result is provided by the IDS.
// */
// public boolean isFromIDS() {
// return (IDSResult.Types.contains(mType));
// }
//
// @Expose
// @SerializedName("data_obj")
// private JsonElement mDataObjs = null;
//
// /**
// * @return List of data object
// * or list of JsonElement if the object type is not defined.
// */
// public <T> ArrayList<T> getDataObjects() {
// if (isFromIDS()) {
// String typeName = mType;
// switch (IDSResult.Types.getByName(mType)) {
// case QUESTION:
// typeName = this.getDescObject().getType();
// break;
// case CONFIRMATION:
// typeName = this.getDescObject().getType();
// break;
// case SELECTION:
// typeName = this.getDescObject().getType();
// break;
// default:
// break;
// }
// return mGson.fromJson(mDataObjs,
// IDSResult.Types.getDataArrayListType(typeName));
// } else if (hasDataObjects()) {
// return mGson.fromJson(mDataObjs,
// new TypeToken<ArrayList<JsonElement>>() {}.getType());
// }
// return null;
// }
//
// /**
// * @return TRUE if contains data contents.
// */
// public boolean hasDataObjects() {
// return (mDataObjs != null);
// }
//
// }
// Path: lib/src/main/java/ai/olami/cloudService/APIResponseData.java
import ai.olami.nli.NLIResult;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/*
Copyright 2017, VIA Technologies, Inc. & OLAMI Team.
http://olami.ai
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package ai.olami.cloudService;
public class APIResponseData {
@Expose
@SerializedName("seg")
private String mSegResult = null;
@Expose
@SerializedName("nli") | private NLIResult[] mNLIResults = null; |
olami-developers/olami-java-client-sdk | lib/src/main/java/ai/olami/cloudService/NLIConfig.java | // Path: lib/src/main/java/ai/olami/util/GsonFactory.java
// public class GsonFactory {
//
// private static Gson mDefaultGson = new GsonBuilder()
// .excludeFieldsWithoutExposeAnnotation().create();
//
// private static Gson mDebugGson = new GsonBuilder()
// .setPrettyPrinting()
// .create();
//
// private static Gson mDebugGsonWithoutEA = new GsonBuilder()
// .setPrettyPrinting()
// .excludeFieldsWithoutExposeAnnotation()
// .create();
//
// /**
// * Create a new Gson instance with excludeFieldsWithoutExposeAnnotation().
// *
// * @return GsonBuilder.
// */
// public static Gson getNormalGson() {
// return mDefaultGson;
// }
//
// /**
// * Create a new Gson instance with PrettyPrinting.
// *
// * @param exposeAll - TRUE to create without excludeFieldsWithoutExposeAnnotation().
// * @return Gson
// */
// public static Gson getDebugGson(boolean exposeAll) {
//
// if (exposeAll) {
// return mDebugGson;
// }
//
// return mDebugGsonWithoutEA;
// }
//
// }
| import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import ai.olami.util.GsonFactory; | /*
Copyright 2017, VIA Technologies, Inc. & OLAMI Team.
http://olami.ai
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package ai.olami.cloudService;
public class NLIConfig {
@Expose(serialize = false, deserialize = false) | // Path: lib/src/main/java/ai/olami/util/GsonFactory.java
// public class GsonFactory {
//
// private static Gson mDefaultGson = new GsonBuilder()
// .excludeFieldsWithoutExposeAnnotation().create();
//
// private static Gson mDebugGson = new GsonBuilder()
// .setPrettyPrinting()
// .create();
//
// private static Gson mDebugGsonWithoutEA = new GsonBuilder()
// .setPrettyPrinting()
// .excludeFieldsWithoutExposeAnnotation()
// .create();
//
// /**
// * Create a new Gson instance with excludeFieldsWithoutExposeAnnotation().
// *
// * @return GsonBuilder.
// */
// public static Gson getNormalGson() {
// return mDefaultGson;
// }
//
// /**
// * Create a new Gson instance with PrettyPrinting.
// *
// * @param exposeAll - TRUE to create without excludeFieldsWithoutExposeAnnotation().
// * @return Gson
// */
// public static Gson getDebugGson(boolean exposeAll) {
//
// if (exposeAll) {
// return mDebugGson;
// }
//
// return mDebugGsonWithoutEA;
// }
//
// }
// Path: lib/src/main/java/ai/olami/cloudService/NLIConfig.java
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import ai.olami.util.GsonFactory;
/*
Copyright 2017, VIA Technologies, Inc. & OLAMI Team.
http://olami.ai
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package ai.olami.cloudService;
public class NLIConfig {
@Expose(serialize = false, deserialize = false) | private Gson mGson = GsonFactory.getNormalGson(); |
olami-developers/olami-java-client-sdk | lib/src/main/java/ai/olami/nli/Semantic.java | // Path: lib/src/main/java/ai/olami/nli/slot/Slot.java
// public class Slot {
//
// @Expose
// @SerializedName("name")
// private String mName = null;
//
// /**
// * @return Slot name.
// */
// public String getName() {
// return mName;
// }
//
// /**
// * @return TRUE if contains Name information.
// */
// public boolean hasName() {
// return ((mName != null) && (!mName.equals("")));
// }
//
// @Expose
// @SerializedName("value")
// private String mValue = null;
//
// /**
// * @return Slot value.
// */
// public String getValue() {
// return mValue;
// }
//
// /**
// * @return TRUE if contains Value information.
// */
// public boolean hasValue() {
// return ((mValue != null) && (!mValue.equals("")));
// }
//
// @Expose
// @SerializedName("modifier")
// private String[] mModifiers = null;
//
// /**
// * @return Slot modifier.
// */
// public String[] getModifiers() {
// return mModifiers;
// }
//
// /**
// * @return TRUE if contains Modifier information.
// */
// public boolean hasModifiers() {
// return ((mModifiers != null) && (mModifiers.length > 0));
// }
//
// @Expose
// @SerializedName("datetime")
// private DateTime mDateTime = null;
//
// /**
// * @return Date time analysis results.
// */
// public DateTime getDateTime() {
// return mDateTime;
// }
//
// /**
// * @return TRUE if contains DateTime information.
// */
// public boolean hasDateTime() {
// return (mDateTime != null);
// }
//
// @Expose
// @SerializedName("num_detail")
// private NumDetail mNumDetail = null;
//
// /**
// * @return The detailed information of the number slot.
// */
// public NumDetail getNumDetail() {
// return mNumDetail;
// }
//
// /**
// * @return TRUE if contains NumDetail information.
// */
// public boolean hasNumDetail() {
// return (mNumDetail != null);
// }
//
// }
| import ai.olami.nli.slot.Slot;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName; | return mAppModule;
}
/**
* @return TRUE if contains AppModule information.
*/
public boolean hasAppModule() {
return ((mAppModule != null) && (!mAppModule.equals("")));
}
@Expose
@SerializedName("input")
private String mInput = null;
/**
* @return The original input text.
*/
public String getInput() {
return mInput;
}
/**
* @return TRUE if contains Input information.
*/
public boolean hasInput() {
return ((mInput != null) && (!mInput.equals("")));
}
@Expose
@SerializedName("slots") | // Path: lib/src/main/java/ai/olami/nli/slot/Slot.java
// public class Slot {
//
// @Expose
// @SerializedName("name")
// private String mName = null;
//
// /**
// * @return Slot name.
// */
// public String getName() {
// return mName;
// }
//
// /**
// * @return TRUE if contains Name information.
// */
// public boolean hasName() {
// return ((mName != null) && (!mName.equals("")));
// }
//
// @Expose
// @SerializedName("value")
// private String mValue = null;
//
// /**
// * @return Slot value.
// */
// public String getValue() {
// return mValue;
// }
//
// /**
// * @return TRUE if contains Value information.
// */
// public boolean hasValue() {
// return ((mValue != null) && (!mValue.equals("")));
// }
//
// @Expose
// @SerializedName("modifier")
// private String[] mModifiers = null;
//
// /**
// * @return Slot modifier.
// */
// public String[] getModifiers() {
// return mModifiers;
// }
//
// /**
// * @return TRUE if contains Modifier information.
// */
// public boolean hasModifiers() {
// return ((mModifiers != null) && (mModifiers.length > 0));
// }
//
// @Expose
// @SerializedName("datetime")
// private DateTime mDateTime = null;
//
// /**
// * @return Date time analysis results.
// */
// public DateTime getDateTime() {
// return mDateTime;
// }
//
// /**
// * @return TRUE if contains DateTime information.
// */
// public boolean hasDateTime() {
// return (mDateTime != null);
// }
//
// @Expose
// @SerializedName("num_detail")
// private NumDetail mNumDetail = null;
//
// /**
// * @return The detailed information of the number slot.
// */
// public NumDetail getNumDetail() {
// return mNumDetail;
// }
//
// /**
// * @return TRUE if contains NumDetail information.
// */
// public boolean hasNumDetail() {
// return (mNumDetail != null);
// }
//
// }
// Path: lib/src/main/java/ai/olami/nli/Semantic.java
import ai.olami.nli.slot.Slot;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
return mAppModule;
}
/**
* @return TRUE if contains AppModule information.
*/
public boolean hasAppModule() {
return ((mAppModule != null) && (!mAppModule.equals("")));
}
@Expose
@SerializedName("input")
private String mInput = null;
/**
* @return The original input text.
*/
public String getInput() {
return mInput;
}
/**
* @return TRUE if contains Input information.
*/
public boolean hasInput() {
return ((mInput != null) && (!mInput.equals("")));
}
@Expose
@SerializedName("slots") | private Slot[] mSlots = null; |
andresth/Kandroid | app/src/main/java/in/andres/kandroid/kanboard/KanboardRequest.java | // Path: app/src/main/java/in/andres/kandroid/kanboard/events/OnSubtaskTimetrackingListener.java
// public interface OnSubtaskTimetrackingListener {
// void onSubtaskTimetracking(boolean result, double time);
// }
| import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import org.apache.commons.text.StringEscapeUtils;
import java.util.Date;
import in.andres.kandroid.kanboard.events.OnSubtaskTimetrackingListener; | "}", content)});
}
@NonNull
public static KanboardRequest getAllSubtasks(int taskid) {
return new KanboardRequest("getAllSubtasks", new String[] {String.format(
"{\n" +
" \"jsonrpc\": \"2.0\",\n" +
" \"method\": \"getAllSubtasks\",\n" +
" \"id\": 2087700490,\n" +
" \"params\": {\n" +
" \"task_id\":%d\n" +
" }\n" +
"}", taskid)});
}
@NonNull
public static KanboardRequest removeSubtask(int subtaskid) {
return new KanboardRequest("removeSubtask", new String[] {String.format(
"{\n" +
" \"jsonrpc\": \"2.0\",\n" +
" \"method\": \"removeSubtask\",\n" +
" \"id\": 1382487306,\n" +
" \"params\": {\n" +
" \"subtask_id\": %d\n" +
" }\n" +
"}", subtaskid)});
}
@NonNull | // Path: app/src/main/java/in/andres/kandroid/kanboard/events/OnSubtaskTimetrackingListener.java
// public interface OnSubtaskTimetrackingListener {
// void onSubtaskTimetracking(boolean result, double time);
// }
// Path: app/src/main/java/in/andres/kandroid/kanboard/KanboardRequest.java
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import org.apache.commons.text.StringEscapeUtils;
import java.util.Date;
import in.andres.kandroid.kanboard.events.OnSubtaskTimetrackingListener;
"}", content)});
}
@NonNull
public static KanboardRequest getAllSubtasks(int taskid) {
return new KanboardRequest("getAllSubtasks", new String[] {String.format(
"{\n" +
" \"jsonrpc\": \"2.0\",\n" +
" \"method\": \"getAllSubtasks\",\n" +
" \"id\": 2087700490,\n" +
" \"params\": {\n" +
" \"task_id\":%d\n" +
" }\n" +
"}", taskid)});
}
@NonNull
public static KanboardRequest removeSubtask(int subtaskid) {
return new KanboardRequest("removeSubtask", new String[] {String.format(
"{\n" +
" \"jsonrpc\": \"2.0\",\n" +
" \"method\": \"removeSubtask\",\n" +
" \"id\": 1382487306,\n" +
" \"params\": {\n" +
" \"subtask_id\": %d\n" +
" }\n" +
"}", subtaskid)});
}
@NonNull | public static KanboardRequest hasSubtaskTimer(int subtaskid, int userid, @NonNull OnSubtaskTimetrackingListener listener) { |
andresth/Kandroid | app/src/main/java/in/andres/kandroid/ui/DashActivitiesFragment.java | // Path: app/src/main/java/in/andres/kandroid/Utils.java
// public class Utils {
// @SuppressWarnings("deprecation")
// public static Spanned fromHtml(String html){
// Spanned result;
// if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
// result = Html.fromHtml(html,Html.FROM_HTML_MODE_LEGACY);
// } else {
// result = Html.fromHtml(html);
// }
// return result;
// }
// }
//
// Path: app/src/main/java/in/andres/kandroid/kanboard/KanboardActivity.java
// @SuppressWarnings("unused")
// public class KanboardActivity implements Serializable {
// private String Title;
// private String Content;
// private String Creator;
// private String CreatorUserName;
// private int CreatorId;
// private int Id;
// private int ProjectId;
// private int TaskId;
// private Date DateCreation;
//
// public KanboardActivity(JSONObject json) {
// Title = json.optString("event_title");
// Content = json.optString("event_content");
// Creator = json.optString("author");
// CreatorUserName = json.optString("author_username");
// CreatorId = json.optInt("creator_id");
// Id = json.optInt("id");
// ProjectId = json.optInt("project_id");
// TaskId = json.optInt("task_id");
// DateCreation = new Date(json.optLong("date_creation") * 1000);
// }
//
// public String getTitle() {
// return Title;
// }
//
// public String getContent() {
// return Content;
// }
//
// public String getCreator() {
// return Creator;
// }
//
// public String getCreatorUserName() {
// return CreatorUserName;
// }
//
// public int getCreatorId() {
// return CreatorId;
// }
//
// public int getId() {
// return Id;
// }
//
// public int getProjectId() {
// return ProjectId;
// }
//
// public int getTaskId() {
// return TaskId;
// }
//
// public Date getDateCreation() {
// return DateCreation;
// }
//
// @Override
// public String toString() {
// return this.Title + " " + this.DateCreation.toString();
// }
// }
| import in.andres.kandroid.Utils;
import in.andres.kandroid.kanboard.KanboardActivity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.List; | /*
* Copyright 2017 Thomas Andres
*
* This file is part of Kandroid.
*
* Kandroid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kandroid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
package in.andres.kandroid.ui;
public class DashActivitiesFragment extends ListFragment {
public DashActivitiesFragment() {}
public static DashActivitiesFragment newInstance() {
return new DashActivitiesFragment();
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (((MainActivity)getActivity()).getDashboard() != null) {
DashActivityAdapter listAdapter = new DashActivityAdapter(getContext(), ((MainActivity)getActivity()).getDashboard().getActivities());
setListAdapter(listAdapter);
}
}
| // Path: app/src/main/java/in/andres/kandroid/Utils.java
// public class Utils {
// @SuppressWarnings("deprecation")
// public static Spanned fromHtml(String html){
// Spanned result;
// if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
// result = Html.fromHtml(html,Html.FROM_HTML_MODE_LEGACY);
// } else {
// result = Html.fromHtml(html);
// }
// return result;
// }
// }
//
// Path: app/src/main/java/in/andres/kandroid/kanboard/KanboardActivity.java
// @SuppressWarnings("unused")
// public class KanboardActivity implements Serializable {
// private String Title;
// private String Content;
// private String Creator;
// private String CreatorUserName;
// private int CreatorId;
// private int Id;
// private int ProjectId;
// private int TaskId;
// private Date DateCreation;
//
// public KanboardActivity(JSONObject json) {
// Title = json.optString("event_title");
// Content = json.optString("event_content");
// Creator = json.optString("author");
// CreatorUserName = json.optString("author_username");
// CreatorId = json.optInt("creator_id");
// Id = json.optInt("id");
// ProjectId = json.optInt("project_id");
// TaskId = json.optInt("task_id");
// DateCreation = new Date(json.optLong("date_creation") * 1000);
// }
//
// public String getTitle() {
// return Title;
// }
//
// public String getContent() {
// return Content;
// }
//
// public String getCreator() {
// return Creator;
// }
//
// public String getCreatorUserName() {
// return CreatorUserName;
// }
//
// public int getCreatorId() {
// return CreatorId;
// }
//
// public int getId() {
// return Id;
// }
//
// public int getProjectId() {
// return ProjectId;
// }
//
// public int getTaskId() {
// return TaskId;
// }
//
// public Date getDateCreation() {
// return DateCreation;
// }
//
// @Override
// public String toString() {
// return this.Title + " " + this.DateCreation.toString();
// }
// }
// Path: app/src/main/java/in/andres/kandroid/ui/DashActivitiesFragment.java
import in.andres.kandroid.Utils;
import in.andres.kandroid.kanboard.KanboardActivity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.List;
/*
* Copyright 2017 Thomas Andres
*
* This file is part of Kandroid.
*
* Kandroid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kandroid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
package in.andres.kandroid.ui;
public class DashActivitiesFragment extends ListFragment {
public DashActivitiesFragment() {}
public static DashActivitiesFragment newInstance() {
return new DashActivitiesFragment();
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (((MainActivity)getActivity()).getDashboard() != null) {
DashActivityAdapter listAdapter = new DashActivityAdapter(getContext(), ((MainActivity)getActivity()).getDashboard().getActivities());
setListAdapter(listAdapter);
}
}
| class DashActivityAdapter extends ArrayAdapter<KanboardActivity> { |
andresth/Kandroid | app/src/main/java/in/andres/kandroid/ui/DashActivitiesFragment.java | // Path: app/src/main/java/in/andres/kandroid/Utils.java
// public class Utils {
// @SuppressWarnings("deprecation")
// public static Spanned fromHtml(String html){
// Spanned result;
// if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
// result = Html.fromHtml(html,Html.FROM_HTML_MODE_LEGACY);
// } else {
// result = Html.fromHtml(html);
// }
// return result;
// }
// }
//
// Path: app/src/main/java/in/andres/kandroid/kanboard/KanboardActivity.java
// @SuppressWarnings("unused")
// public class KanboardActivity implements Serializable {
// private String Title;
// private String Content;
// private String Creator;
// private String CreatorUserName;
// private int CreatorId;
// private int Id;
// private int ProjectId;
// private int TaskId;
// private Date DateCreation;
//
// public KanboardActivity(JSONObject json) {
// Title = json.optString("event_title");
// Content = json.optString("event_content");
// Creator = json.optString("author");
// CreatorUserName = json.optString("author_username");
// CreatorId = json.optInt("creator_id");
// Id = json.optInt("id");
// ProjectId = json.optInt("project_id");
// TaskId = json.optInt("task_id");
// DateCreation = new Date(json.optLong("date_creation") * 1000);
// }
//
// public String getTitle() {
// return Title;
// }
//
// public String getContent() {
// return Content;
// }
//
// public String getCreator() {
// return Creator;
// }
//
// public String getCreatorUserName() {
// return CreatorUserName;
// }
//
// public int getCreatorId() {
// return CreatorId;
// }
//
// public int getId() {
// return Id;
// }
//
// public int getProjectId() {
// return ProjectId;
// }
//
// public int getTaskId() {
// return TaskId;
// }
//
// public Date getDateCreation() {
// return DateCreation;
// }
//
// @Override
// public String toString() {
// return this.Title + " " + this.DateCreation.toString();
// }
// }
| import in.andres.kandroid.Utils;
import in.andres.kandroid.kanboard.KanboardActivity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.List; | /*
* Copyright 2017 Thomas Andres
*
* This file is part of Kandroid.
*
* Kandroid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kandroid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
package in.andres.kandroid.ui;
public class DashActivitiesFragment extends ListFragment {
public DashActivitiesFragment() {}
public static DashActivitiesFragment newInstance() {
return new DashActivitiesFragment();
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (((MainActivity)getActivity()).getDashboard() != null) {
DashActivityAdapter listAdapter = new DashActivityAdapter(getContext(), ((MainActivity)getActivity()).getDashboard().getActivities());
setListAdapter(listAdapter);
}
}
class DashActivityAdapter extends ArrayAdapter<KanboardActivity> {
private Context mContext;
private LayoutInflater mInflater;
private List<KanboardActivity> mValues;
DashActivityAdapter(Context context, List<KanboardActivity> values) {
super(context, android.R.layout.simple_list_item_1, values);
mContext = context;
mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mValues = values;
}
@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
if (convertView == null)
convertView = mInflater.inflate(android.R.layout.simple_list_item_1, parent, false);
TextView textView = (TextView) convertView.findViewById(android.R.id.text1); | // Path: app/src/main/java/in/andres/kandroid/Utils.java
// public class Utils {
// @SuppressWarnings("deprecation")
// public static Spanned fromHtml(String html){
// Spanned result;
// if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
// result = Html.fromHtml(html,Html.FROM_HTML_MODE_LEGACY);
// } else {
// result = Html.fromHtml(html);
// }
// return result;
// }
// }
//
// Path: app/src/main/java/in/andres/kandroid/kanboard/KanboardActivity.java
// @SuppressWarnings("unused")
// public class KanboardActivity implements Serializable {
// private String Title;
// private String Content;
// private String Creator;
// private String CreatorUserName;
// private int CreatorId;
// private int Id;
// private int ProjectId;
// private int TaskId;
// private Date DateCreation;
//
// public KanboardActivity(JSONObject json) {
// Title = json.optString("event_title");
// Content = json.optString("event_content");
// Creator = json.optString("author");
// CreatorUserName = json.optString("author_username");
// CreatorId = json.optInt("creator_id");
// Id = json.optInt("id");
// ProjectId = json.optInt("project_id");
// TaskId = json.optInt("task_id");
// DateCreation = new Date(json.optLong("date_creation") * 1000);
// }
//
// public String getTitle() {
// return Title;
// }
//
// public String getContent() {
// return Content;
// }
//
// public String getCreator() {
// return Creator;
// }
//
// public String getCreatorUserName() {
// return CreatorUserName;
// }
//
// public int getCreatorId() {
// return CreatorId;
// }
//
// public int getId() {
// return Id;
// }
//
// public int getProjectId() {
// return ProjectId;
// }
//
// public int getTaskId() {
// return TaskId;
// }
//
// public Date getDateCreation() {
// return DateCreation;
// }
//
// @Override
// public String toString() {
// return this.Title + " " + this.DateCreation.toString();
// }
// }
// Path: app/src/main/java/in/andres/kandroid/ui/DashActivitiesFragment.java
import in.andres.kandroid.Utils;
import in.andres.kandroid.kanboard.KanboardActivity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.List;
/*
* Copyright 2017 Thomas Andres
*
* This file is part of Kandroid.
*
* Kandroid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kandroid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
package in.andres.kandroid.ui;
public class DashActivitiesFragment extends ListFragment {
public DashActivitiesFragment() {}
public static DashActivitiesFragment newInstance() {
return new DashActivitiesFragment();
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (((MainActivity)getActivity()).getDashboard() != null) {
DashActivityAdapter listAdapter = new DashActivityAdapter(getContext(), ((MainActivity)getActivity()).getDashboard().getActivities());
setListAdapter(listAdapter);
}
}
class DashActivityAdapter extends ArrayAdapter<KanboardActivity> {
private Context mContext;
private LayoutInflater mInflater;
private List<KanboardActivity> mValues;
DashActivityAdapter(Context context, List<KanboardActivity> values) {
super(context, android.R.layout.simple_list_item_1, values);
mContext = context;
mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mValues = values;
}
@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
if (convertView == null)
convertView = mInflater.inflate(android.R.layout.simple_list_item_1, parent, false);
TextView textView = (TextView) convertView.findViewById(android.R.id.text1); | textView.setText(Utils.fromHtml(mValues.get(position).getContent())); |
andresth/Kandroid | app/src/main/java/in/andres/kandroid/kanboard/KanboardDashboard.java | // Path: app/src/main/java/in/andres/kandroid/Constants.java
// public interface Constants {
// String TAG = "Kandroid";
// int ResultChanged = 1;
// int RequestEditTask = 1;
// int FileSelectCode = 10;
// int RequestStoragePermission = 20;
// int[] minKanboardVersion = new int[] {1, 0, 38};
// }
| import java.util.Dictionary;
import java.util.Hashtable;
import java.util.List;
import in.andres.kandroid.Constants;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.util.ArrayList; | /*
* Copyright 2017 Thomas Andres
*
* This file is part of Kandroid.
*
* Kandroid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kandroid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
package in.andres.kandroid.kanboard;
@SuppressWarnings("unused")
public class KanboardDashboard implements Serializable {
private List<KanboardProject> Projects;
private List<KanboardTask> Tasks;
private List<KanboardSubtask> Subtasks;
private Dictionary<Integer, List<KanboardTask>> GroupedTasks;
private List<KanboardTask> OverdueTasks = new ArrayList<>();
private List<KanboardActivity> Activities = new ArrayList<>();
private boolean newDashFormat = false;
public KanboardDashboard(@NonNull Object dashboard) throws MalformedURLException {
this(dashboard, null, null);
}
public KanboardDashboard(@NonNull Object dashboard, @Nullable JSONArray overdue, @Nullable JSONArray activities) throws MalformedURLException {
GroupedTasks = new Hashtable<>();
Projects = new ArrayList<>();
if (dashboard instanceof JSONObject) { | // Path: app/src/main/java/in/andres/kandroid/Constants.java
// public interface Constants {
// String TAG = "Kandroid";
// int ResultChanged = 1;
// int RequestEditTask = 1;
// int FileSelectCode = 10;
// int RequestStoragePermission = 20;
// int[] minKanboardVersion = new int[] {1, 0, 38};
// }
// Path: app/src/main/java/in/andres/kandroid/kanboard/KanboardDashboard.java
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.List;
import in.andres.kandroid.Constants;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.util.ArrayList;
/*
* Copyright 2017 Thomas Andres
*
* This file is part of Kandroid.
*
* Kandroid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kandroid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
package in.andres.kandroid.kanboard;
@SuppressWarnings("unused")
public class KanboardDashboard implements Serializable {
private List<KanboardProject> Projects;
private List<KanboardTask> Tasks;
private List<KanboardSubtask> Subtasks;
private Dictionary<Integer, List<KanboardTask>> GroupedTasks;
private List<KanboardTask> OverdueTasks = new ArrayList<>();
private List<KanboardActivity> Activities = new ArrayList<>();
private boolean newDashFormat = false;
public KanboardDashboard(@NonNull Object dashboard) throws MalformedURLException {
this(dashboard, null, null);
}
public KanboardDashboard(@NonNull Object dashboard, @Nullable JSONArray overdue, @Nullable JSONArray activities) throws MalformedURLException {
GroupedTasks = new Hashtable<>();
Projects = new ArrayList<>();
if (dashboard instanceof JSONObject) { | Log.i(Constants.TAG, "Old Dashboard"); |
hitherejoe/AndroidTvBoilerplate | app/src/main/java/com/hitherejoe/androidtvboilerplate/AndroidTvBoilerplateApplication.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/injection/component/ApplicationComponent.java
// @Singleton
// @Component(modules = ApplicationModule.class)
// public interface ApplicationComponent {
//
// @ApplicationContext
// Context context();
// Application application();
// PreferencesHelper preferencesHelper();
// DataManager dataManager();
// CompositeSubscription compositeSubscription();
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/injection/module/ApplicationModule.java
// @Module
// public class ApplicationModule {
// protected final Application mApplication;
//
// public ApplicationModule(Application application) {
// mApplication = application;
// }
//
// @Provides
// @ApplicationContext
// Context provideContext() {
// return mApplication;
// }
//
// @Provides
// @Singleton
// Application provideApplication() {
// return mApplication;
// }
//
// @Provides
// CompositeSubscription provideCompositeSubscription() {
// return new CompositeSubscription();
// }
//
// @Provides
// @Singleton
// AndroidTvBoilerplateService provideVineyardService() {
// return AndroidTvBoilerplateService.Creator.newVineyardService();
// }
// }
| import android.app.Application;
import android.content.Context;
import com.hitherejoe.androidtvboilerplate.injection.component.ApplicationComponent;
import com.hitherejoe.androidtvboilerplate.injection.component.DaggerApplicationComponent;
import com.hitherejoe.androidtvboilerplate.injection.module.ApplicationModule;
import timber.log.Timber; | package com.hitherejoe.androidtvboilerplate;
public class AndroidTvBoilerplateApplication extends Application {
ApplicationComponent mApplicationComponent;
@Override
public void onCreate() {
super.onCreate();
if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree());
mApplicationComponent = DaggerApplicationComponent.builder() | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/injection/component/ApplicationComponent.java
// @Singleton
// @Component(modules = ApplicationModule.class)
// public interface ApplicationComponent {
//
// @ApplicationContext
// Context context();
// Application application();
// PreferencesHelper preferencesHelper();
// DataManager dataManager();
// CompositeSubscription compositeSubscription();
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/injection/module/ApplicationModule.java
// @Module
// public class ApplicationModule {
// protected final Application mApplication;
//
// public ApplicationModule(Application application) {
// mApplication = application;
// }
//
// @Provides
// @ApplicationContext
// Context provideContext() {
// return mApplication;
// }
//
// @Provides
// @Singleton
// Application provideApplication() {
// return mApplication;
// }
//
// @Provides
// CompositeSubscription provideCompositeSubscription() {
// return new CompositeSubscription();
// }
//
// @Provides
// @Singleton
// AndroidTvBoilerplateService provideVineyardService() {
// return AndroidTvBoilerplateService.Creator.newVineyardService();
// }
// }
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/AndroidTvBoilerplateApplication.java
import android.app.Application;
import android.content.Context;
import com.hitherejoe.androidtvboilerplate.injection.component.ApplicationComponent;
import com.hitherejoe.androidtvboilerplate.injection.component.DaggerApplicationComponent;
import com.hitherejoe.androidtvboilerplate.injection.module.ApplicationModule;
import timber.log.Timber;
package com.hitherejoe.androidtvboilerplate;
public class AndroidTvBoilerplateApplication extends Application {
ApplicationComponent mApplicationComponent;
@Override
public void onCreate() {
super.onCreate();
if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree());
mApplicationComponent = DaggerApplicationComponent.builder() | .applicationModule(new ApplicationModule(this)) |
hitherejoe/AndroidTvBoilerplate | app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/common/CardPresenter.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
| import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v17.leanback.widget.ImageCardView;
import android.support.v17.leanback.widget.Presenter;
import android.support.v4.content.ContextCompat;
import android.view.ViewGroup;
import com.bumptech.glide.Glide;
import com.hitherejoe.androidtvboilerplate.R;
import com.hitherejoe.androidtvboilerplate.data.model.Cat; |
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
Context context = parent.getContext();
mDefaultBackgroundColor = ContextCompat.getColor(context, R.color.primary);
mSelectedBackgroundColor = ContextCompat.getColor(context, R.color.primary_dark);
mDefaultCardImage = ContextCompat.getDrawable(context, R.drawable.card_default);
ImageCardView cardView = new ImageCardView(parent.getContext()) {
@Override
public void setSelected(boolean selected) {
updateCardBackgroundColor(this, selected);
super.setSelected(selected);
}
};
cardView.setFocusable(true);
cardView.setFocusableInTouchMode(true);
updateCardBackgroundColor(cardView, false);
return new ViewHolder(cardView);
}
private void updateCardBackgroundColor(ImageCardView view, boolean selected) {
int color = selected ? mSelectedBackgroundColor : mDefaultBackgroundColor;
view.setBackgroundColor(color);
view.findViewById(R.id.info_field).setBackgroundColor(color);
}
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) { | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/common/CardPresenter.java
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v17.leanback.widget.ImageCardView;
import android.support.v17.leanback.widget.Presenter;
import android.support.v4.content.ContextCompat;
import android.view.ViewGroup;
import com.bumptech.glide.Glide;
import com.hitherejoe.androidtvboilerplate.R;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
Context context = parent.getContext();
mDefaultBackgroundColor = ContextCompat.getColor(context, R.color.primary);
mSelectedBackgroundColor = ContextCompat.getColor(context, R.color.primary_dark);
mDefaultCardImage = ContextCompat.getDrawable(context, R.drawable.card_default);
ImageCardView cardView = new ImageCardView(parent.getContext()) {
@Override
public void setSelected(boolean selected) {
updateCardBackgroundColor(this, selected);
super.setSelected(selected);
}
};
cardView.setFocusable(true);
cardView.setFocusableInTouchMode(true);
updateCardBackgroundColor(cardView, false);
return new ViewHolder(cardView);
}
private void updateCardBackgroundColor(ImageCardView view, boolean selected) {
int color = selected ? mSelectedBackgroundColor : mDefaultBackgroundColor;
view.setBackgroundColor(color);
view.findViewById(R.id.info_field).setBackgroundColor(color);
}
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) { | Cat cat = (Cat) item; |
hitherejoe/AndroidTvBoilerplate | app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/AndroidTvBoilerplateApplication.java
// public class AndroidTvBoilerplateApplication extends Application {
//
// ApplicationComponent mApplicationComponent;
//
// @Override
// public void onCreate() {
// super.onCreate();
// if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree());
//
// mApplicationComponent = DaggerApplicationComponent.builder()
// .applicationModule(new ApplicationModule(this))
// .build();
// }
//
// public static AndroidTvBoilerplateApplication get(Context context) {
// return (AndroidTvBoilerplateApplication) context.getApplicationContext();
// }
//
// // Needed to replace the component with a test specific one
// public void setComponent(ApplicationComponent applicationComponent) {
// mApplicationComponent = applicationComponent;
// }
//
// public ApplicationComponent getComponent() {
// if (mApplicationComponent == null) {
// mApplicationComponent = DaggerApplicationComponent.builder()
// .applicationModule(new ApplicationModule(this))
// .build();
// }
// return mApplicationComponent;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/injection/component/TestComponent.java
// @Singleton
// @Component(modules = ApplicationTestModule.class)
// public interface TestComponent extends ApplicationComponent {
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/injection/module/ApplicationTestModule.java
// @Module
// public class ApplicationTestModule {
//
// private final Application mApplication;
//
// public ApplicationTestModule(Application application) {
// mApplication = application;
// }
//
// @Provides
// Application provideApplication() {
// return mApplication;
// }
//
// @Provides
// @ApplicationContext
// Context provideContext() {
// return mApplication;
// }
//
// @Provides
// CompositeSubscription provideCompositeSubscription() {
// return new CompositeSubscription();
// }
//
// /************* MOCKS *************/
//
// @Provides
// @Singleton
// DataManager provideDataManager() {
// return mock(DataManager.class);
// }
//
// @Provides
// @Singleton
// PreferencesHelper providePreferencesHelper() {
// return mock(PreferencesHelper.class);
// }
//
// @Provides
// @Singleton
// AndroidTvBoilerplateService provideAndroidTvBoilerplateService() {
// return mock(AndroidTvBoilerplateService.class);
// }
//
// }
| import android.content.Context;
import com.hitherejoe.androidtvboilerplate.AndroidTvBoilerplateApplication;
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.test.common.injection.component.DaggerTestComponent;
import com.hitherejoe.androidtvboilerplate.test.common.injection.component.TestComponent;
import com.hitherejoe.androidtvboilerplate.test.common.injection.module.ApplicationTestModule;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement; | package com.hitherejoe.androidtvboilerplate.test.common.rules;
/**
* Test rule that creates and sets a Dagger TestComponent into the application overriding the
* existing application component.
* Use this rule in your test case in order for the app to use mock dependencies.
* It also exposes some of the dependencies so they can be easily accessed from the tests, e.g. to
* stub mocks etc.
*/
public class TestComponentRule implements TestRule {
private final TestComponent mTestComponent;
private final Context mContext;
public TestComponentRule(Context context) {
mContext = context; | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/AndroidTvBoilerplateApplication.java
// public class AndroidTvBoilerplateApplication extends Application {
//
// ApplicationComponent mApplicationComponent;
//
// @Override
// public void onCreate() {
// super.onCreate();
// if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree());
//
// mApplicationComponent = DaggerApplicationComponent.builder()
// .applicationModule(new ApplicationModule(this))
// .build();
// }
//
// public static AndroidTvBoilerplateApplication get(Context context) {
// return (AndroidTvBoilerplateApplication) context.getApplicationContext();
// }
//
// // Needed to replace the component with a test specific one
// public void setComponent(ApplicationComponent applicationComponent) {
// mApplicationComponent = applicationComponent;
// }
//
// public ApplicationComponent getComponent() {
// if (mApplicationComponent == null) {
// mApplicationComponent = DaggerApplicationComponent.builder()
// .applicationModule(new ApplicationModule(this))
// .build();
// }
// return mApplicationComponent;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/injection/component/TestComponent.java
// @Singleton
// @Component(modules = ApplicationTestModule.class)
// public interface TestComponent extends ApplicationComponent {
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/injection/module/ApplicationTestModule.java
// @Module
// public class ApplicationTestModule {
//
// private final Application mApplication;
//
// public ApplicationTestModule(Application application) {
// mApplication = application;
// }
//
// @Provides
// Application provideApplication() {
// return mApplication;
// }
//
// @Provides
// @ApplicationContext
// Context provideContext() {
// return mApplication;
// }
//
// @Provides
// CompositeSubscription provideCompositeSubscription() {
// return new CompositeSubscription();
// }
//
// /************* MOCKS *************/
//
// @Provides
// @Singleton
// DataManager provideDataManager() {
// return mock(DataManager.class);
// }
//
// @Provides
// @Singleton
// PreferencesHelper providePreferencesHelper() {
// return mock(PreferencesHelper.class);
// }
//
// @Provides
// @Singleton
// AndroidTvBoilerplateService provideAndroidTvBoilerplateService() {
// return mock(AndroidTvBoilerplateService.class);
// }
//
// }
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java
import android.content.Context;
import com.hitherejoe.androidtvboilerplate.AndroidTvBoilerplateApplication;
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.test.common.injection.component.DaggerTestComponent;
import com.hitherejoe.androidtvboilerplate.test.common.injection.component.TestComponent;
import com.hitherejoe.androidtvboilerplate.test.common.injection.module.ApplicationTestModule;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
package com.hitherejoe.androidtvboilerplate.test.common.rules;
/**
* Test rule that creates and sets a Dagger TestComponent into the application overriding the
* existing application component.
* Use this rule in your test case in order for the app to use mock dependencies.
* It also exposes some of the dependencies so they can be easily accessed from the tests, e.g. to
* stub mocks etc.
*/
public class TestComponentRule implements TestRule {
private final TestComponent mTestComponent;
private final Context mContext;
public TestComponentRule(Context context) {
mContext = context; | AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context); |
hitherejoe/AndroidTvBoilerplate | app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/AndroidTvBoilerplateApplication.java
// public class AndroidTvBoilerplateApplication extends Application {
//
// ApplicationComponent mApplicationComponent;
//
// @Override
// public void onCreate() {
// super.onCreate();
// if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree());
//
// mApplicationComponent = DaggerApplicationComponent.builder()
// .applicationModule(new ApplicationModule(this))
// .build();
// }
//
// public static AndroidTvBoilerplateApplication get(Context context) {
// return (AndroidTvBoilerplateApplication) context.getApplicationContext();
// }
//
// // Needed to replace the component with a test specific one
// public void setComponent(ApplicationComponent applicationComponent) {
// mApplicationComponent = applicationComponent;
// }
//
// public ApplicationComponent getComponent() {
// if (mApplicationComponent == null) {
// mApplicationComponent = DaggerApplicationComponent.builder()
// .applicationModule(new ApplicationModule(this))
// .build();
// }
// return mApplicationComponent;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/injection/component/TestComponent.java
// @Singleton
// @Component(modules = ApplicationTestModule.class)
// public interface TestComponent extends ApplicationComponent {
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/injection/module/ApplicationTestModule.java
// @Module
// public class ApplicationTestModule {
//
// private final Application mApplication;
//
// public ApplicationTestModule(Application application) {
// mApplication = application;
// }
//
// @Provides
// Application provideApplication() {
// return mApplication;
// }
//
// @Provides
// @ApplicationContext
// Context provideContext() {
// return mApplication;
// }
//
// @Provides
// CompositeSubscription provideCompositeSubscription() {
// return new CompositeSubscription();
// }
//
// /************* MOCKS *************/
//
// @Provides
// @Singleton
// DataManager provideDataManager() {
// return mock(DataManager.class);
// }
//
// @Provides
// @Singleton
// PreferencesHelper providePreferencesHelper() {
// return mock(PreferencesHelper.class);
// }
//
// @Provides
// @Singleton
// AndroidTvBoilerplateService provideAndroidTvBoilerplateService() {
// return mock(AndroidTvBoilerplateService.class);
// }
//
// }
| import android.content.Context;
import com.hitherejoe.androidtvboilerplate.AndroidTvBoilerplateApplication;
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.test.common.injection.component.DaggerTestComponent;
import com.hitherejoe.androidtvboilerplate.test.common.injection.component.TestComponent;
import com.hitherejoe.androidtvboilerplate.test.common.injection.module.ApplicationTestModule;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement; | package com.hitherejoe.androidtvboilerplate.test.common.rules;
/**
* Test rule that creates and sets a Dagger TestComponent into the application overriding the
* existing application component.
* Use this rule in your test case in order for the app to use mock dependencies.
* It also exposes some of the dependencies so they can be easily accessed from the tests, e.g. to
* stub mocks etc.
*/
public class TestComponentRule implements TestRule {
private final TestComponent mTestComponent;
private final Context mContext;
public TestComponentRule(Context context) {
mContext = context;
AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context);
mTestComponent = DaggerTestComponent.builder() | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/AndroidTvBoilerplateApplication.java
// public class AndroidTvBoilerplateApplication extends Application {
//
// ApplicationComponent mApplicationComponent;
//
// @Override
// public void onCreate() {
// super.onCreate();
// if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree());
//
// mApplicationComponent = DaggerApplicationComponent.builder()
// .applicationModule(new ApplicationModule(this))
// .build();
// }
//
// public static AndroidTvBoilerplateApplication get(Context context) {
// return (AndroidTvBoilerplateApplication) context.getApplicationContext();
// }
//
// // Needed to replace the component with a test specific one
// public void setComponent(ApplicationComponent applicationComponent) {
// mApplicationComponent = applicationComponent;
// }
//
// public ApplicationComponent getComponent() {
// if (mApplicationComponent == null) {
// mApplicationComponent = DaggerApplicationComponent.builder()
// .applicationModule(new ApplicationModule(this))
// .build();
// }
// return mApplicationComponent;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/injection/component/TestComponent.java
// @Singleton
// @Component(modules = ApplicationTestModule.class)
// public interface TestComponent extends ApplicationComponent {
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/injection/module/ApplicationTestModule.java
// @Module
// public class ApplicationTestModule {
//
// private final Application mApplication;
//
// public ApplicationTestModule(Application application) {
// mApplication = application;
// }
//
// @Provides
// Application provideApplication() {
// return mApplication;
// }
//
// @Provides
// @ApplicationContext
// Context provideContext() {
// return mApplication;
// }
//
// @Provides
// CompositeSubscription provideCompositeSubscription() {
// return new CompositeSubscription();
// }
//
// /************* MOCKS *************/
//
// @Provides
// @Singleton
// DataManager provideDataManager() {
// return mock(DataManager.class);
// }
//
// @Provides
// @Singleton
// PreferencesHelper providePreferencesHelper() {
// return mock(PreferencesHelper.class);
// }
//
// @Provides
// @Singleton
// AndroidTvBoilerplateService provideAndroidTvBoilerplateService() {
// return mock(AndroidTvBoilerplateService.class);
// }
//
// }
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java
import android.content.Context;
import com.hitherejoe.androidtvboilerplate.AndroidTvBoilerplateApplication;
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.test.common.injection.component.DaggerTestComponent;
import com.hitherejoe.androidtvboilerplate.test.common.injection.component.TestComponent;
import com.hitherejoe.androidtvboilerplate.test.common.injection.module.ApplicationTestModule;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
package com.hitherejoe.androidtvboilerplate.test.common.rules;
/**
* Test rule that creates and sets a Dagger TestComponent into the application overriding the
* existing application component.
* Use this rule in your test case in order for the app to use mock dependencies.
* It also exposes some of the dependencies so they can be easily accessed from the tests, e.g. to
* stub mocks etc.
*/
public class TestComponentRule implements TestRule {
private final TestComponent mTestComponent;
private final Context mContext;
public TestComponentRule(Context context) {
mContext = context;
AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context);
mTestComponent = DaggerTestComponent.builder() | .applicationTestModule(new ApplicationTestModule(application)) |
hitherejoe/AndroidTvBoilerplate | app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/AndroidTvBoilerplateApplication.java
// public class AndroidTvBoilerplateApplication extends Application {
//
// ApplicationComponent mApplicationComponent;
//
// @Override
// public void onCreate() {
// super.onCreate();
// if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree());
//
// mApplicationComponent = DaggerApplicationComponent.builder()
// .applicationModule(new ApplicationModule(this))
// .build();
// }
//
// public static AndroidTvBoilerplateApplication get(Context context) {
// return (AndroidTvBoilerplateApplication) context.getApplicationContext();
// }
//
// // Needed to replace the component with a test specific one
// public void setComponent(ApplicationComponent applicationComponent) {
// mApplicationComponent = applicationComponent;
// }
//
// public ApplicationComponent getComponent() {
// if (mApplicationComponent == null) {
// mApplicationComponent = DaggerApplicationComponent.builder()
// .applicationModule(new ApplicationModule(this))
// .build();
// }
// return mApplicationComponent;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/injection/component/TestComponent.java
// @Singleton
// @Component(modules = ApplicationTestModule.class)
// public interface TestComponent extends ApplicationComponent {
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/injection/module/ApplicationTestModule.java
// @Module
// public class ApplicationTestModule {
//
// private final Application mApplication;
//
// public ApplicationTestModule(Application application) {
// mApplication = application;
// }
//
// @Provides
// Application provideApplication() {
// return mApplication;
// }
//
// @Provides
// @ApplicationContext
// Context provideContext() {
// return mApplication;
// }
//
// @Provides
// CompositeSubscription provideCompositeSubscription() {
// return new CompositeSubscription();
// }
//
// /************* MOCKS *************/
//
// @Provides
// @Singleton
// DataManager provideDataManager() {
// return mock(DataManager.class);
// }
//
// @Provides
// @Singleton
// PreferencesHelper providePreferencesHelper() {
// return mock(PreferencesHelper.class);
// }
//
// @Provides
// @Singleton
// AndroidTvBoilerplateService provideAndroidTvBoilerplateService() {
// return mock(AndroidTvBoilerplateService.class);
// }
//
// }
| import android.content.Context;
import com.hitherejoe.androidtvboilerplate.AndroidTvBoilerplateApplication;
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.test.common.injection.component.DaggerTestComponent;
import com.hitherejoe.androidtvboilerplate.test.common.injection.component.TestComponent;
import com.hitherejoe.androidtvboilerplate.test.common.injection.module.ApplicationTestModule;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement; | package com.hitherejoe.androidtvboilerplate.test.common.rules;
/**
* Test rule that creates and sets a Dagger TestComponent into the application overriding the
* existing application component.
* Use this rule in your test case in order for the app to use mock dependencies.
* It also exposes some of the dependencies so they can be easily accessed from the tests, e.g. to
* stub mocks etc.
*/
public class TestComponentRule implements TestRule {
private final TestComponent mTestComponent;
private final Context mContext;
public TestComponentRule(Context context) {
mContext = context;
AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context);
mTestComponent = DaggerTestComponent.builder()
.applicationTestModule(new ApplicationTestModule(application))
.build();
}
public Context getContext() {
return mContext;
}
| // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/AndroidTvBoilerplateApplication.java
// public class AndroidTvBoilerplateApplication extends Application {
//
// ApplicationComponent mApplicationComponent;
//
// @Override
// public void onCreate() {
// super.onCreate();
// if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree());
//
// mApplicationComponent = DaggerApplicationComponent.builder()
// .applicationModule(new ApplicationModule(this))
// .build();
// }
//
// public static AndroidTvBoilerplateApplication get(Context context) {
// return (AndroidTvBoilerplateApplication) context.getApplicationContext();
// }
//
// // Needed to replace the component with a test specific one
// public void setComponent(ApplicationComponent applicationComponent) {
// mApplicationComponent = applicationComponent;
// }
//
// public ApplicationComponent getComponent() {
// if (mApplicationComponent == null) {
// mApplicationComponent = DaggerApplicationComponent.builder()
// .applicationModule(new ApplicationModule(this))
// .build();
// }
// return mApplicationComponent;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/injection/component/TestComponent.java
// @Singleton
// @Component(modules = ApplicationTestModule.class)
// public interface TestComponent extends ApplicationComponent {
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/injection/module/ApplicationTestModule.java
// @Module
// public class ApplicationTestModule {
//
// private final Application mApplication;
//
// public ApplicationTestModule(Application application) {
// mApplication = application;
// }
//
// @Provides
// Application provideApplication() {
// return mApplication;
// }
//
// @Provides
// @ApplicationContext
// Context provideContext() {
// return mApplication;
// }
//
// @Provides
// CompositeSubscription provideCompositeSubscription() {
// return new CompositeSubscription();
// }
//
// /************* MOCKS *************/
//
// @Provides
// @Singleton
// DataManager provideDataManager() {
// return mock(DataManager.class);
// }
//
// @Provides
// @Singleton
// PreferencesHelper providePreferencesHelper() {
// return mock(PreferencesHelper.class);
// }
//
// @Provides
// @Singleton
// AndroidTvBoilerplateService provideAndroidTvBoilerplateService() {
// return mock(AndroidTvBoilerplateService.class);
// }
//
// }
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java
import android.content.Context;
import com.hitherejoe.androidtvboilerplate.AndroidTvBoilerplateApplication;
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.test.common.injection.component.DaggerTestComponent;
import com.hitherejoe.androidtvboilerplate.test.common.injection.component.TestComponent;
import com.hitherejoe.androidtvboilerplate.test.common.injection.module.ApplicationTestModule;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
package com.hitherejoe.androidtvboilerplate.test.common.rules;
/**
* Test rule that creates and sets a Dagger TestComponent into the application overriding the
* existing application component.
* Use this rule in your test case in order for the app to use mock dependencies.
* It also exposes some of the dependencies so they can be easily accessed from the tests, e.g. to
* stub mocks etc.
*/
public class TestComponentRule implements TestRule {
private final TestComponent mTestComponent;
private final Context mContext;
public TestComponentRule(Context context) {
mContext = context;
AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context);
mTestComponent = DaggerTestComponent.builder()
.applicationTestModule(new ApplicationTestModule(application))
.build();
}
public Context getContext() {
return mContext;
}
| public DataManager getMockDataManager() { |
hitherejoe/AndroidTvBoilerplate | app/src/main/java/com/hitherejoe/androidtvboilerplate/injection/component/ApplicationComponent.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/local/PreferencesHelper.java
// @Singleton
// public class PreferencesHelper {
//
// private final SharedPreferences mPref;
//
// public static final String PREF_FILE_NAME = "tv_boilerplate_pref_file";
// private static final String PREF_KEY_ACCESS_TOKEN = "PREF_KEY_ACCESS_TOKEN";
//
// @Inject
// public PreferencesHelper(@ApplicationContext Context context) {
// mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
// }
//
// public void clear() {
// mPref.edit().clear().apply();
// }
//
// public void putAccessToken(String accessToken) {
// mPref.edit().putString(PREF_KEY_ACCESS_TOKEN, accessToken).apply();
// }
//
// @Nullable
// public String getAccessToken() {
// return mPref.getString(PREF_KEY_ACCESS_TOKEN, null);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/injection/module/ApplicationModule.java
// @Module
// public class ApplicationModule {
// protected final Application mApplication;
//
// public ApplicationModule(Application application) {
// mApplication = application;
// }
//
// @Provides
// @ApplicationContext
// Context provideContext() {
// return mApplication;
// }
//
// @Provides
// @Singleton
// Application provideApplication() {
// return mApplication;
// }
//
// @Provides
// CompositeSubscription provideCompositeSubscription() {
// return new CompositeSubscription();
// }
//
// @Provides
// @Singleton
// AndroidTvBoilerplateService provideVineyardService() {
// return AndroidTvBoilerplateService.Creator.newVineyardService();
// }
// }
| import android.app.Application;
import android.content.Context;
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.local.PreferencesHelper;
import com.hitherejoe.androidtvboilerplate.injection.ApplicationContext;
import com.hitherejoe.androidtvboilerplate.injection.module.ApplicationModule;
import javax.inject.Singleton;
import dagger.Component;
import rx.subscriptions.CompositeSubscription; | package com.hitherejoe.androidtvboilerplate.injection.component;
@Singleton
@Component(modules = ApplicationModule.class)
public interface ApplicationComponent {
@ApplicationContext
Context context();
Application application(); | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/local/PreferencesHelper.java
// @Singleton
// public class PreferencesHelper {
//
// private final SharedPreferences mPref;
//
// public static final String PREF_FILE_NAME = "tv_boilerplate_pref_file";
// private static final String PREF_KEY_ACCESS_TOKEN = "PREF_KEY_ACCESS_TOKEN";
//
// @Inject
// public PreferencesHelper(@ApplicationContext Context context) {
// mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
// }
//
// public void clear() {
// mPref.edit().clear().apply();
// }
//
// public void putAccessToken(String accessToken) {
// mPref.edit().putString(PREF_KEY_ACCESS_TOKEN, accessToken).apply();
// }
//
// @Nullable
// public String getAccessToken() {
// return mPref.getString(PREF_KEY_ACCESS_TOKEN, null);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/injection/module/ApplicationModule.java
// @Module
// public class ApplicationModule {
// protected final Application mApplication;
//
// public ApplicationModule(Application application) {
// mApplication = application;
// }
//
// @Provides
// @ApplicationContext
// Context provideContext() {
// return mApplication;
// }
//
// @Provides
// @Singleton
// Application provideApplication() {
// return mApplication;
// }
//
// @Provides
// CompositeSubscription provideCompositeSubscription() {
// return new CompositeSubscription();
// }
//
// @Provides
// @Singleton
// AndroidTvBoilerplateService provideVineyardService() {
// return AndroidTvBoilerplateService.Creator.newVineyardService();
// }
// }
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/injection/component/ApplicationComponent.java
import android.app.Application;
import android.content.Context;
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.local.PreferencesHelper;
import com.hitherejoe.androidtvboilerplate.injection.ApplicationContext;
import com.hitherejoe.androidtvboilerplate.injection.module.ApplicationModule;
import javax.inject.Singleton;
import dagger.Component;
import rx.subscriptions.CompositeSubscription;
package com.hitherejoe.androidtvboilerplate.injection.component;
@Singleton
@Component(modules = ApplicationModule.class)
public interface ApplicationComponent {
@ApplicationContext
Context context();
Application application(); | PreferencesHelper preferencesHelper(); |
hitherejoe/AndroidTvBoilerplate | app/src/main/java/com/hitherejoe/androidtvboilerplate/injection/component/ApplicationComponent.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/local/PreferencesHelper.java
// @Singleton
// public class PreferencesHelper {
//
// private final SharedPreferences mPref;
//
// public static final String PREF_FILE_NAME = "tv_boilerplate_pref_file";
// private static final String PREF_KEY_ACCESS_TOKEN = "PREF_KEY_ACCESS_TOKEN";
//
// @Inject
// public PreferencesHelper(@ApplicationContext Context context) {
// mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
// }
//
// public void clear() {
// mPref.edit().clear().apply();
// }
//
// public void putAccessToken(String accessToken) {
// mPref.edit().putString(PREF_KEY_ACCESS_TOKEN, accessToken).apply();
// }
//
// @Nullable
// public String getAccessToken() {
// return mPref.getString(PREF_KEY_ACCESS_TOKEN, null);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/injection/module/ApplicationModule.java
// @Module
// public class ApplicationModule {
// protected final Application mApplication;
//
// public ApplicationModule(Application application) {
// mApplication = application;
// }
//
// @Provides
// @ApplicationContext
// Context provideContext() {
// return mApplication;
// }
//
// @Provides
// @Singleton
// Application provideApplication() {
// return mApplication;
// }
//
// @Provides
// CompositeSubscription provideCompositeSubscription() {
// return new CompositeSubscription();
// }
//
// @Provides
// @Singleton
// AndroidTvBoilerplateService provideVineyardService() {
// return AndroidTvBoilerplateService.Creator.newVineyardService();
// }
// }
| import android.app.Application;
import android.content.Context;
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.local.PreferencesHelper;
import com.hitherejoe.androidtvboilerplate.injection.ApplicationContext;
import com.hitherejoe.androidtvboilerplate.injection.module.ApplicationModule;
import javax.inject.Singleton;
import dagger.Component;
import rx.subscriptions.CompositeSubscription; | package com.hitherejoe.androidtvboilerplate.injection.component;
@Singleton
@Component(modules = ApplicationModule.class)
public interface ApplicationComponent {
@ApplicationContext
Context context();
Application application();
PreferencesHelper preferencesHelper(); | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/local/PreferencesHelper.java
// @Singleton
// public class PreferencesHelper {
//
// private final SharedPreferences mPref;
//
// public static final String PREF_FILE_NAME = "tv_boilerplate_pref_file";
// private static final String PREF_KEY_ACCESS_TOKEN = "PREF_KEY_ACCESS_TOKEN";
//
// @Inject
// public PreferencesHelper(@ApplicationContext Context context) {
// mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
// }
//
// public void clear() {
// mPref.edit().clear().apply();
// }
//
// public void putAccessToken(String accessToken) {
// mPref.edit().putString(PREF_KEY_ACCESS_TOKEN, accessToken).apply();
// }
//
// @Nullable
// public String getAccessToken() {
// return mPref.getString(PREF_KEY_ACCESS_TOKEN, null);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/injection/module/ApplicationModule.java
// @Module
// public class ApplicationModule {
// protected final Application mApplication;
//
// public ApplicationModule(Application application) {
// mApplication = application;
// }
//
// @Provides
// @ApplicationContext
// Context provideContext() {
// return mApplication;
// }
//
// @Provides
// @Singleton
// Application provideApplication() {
// return mApplication;
// }
//
// @Provides
// CompositeSubscription provideCompositeSubscription() {
// return new CompositeSubscription();
// }
//
// @Provides
// @Singleton
// AndroidTvBoilerplateService provideVineyardService() {
// return AndroidTvBoilerplateService.Creator.newVineyardService();
// }
// }
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/injection/component/ApplicationComponent.java
import android.app.Application;
import android.content.Context;
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.local.PreferencesHelper;
import com.hitherejoe.androidtvboilerplate.injection.ApplicationContext;
import com.hitherejoe.androidtvboilerplate.injection.module.ApplicationModule;
import javax.inject.Singleton;
import dagger.Component;
import rx.subscriptions.CompositeSubscription;
package com.hitherejoe.androidtvboilerplate.injection.component;
@Singleton
@Component(modules = ApplicationModule.class)
public interface ApplicationComponent {
@ApplicationContext
Context context();
Application application();
PreferencesHelper preferencesHelper(); | DataManager dataManager(); |
hitherejoe/AndroidTvBoilerplate | app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/content/ContentActivity.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/base/BaseActivity.java
// public class BaseActivity extends Activity {
//
// private ActivityComponent mActivityComponent;
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// }
//
// @Override
// public boolean onOptionsItemSelected(MenuItem item) {
// switch (item.getItemId()) {
// case android.R.id.home:
// finish();
// return true;
// default:
// return super.onOptionsItemSelected(item);
// }
// }
//
// public ActivityComponent activityComponent() {
// if (mActivityComponent == null) {
// mActivityComponent = DaggerActivityComponent.builder()
// .activityModule(new ActivityModule(this))
// .applicationComponent(AndroidTvBoilerplateApplication.get(this).getComponent())
// .build();
// }
// return mActivityComponent;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/search/SearchContentActivity.java
// public class SearchContentActivity extends BaseActivity {
//
// private SearchContentFragment mSearchContentFragment;
//
// public static Intent getStartIntent(Context context) {
// return new Intent(context, SearchContentActivity.class);
// }
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_search);
//
// mSearchContentFragment = (SearchContentFragment) getFragmentManager()
// .findFragmentById(R.id.search_fragment);
// }
//
// @Override
// public boolean onSearchRequested() {
// if (mSearchContentFragment.hasResults()) {
// startActivity(new Intent(this, SearchContentActivity.class));
// } else {
// mSearchContentFragment.startRecognition();
// }
// return true;
// }
//
// }
| import android.os.Bundle;
import android.widget.FrameLayout;
import com.hitherejoe.androidtvboilerplate.R;
import com.hitherejoe.androidtvboilerplate.ui.base.BaseActivity;
import com.hitherejoe.androidtvboilerplate.ui.search.SearchContentActivity;
import butterknife.Bind;
import butterknife.ButterKnife; | package com.hitherejoe.androidtvboilerplate.ui.content;
public class ContentActivity extends BaseActivity {
@Bind(R.id.frame_container) FrameLayout mFragmentContainer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
getFragmentManager().beginTransaction()
.replace(mFragmentContainer.getId(), ContentFragment.newInstance()).commit();
}
@Override
public boolean onSearchRequested() { | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/base/BaseActivity.java
// public class BaseActivity extends Activity {
//
// private ActivityComponent mActivityComponent;
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// }
//
// @Override
// public boolean onOptionsItemSelected(MenuItem item) {
// switch (item.getItemId()) {
// case android.R.id.home:
// finish();
// return true;
// default:
// return super.onOptionsItemSelected(item);
// }
// }
//
// public ActivityComponent activityComponent() {
// if (mActivityComponent == null) {
// mActivityComponent = DaggerActivityComponent.builder()
// .activityModule(new ActivityModule(this))
// .applicationComponent(AndroidTvBoilerplateApplication.get(this).getComponent())
// .build();
// }
// return mActivityComponent;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/search/SearchContentActivity.java
// public class SearchContentActivity extends BaseActivity {
//
// private SearchContentFragment mSearchContentFragment;
//
// public static Intent getStartIntent(Context context) {
// return new Intent(context, SearchContentActivity.class);
// }
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_search);
//
// mSearchContentFragment = (SearchContentFragment) getFragmentManager()
// .findFragmentById(R.id.search_fragment);
// }
//
// @Override
// public boolean onSearchRequested() {
// if (mSearchContentFragment.hasResults()) {
// startActivity(new Intent(this, SearchContentActivity.class));
// } else {
// mSearchContentFragment.startRecognition();
// }
// return true;
// }
//
// }
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/content/ContentActivity.java
import android.os.Bundle;
import android.widget.FrameLayout;
import com.hitherejoe.androidtvboilerplate.R;
import com.hitherejoe.androidtvboilerplate.ui.base.BaseActivity;
import com.hitherejoe.androidtvboilerplate.ui.search.SearchContentActivity;
import butterknife.Bind;
import butterknife.ButterKnife;
package com.hitherejoe.androidtvboilerplate.ui.content;
public class ContentActivity extends BaseActivity {
@Bind(R.id.frame_container) FrameLayout mFragmentContainer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
getFragmentManager().beginTransaction()
.replace(mFragmentContainer.getId(), ContentFragment.newInstance()).commit();
}
@Override
public boolean onSearchRequested() { | startActivity(SearchContentActivity.getStartIntent(this)); |
hitherejoe/AndroidTvBoilerplate | app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/injection/component/TestComponent.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/injection/component/ApplicationComponent.java
// @Singleton
// @Component(modules = ApplicationModule.class)
// public interface ApplicationComponent {
//
// @ApplicationContext
// Context context();
// Application application();
// PreferencesHelper preferencesHelper();
// DataManager dataManager();
// CompositeSubscription compositeSubscription();
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/injection/module/ApplicationTestModule.java
// @Module
// public class ApplicationTestModule {
//
// private final Application mApplication;
//
// public ApplicationTestModule(Application application) {
// mApplication = application;
// }
//
// @Provides
// Application provideApplication() {
// return mApplication;
// }
//
// @Provides
// @ApplicationContext
// Context provideContext() {
// return mApplication;
// }
//
// @Provides
// CompositeSubscription provideCompositeSubscription() {
// return new CompositeSubscription();
// }
//
// /************* MOCKS *************/
//
// @Provides
// @Singleton
// DataManager provideDataManager() {
// return mock(DataManager.class);
// }
//
// @Provides
// @Singleton
// PreferencesHelper providePreferencesHelper() {
// return mock(PreferencesHelper.class);
// }
//
// @Provides
// @Singleton
// AndroidTvBoilerplateService provideAndroidTvBoilerplateService() {
// return mock(AndroidTvBoilerplateService.class);
// }
//
// }
| import com.hitherejoe.androidtvboilerplate.injection.component.ApplicationComponent;
import com.hitherejoe.androidtvboilerplate.test.common.injection.module.ApplicationTestModule;
import javax.inject.Singleton;
import dagger.Component; | package com.hitherejoe.androidtvboilerplate.test.common.injection.component;
@Singleton
@Component(modules = ApplicationTestModule.class) | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/injection/component/ApplicationComponent.java
// @Singleton
// @Component(modules = ApplicationModule.class)
// public interface ApplicationComponent {
//
// @ApplicationContext
// Context context();
// Application application();
// PreferencesHelper preferencesHelper();
// DataManager dataManager();
// CompositeSubscription compositeSubscription();
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/injection/module/ApplicationTestModule.java
// @Module
// public class ApplicationTestModule {
//
// private final Application mApplication;
//
// public ApplicationTestModule(Application application) {
// mApplication = application;
// }
//
// @Provides
// Application provideApplication() {
// return mApplication;
// }
//
// @Provides
// @ApplicationContext
// Context provideContext() {
// return mApplication;
// }
//
// @Provides
// CompositeSubscription provideCompositeSubscription() {
// return new CompositeSubscription();
// }
//
// /************* MOCKS *************/
//
// @Provides
// @Singleton
// DataManager provideDataManager() {
// return mock(DataManager.class);
// }
//
// @Provides
// @Singleton
// PreferencesHelper providePreferencesHelper() {
// return mock(PreferencesHelper.class);
// }
//
// @Provides
// @Singleton
// AndroidTvBoilerplateService provideAndroidTvBoilerplateService() {
// return mock(AndroidTvBoilerplateService.class);
// }
//
// }
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/injection/component/TestComponent.java
import com.hitherejoe.androidtvboilerplate.injection.component.ApplicationComponent;
import com.hitherejoe.androidtvboilerplate.test.common.injection.module.ApplicationTestModule;
import javax.inject.Singleton;
import dagger.Component;
package com.hitherejoe.androidtvboilerplate.test.common.injection.component;
@Singleton
@Component(modules = ApplicationTestModule.class) | public interface TestComponent extends ApplicationComponent { |
hitherejoe/AndroidTvBoilerplate | app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/content/ContentPresenter.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/base/BasePresenter.java
// public class BasePresenter<T extends MvpView> implements Presenter<T> {
//
// private T mMvpView;
//
// @Override
// public void attachView(T mvpView) {
// mMvpView = mvpView;
// }
//
// @Override
// public void detachView() {
// mMvpView = null;
// }
//
// public boolean isViewAttached() {
// return mMvpView != null;
// }
//
// public T getMvpView() {
// return mMvpView;
// }
//
// public void checkViewAttached() {
// if (!isViewAttached()) throw new MvpViewNotAttachedException();
// }
//
// public static class MvpViewNotAttachedException extends RuntimeException {
// public MvpViewNotAttachedException() {
// super("Please call Presenter.attachView(MvpView) before" +
// " requesting data to the Presenter");
// }
// }
// }
| import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.ui.base.BasePresenter;
import java.util.List;
import javax.inject.Inject;
import rx.SingleSubscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import timber.log.Timber; | package com.hitherejoe.androidtvboilerplate.ui.content;
public class ContentPresenter extends BasePresenter<ContentMvpView> {
private Subscription mSubscription; | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/base/BasePresenter.java
// public class BasePresenter<T extends MvpView> implements Presenter<T> {
//
// private T mMvpView;
//
// @Override
// public void attachView(T mvpView) {
// mMvpView = mvpView;
// }
//
// @Override
// public void detachView() {
// mMvpView = null;
// }
//
// public boolean isViewAttached() {
// return mMvpView != null;
// }
//
// public T getMvpView() {
// return mMvpView;
// }
//
// public void checkViewAttached() {
// if (!isViewAttached()) throw new MvpViewNotAttachedException();
// }
//
// public static class MvpViewNotAttachedException extends RuntimeException {
// public MvpViewNotAttachedException() {
// super("Please call Presenter.attachView(MvpView) before" +
// " requesting data to the Presenter");
// }
// }
// }
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/content/ContentPresenter.java
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.ui.base.BasePresenter;
import java.util.List;
import javax.inject.Inject;
import rx.SingleSubscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import timber.log.Timber;
package com.hitherejoe.androidtvboilerplate.ui.content;
public class ContentPresenter extends BasePresenter<ContentMvpView> {
private Subscription mSubscription; | private final DataManager mDataManager; |
hitherejoe/AndroidTvBoilerplate | app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/content/ContentPresenter.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/base/BasePresenter.java
// public class BasePresenter<T extends MvpView> implements Presenter<T> {
//
// private T mMvpView;
//
// @Override
// public void attachView(T mvpView) {
// mMvpView = mvpView;
// }
//
// @Override
// public void detachView() {
// mMvpView = null;
// }
//
// public boolean isViewAttached() {
// return mMvpView != null;
// }
//
// public T getMvpView() {
// return mMvpView;
// }
//
// public void checkViewAttached() {
// if (!isViewAttached()) throw new MvpViewNotAttachedException();
// }
//
// public static class MvpViewNotAttachedException extends RuntimeException {
// public MvpViewNotAttachedException() {
// super("Please call Presenter.attachView(MvpView) before" +
// " requesting data to the Presenter");
// }
// }
// }
| import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.ui.base.BasePresenter;
import java.util.List;
import javax.inject.Inject;
import rx.SingleSubscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import timber.log.Timber; | package com.hitherejoe.androidtvboilerplate.ui.content;
public class ContentPresenter extends BasePresenter<ContentMvpView> {
private Subscription mSubscription;
private final DataManager mDataManager;
@Inject
public ContentPresenter(DataManager dataManager) {
mDataManager = dataManager;
}
@Override
public void detachView() {
super.detachView();
if (mSubscription != null) mSubscription.unsubscribe();
}
| // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/base/BasePresenter.java
// public class BasePresenter<T extends MvpView> implements Presenter<T> {
//
// private T mMvpView;
//
// @Override
// public void attachView(T mvpView) {
// mMvpView = mvpView;
// }
//
// @Override
// public void detachView() {
// mMvpView = null;
// }
//
// public boolean isViewAttached() {
// return mMvpView != null;
// }
//
// public T getMvpView() {
// return mMvpView;
// }
//
// public void checkViewAttached() {
// if (!isViewAttached()) throw new MvpViewNotAttachedException();
// }
//
// public static class MvpViewNotAttachedException extends RuntimeException {
// public MvpViewNotAttachedException() {
// super("Please call Presenter.attachView(MvpView) before" +
// " requesting data to the Presenter");
// }
// }
// }
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/content/ContentPresenter.java
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.ui.base.BasePresenter;
import java.util.List;
import javax.inject.Inject;
import rx.SingleSubscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import timber.log.Timber;
package com.hitherejoe.androidtvboilerplate.ui.content;
public class ContentPresenter extends BasePresenter<ContentMvpView> {
private Subscription mSubscription;
private final DataManager mDataManager;
@Inject
public ContentPresenter(DataManager dataManager) {
mDataManager = dataManager;
}
@Override
public void detachView() {
super.detachView();
if (mSubscription != null) mSubscription.unsubscribe();
}
| public void getCats(List<Cat> cats) { |
hitherejoe/AndroidTvBoilerplate | app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/SearchContentActivityTest.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java
// public class TestComponentRule implements TestRule {
//
// private final TestComponent mTestComponent;
// private final Context mContext;
//
// public TestComponentRule(Context context) {
// mContext = context;
// AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context);
// mTestComponent = DaggerTestComponent.builder()
// .applicationTestModule(new ApplicationTestModule(application))
// .build();
// }
//
// public Context getContext() {
// return mContext;
// }
//
// public DataManager getMockDataManager() {
// return mTestComponent.dataManager();
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// AndroidTvBoilerplateApplication application =
// AndroidTvBoilerplateApplication.get(mContext);
// application.setComponent(mTestComponent);
// base.evaluate();
// application.setComponent(null);
// }
// };
// }
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/search/SearchContentActivity.java
// public class SearchContentActivity extends BaseActivity {
//
// private SearchContentFragment mSearchContentFragment;
//
// public static Intent getStartIntent(Context context) {
// return new Intent(context, SearchContentActivity.class);
// }
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_search);
//
// mSearchContentFragment = (SearchContentFragment) getFragmentManager()
// .findFragmentById(R.id.search_fragment);
// }
//
// @Override
// public boolean onSearchRequested() {
// if (mSearchContentFragment.hasResults()) {
// startActivity(new Intent(this, SearchContentActivity.class));
// } else {
// mSearchContentFragment.startRecognition();
// }
// return true;
// }
//
// }
//
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/util/CustomMatchers.java
// public static Matcher<View> withItemText(final String itemText, final int parentId) {
// checkArgument(!TextUtils.isEmpty(itemText), "itemText cannot be null or empty");
// return new TypeSafeMatcher<View>() {
// @Override
// public boolean matchesSafely(View item) {
// return allOf(isDescendantOfA(withId(parentId)),
// withText(itemText)).matches(item);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("is isDescendantOfA RecyclerView with text " + itemText);
// }
// };
// }
| import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.test.common.rules.TestComponentRule;
import com.hitherejoe.androidtvboilerplate.ui.search.SearchContentActivity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import java.util.List;
import rx.Single;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.hitherejoe.androidtvboilerplate.util.CustomMatchers.withItemText;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.when; | package com.hitherejoe.androidtvboilerplate;
@RunWith(AndroidJUnit4.class)
public class SearchContentActivityTest {
| // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java
// public class TestComponentRule implements TestRule {
//
// private final TestComponent mTestComponent;
// private final Context mContext;
//
// public TestComponentRule(Context context) {
// mContext = context;
// AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context);
// mTestComponent = DaggerTestComponent.builder()
// .applicationTestModule(new ApplicationTestModule(application))
// .build();
// }
//
// public Context getContext() {
// return mContext;
// }
//
// public DataManager getMockDataManager() {
// return mTestComponent.dataManager();
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// AndroidTvBoilerplateApplication application =
// AndroidTvBoilerplateApplication.get(mContext);
// application.setComponent(mTestComponent);
// base.evaluate();
// application.setComponent(null);
// }
// };
// }
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/search/SearchContentActivity.java
// public class SearchContentActivity extends BaseActivity {
//
// private SearchContentFragment mSearchContentFragment;
//
// public static Intent getStartIntent(Context context) {
// return new Intent(context, SearchContentActivity.class);
// }
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_search);
//
// mSearchContentFragment = (SearchContentFragment) getFragmentManager()
// .findFragmentById(R.id.search_fragment);
// }
//
// @Override
// public boolean onSearchRequested() {
// if (mSearchContentFragment.hasResults()) {
// startActivity(new Intent(this, SearchContentActivity.class));
// } else {
// mSearchContentFragment.startRecognition();
// }
// return true;
// }
//
// }
//
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/util/CustomMatchers.java
// public static Matcher<View> withItemText(final String itemText, final int parentId) {
// checkArgument(!TextUtils.isEmpty(itemText), "itemText cannot be null or empty");
// return new TypeSafeMatcher<View>() {
// @Override
// public boolean matchesSafely(View item) {
// return allOf(isDescendantOfA(withId(parentId)),
// withText(itemText)).matches(item);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("is isDescendantOfA RecyclerView with text " + itemText);
// }
// };
// }
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/SearchContentActivityTest.java
import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.test.common.rules.TestComponentRule;
import com.hitherejoe.androidtvboilerplate.ui.search.SearchContentActivity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import java.util.List;
import rx.Single;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.hitherejoe.androidtvboilerplate.util.CustomMatchers.withItemText;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.when;
package com.hitherejoe.androidtvboilerplate;
@RunWith(AndroidJUnit4.class)
public class SearchContentActivityTest {
| public final TestComponentRule component = |
hitherejoe/AndroidTvBoilerplate | app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/SearchContentActivityTest.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java
// public class TestComponentRule implements TestRule {
//
// private final TestComponent mTestComponent;
// private final Context mContext;
//
// public TestComponentRule(Context context) {
// mContext = context;
// AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context);
// mTestComponent = DaggerTestComponent.builder()
// .applicationTestModule(new ApplicationTestModule(application))
// .build();
// }
//
// public Context getContext() {
// return mContext;
// }
//
// public DataManager getMockDataManager() {
// return mTestComponent.dataManager();
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// AndroidTvBoilerplateApplication application =
// AndroidTvBoilerplateApplication.get(mContext);
// application.setComponent(mTestComponent);
// base.evaluate();
// application.setComponent(null);
// }
// };
// }
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/search/SearchContentActivity.java
// public class SearchContentActivity extends BaseActivity {
//
// private SearchContentFragment mSearchContentFragment;
//
// public static Intent getStartIntent(Context context) {
// return new Intent(context, SearchContentActivity.class);
// }
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_search);
//
// mSearchContentFragment = (SearchContentFragment) getFragmentManager()
// .findFragmentById(R.id.search_fragment);
// }
//
// @Override
// public boolean onSearchRequested() {
// if (mSearchContentFragment.hasResults()) {
// startActivity(new Intent(this, SearchContentActivity.class));
// } else {
// mSearchContentFragment.startRecognition();
// }
// return true;
// }
//
// }
//
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/util/CustomMatchers.java
// public static Matcher<View> withItemText(final String itemText, final int parentId) {
// checkArgument(!TextUtils.isEmpty(itemText), "itemText cannot be null or empty");
// return new TypeSafeMatcher<View>() {
// @Override
// public boolean matchesSafely(View item) {
// return allOf(isDescendantOfA(withId(parentId)),
// withText(itemText)).matches(item);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("is isDescendantOfA RecyclerView with text " + itemText);
// }
// };
// }
| import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.test.common.rules.TestComponentRule;
import com.hitherejoe.androidtvboilerplate.ui.search.SearchContentActivity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import java.util.List;
import rx.Single;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.hitherejoe.androidtvboilerplate.util.CustomMatchers.withItemText;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.when; | package com.hitherejoe.androidtvboilerplate;
@RunWith(AndroidJUnit4.class)
public class SearchContentActivityTest {
public final TestComponentRule component =
new TestComponentRule(InstrumentationRegistry.getTargetContext()); | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java
// public class TestComponentRule implements TestRule {
//
// private final TestComponent mTestComponent;
// private final Context mContext;
//
// public TestComponentRule(Context context) {
// mContext = context;
// AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context);
// mTestComponent = DaggerTestComponent.builder()
// .applicationTestModule(new ApplicationTestModule(application))
// .build();
// }
//
// public Context getContext() {
// return mContext;
// }
//
// public DataManager getMockDataManager() {
// return mTestComponent.dataManager();
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// AndroidTvBoilerplateApplication application =
// AndroidTvBoilerplateApplication.get(mContext);
// application.setComponent(mTestComponent);
// base.evaluate();
// application.setComponent(null);
// }
// };
// }
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/search/SearchContentActivity.java
// public class SearchContentActivity extends BaseActivity {
//
// private SearchContentFragment mSearchContentFragment;
//
// public static Intent getStartIntent(Context context) {
// return new Intent(context, SearchContentActivity.class);
// }
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_search);
//
// mSearchContentFragment = (SearchContentFragment) getFragmentManager()
// .findFragmentById(R.id.search_fragment);
// }
//
// @Override
// public boolean onSearchRequested() {
// if (mSearchContentFragment.hasResults()) {
// startActivity(new Intent(this, SearchContentActivity.class));
// } else {
// mSearchContentFragment.startRecognition();
// }
// return true;
// }
//
// }
//
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/util/CustomMatchers.java
// public static Matcher<View> withItemText(final String itemText, final int parentId) {
// checkArgument(!TextUtils.isEmpty(itemText), "itemText cannot be null or empty");
// return new TypeSafeMatcher<View>() {
// @Override
// public boolean matchesSafely(View item) {
// return allOf(isDescendantOfA(withId(parentId)),
// withText(itemText)).matches(item);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("is isDescendantOfA RecyclerView with text " + itemText);
// }
// };
// }
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/SearchContentActivityTest.java
import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.test.common.rules.TestComponentRule;
import com.hitherejoe.androidtvboilerplate.ui.search.SearchContentActivity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import java.util.List;
import rx.Single;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.hitherejoe.androidtvboilerplate.util.CustomMatchers.withItemText;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.when;
package com.hitherejoe.androidtvboilerplate;
@RunWith(AndroidJUnit4.class)
public class SearchContentActivityTest {
public final TestComponentRule component =
new TestComponentRule(InstrumentationRegistry.getTargetContext()); | public final ActivityTestRule<SearchContentActivity> main = |
hitherejoe/AndroidTvBoilerplate | app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/SearchContentActivityTest.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java
// public class TestComponentRule implements TestRule {
//
// private final TestComponent mTestComponent;
// private final Context mContext;
//
// public TestComponentRule(Context context) {
// mContext = context;
// AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context);
// mTestComponent = DaggerTestComponent.builder()
// .applicationTestModule(new ApplicationTestModule(application))
// .build();
// }
//
// public Context getContext() {
// return mContext;
// }
//
// public DataManager getMockDataManager() {
// return mTestComponent.dataManager();
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// AndroidTvBoilerplateApplication application =
// AndroidTvBoilerplateApplication.get(mContext);
// application.setComponent(mTestComponent);
// base.evaluate();
// application.setComponent(null);
// }
// };
// }
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/search/SearchContentActivity.java
// public class SearchContentActivity extends BaseActivity {
//
// private SearchContentFragment mSearchContentFragment;
//
// public static Intent getStartIntent(Context context) {
// return new Intent(context, SearchContentActivity.class);
// }
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_search);
//
// mSearchContentFragment = (SearchContentFragment) getFragmentManager()
// .findFragmentById(R.id.search_fragment);
// }
//
// @Override
// public boolean onSearchRequested() {
// if (mSearchContentFragment.hasResults()) {
// startActivity(new Intent(this, SearchContentActivity.class));
// } else {
// mSearchContentFragment.startRecognition();
// }
// return true;
// }
//
// }
//
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/util/CustomMatchers.java
// public static Matcher<View> withItemText(final String itemText, final int parentId) {
// checkArgument(!TextUtils.isEmpty(itemText), "itemText cannot be null or empty");
// return new TypeSafeMatcher<View>() {
// @Override
// public boolean matchesSafely(View item) {
// return allOf(isDescendantOfA(withId(parentId)),
// withText(itemText)).matches(item);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("is isDescendantOfA RecyclerView with text " + itemText);
// }
// };
// }
| import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.test.common.rules.TestComponentRule;
import com.hitherejoe.androidtvboilerplate.ui.search.SearchContentActivity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import java.util.List;
import rx.Single;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.hitherejoe.androidtvboilerplate.util.CustomMatchers.withItemText;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.when; | package com.hitherejoe.androidtvboilerplate;
@RunWith(AndroidJUnit4.class)
public class SearchContentActivityTest {
public final TestComponentRule component =
new TestComponentRule(InstrumentationRegistry.getTargetContext());
public final ActivityTestRule<SearchContentActivity> main =
new ActivityTestRule<>(SearchContentActivity.class, false, false);
@Rule
public final TestRule chain = RuleChain.outerRule(component).around(main);
@Test
public void searchResultsDisplayAndAreScrollable() {
main.launchActivity(null);
| // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java
// public class TestComponentRule implements TestRule {
//
// private final TestComponent mTestComponent;
// private final Context mContext;
//
// public TestComponentRule(Context context) {
// mContext = context;
// AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context);
// mTestComponent = DaggerTestComponent.builder()
// .applicationTestModule(new ApplicationTestModule(application))
// .build();
// }
//
// public Context getContext() {
// return mContext;
// }
//
// public DataManager getMockDataManager() {
// return mTestComponent.dataManager();
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// AndroidTvBoilerplateApplication application =
// AndroidTvBoilerplateApplication.get(mContext);
// application.setComponent(mTestComponent);
// base.evaluate();
// application.setComponent(null);
// }
// };
// }
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/search/SearchContentActivity.java
// public class SearchContentActivity extends BaseActivity {
//
// private SearchContentFragment mSearchContentFragment;
//
// public static Intent getStartIntent(Context context) {
// return new Intent(context, SearchContentActivity.class);
// }
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_search);
//
// mSearchContentFragment = (SearchContentFragment) getFragmentManager()
// .findFragmentById(R.id.search_fragment);
// }
//
// @Override
// public boolean onSearchRequested() {
// if (mSearchContentFragment.hasResults()) {
// startActivity(new Intent(this, SearchContentActivity.class));
// } else {
// mSearchContentFragment.startRecognition();
// }
// return true;
// }
//
// }
//
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/util/CustomMatchers.java
// public static Matcher<View> withItemText(final String itemText, final int parentId) {
// checkArgument(!TextUtils.isEmpty(itemText), "itemText cannot be null or empty");
// return new TypeSafeMatcher<View>() {
// @Override
// public boolean matchesSafely(View item) {
// return allOf(isDescendantOfA(withId(parentId)),
// withText(itemText)).matches(item);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("is isDescendantOfA RecyclerView with text " + itemText);
// }
// };
// }
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/SearchContentActivityTest.java
import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.test.common.rules.TestComponentRule;
import com.hitherejoe.androidtvboilerplate.ui.search.SearchContentActivity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import java.util.List;
import rx.Single;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.hitherejoe.androidtvboilerplate.util.CustomMatchers.withItemText;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.when;
package com.hitherejoe.androidtvboilerplate;
@RunWith(AndroidJUnit4.class)
public class SearchContentActivityTest {
public final TestComponentRule component =
new TestComponentRule(InstrumentationRegistry.getTargetContext());
public final ActivityTestRule<SearchContentActivity> main =
new ActivityTestRule<>(SearchContentActivity.class, false, false);
@Rule
public final TestRule chain = RuleChain.outerRule(component).around(main);
@Test
public void searchResultsDisplayAndAreScrollable() {
main.launchActivity(null);
| List<Cat> mockCats = TestDataFactory.makeCats(5); |
hitherejoe/AndroidTvBoilerplate | app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/SearchContentActivityTest.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java
// public class TestComponentRule implements TestRule {
//
// private final TestComponent mTestComponent;
// private final Context mContext;
//
// public TestComponentRule(Context context) {
// mContext = context;
// AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context);
// mTestComponent = DaggerTestComponent.builder()
// .applicationTestModule(new ApplicationTestModule(application))
// .build();
// }
//
// public Context getContext() {
// return mContext;
// }
//
// public DataManager getMockDataManager() {
// return mTestComponent.dataManager();
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// AndroidTvBoilerplateApplication application =
// AndroidTvBoilerplateApplication.get(mContext);
// application.setComponent(mTestComponent);
// base.evaluate();
// application.setComponent(null);
// }
// };
// }
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/search/SearchContentActivity.java
// public class SearchContentActivity extends BaseActivity {
//
// private SearchContentFragment mSearchContentFragment;
//
// public static Intent getStartIntent(Context context) {
// return new Intent(context, SearchContentActivity.class);
// }
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_search);
//
// mSearchContentFragment = (SearchContentFragment) getFragmentManager()
// .findFragmentById(R.id.search_fragment);
// }
//
// @Override
// public boolean onSearchRequested() {
// if (mSearchContentFragment.hasResults()) {
// startActivity(new Intent(this, SearchContentActivity.class));
// } else {
// mSearchContentFragment.startRecognition();
// }
// return true;
// }
//
// }
//
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/util/CustomMatchers.java
// public static Matcher<View> withItemText(final String itemText, final int parentId) {
// checkArgument(!TextUtils.isEmpty(itemText), "itemText cannot be null or empty");
// return new TypeSafeMatcher<View>() {
// @Override
// public boolean matchesSafely(View item) {
// return allOf(isDescendantOfA(withId(parentId)),
// withText(itemText)).matches(item);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("is isDescendantOfA RecyclerView with text " + itemText);
// }
// };
// }
| import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.test.common.rules.TestComponentRule;
import com.hitherejoe.androidtvboilerplate.ui.search.SearchContentActivity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import java.util.List;
import rx.Single;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.hitherejoe.androidtvboilerplate.util.CustomMatchers.withItemText;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.when; | package com.hitherejoe.androidtvboilerplate;
@RunWith(AndroidJUnit4.class)
public class SearchContentActivityTest {
public final TestComponentRule component =
new TestComponentRule(InstrumentationRegistry.getTargetContext());
public final ActivityTestRule<SearchContentActivity> main =
new ActivityTestRule<>(SearchContentActivity.class, false, false);
@Rule
public final TestRule chain = RuleChain.outerRule(component).around(main);
@Test
public void searchResultsDisplayAndAreScrollable() {
main.launchActivity(null);
| // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java
// public class TestComponentRule implements TestRule {
//
// private final TestComponent mTestComponent;
// private final Context mContext;
//
// public TestComponentRule(Context context) {
// mContext = context;
// AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context);
// mTestComponent = DaggerTestComponent.builder()
// .applicationTestModule(new ApplicationTestModule(application))
// .build();
// }
//
// public Context getContext() {
// return mContext;
// }
//
// public DataManager getMockDataManager() {
// return mTestComponent.dataManager();
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// AndroidTvBoilerplateApplication application =
// AndroidTvBoilerplateApplication.get(mContext);
// application.setComponent(mTestComponent);
// base.evaluate();
// application.setComponent(null);
// }
// };
// }
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/search/SearchContentActivity.java
// public class SearchContentActivity extends BaseActivity {
//
// private SearchContentFragment mSearchContentFragment;
//
// public static Intent getStartIntent(Context context) {
// return new Intent(context, SearchContentActivity.class);
// }
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_search);
//
// mSearchContentFragment = (SearchContentFragment) getFragmentManager()
// .findFragmentById(R.id.search_fragment);
// }
//
// @Override
// public boolean onSearchRequested() {
// if (mSearchContentFragment.hasResults()) {
// startActivity(new Intent(this, SearchContentActivity.class));
// } else {
// mSearchContentFragment.startRecognition();
// }
// return true;
// }
//
// }
//
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/util/CustomMatchers.java
// public static Matcher<View> withItemText(final String itemText, final int parentId) {
// checkArgument(!TextUtils.isEmpty(itemText), "itemText cannot be null or empty");
// return new TypeSafeMatcher<View>() {
// @Override
// public boolean matchesSafely(View item) {
// return allOf(isDescendantOfA(withId(parentId)),
// withText(itemText)).matches(item);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("is isDescendantOfA RecyclerView with text " + itemText);
// }
// };
// }
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/SearchContentActivityTest.java
import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.test.common.rules.TestComponentRule;
import com.hitherejoe.androidtvboilerplate.ui.search.SearchContentActivity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import java.util.List;
import rx.Single;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.hitherejoe.androidtvboilerplate.util.CustomMatchers.withItemText;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.when;
package com.hitherejoe.androidtvboilerplate;
@RunWith(AndroidJUnit4.class)
public class SearchContentActivityTest {
public final TestComponentRule component =
new TestComponentRule(InstrumentationRegistry.getTargetContext());
public final ActivityTestRule<SearchContentActivity> main =
new ActivityTestRule<>(SearchContentActivity.class, false, false);
@Rule
public final TestRule chain = RuleChain.outerRule(component).around(main);
@Test
public void searchResultsDisplayAndAreScrollable() {
main.launchActivity(null);
| List<Cat> mockCats = TestDataFactory.makeCats(5); |
hitherejoe/AndroidTvBoilerplate | app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/SearchContentActivityTest.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java
// public class TestComponentRule implements TestRule {
//
// private final TestComponent mTestComponent;
// private final Context mContext;
//
// public TestComponentRule(Context context) {
// mContext = context;
// AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context);
// mTestComponent = DaggerTestComponent.builder()
// .applicationTestModule(new ApplicationTestModule(application))
// .build();
// }
//
// public Context getContext() {
// return mContext;
// }
//
// public DataManager getMockDataManager() {
// return mTestComponent.dataManager();
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// AndroidTvBoilerplateApplication application =
// AndroidTvBoilerplateApplication.get(mContext);
// application.setComponent(mTestComponent);
// base.evaluate();
// application.setComponent(null);
// }
// };
// }
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/search/SearchContentActivity.java
// public class SearchContentActivity extends BaseActivity {
//
// private SearchContentFragment mSearchContentFragment;
//
// public static Intent getStartIntent(Context context) {
// return new Intent(context, SearchContentActivity.class);
// }
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_search);
//
// mSearchContentFragment = (SearchContentFragment) getFragmentManager()
// .findFragmentById(R.id.search_fragment);
// }
//
// @Override
// public boolean onSearchRequested() {
// if (mSearchContentFragment.hasResults()) {
// startActivity(new Intent(this, SearchContentActivity.class));
// } else {
// mSearchContentFragment.startRecognition();
// }
// return true;
// }
//
// }
//
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/util/CustomMatchers.java
// public static Matcher<View> withItemText(final String itemText, final int parentId) {
// checkArgument(!TextUtils.isEmpty(itemText), "itemText cannot be null or empty");
// return new TypeSafeMatcher<View>() {
// @Override
// public boolean matchesSafely(View item) {
// return allOf(isDescendantOfA(withId(parentId)),
// withText(itemText)).matches(item);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("is isDescendantOfA RecyclerView with text " + itemText);
// }
// };
// }
| import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.test.common.rules.TestComponentRule;
import com.hitherejoe.androidtvboilerplate.ui.search.SearchContentActivity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import java.util.List;
import rx.Single;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.hitherejoe.androidtvboilerplate.util.CustomMatchers.withItemText;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.when; | package com.hitherejoe.androidtvboilerplate;
@RunWith(AndroidJUnit4.class)
public class SearchContentActivityTest {
public final TestComponentRule component =
new TestComponentRule(InstrumentationRegistry.getTargetContext());
public final ActivityTestRule<SearchContentActivity> main =
new ActivityTestRule<>(SearchContentActivity.class, false, false);
@Rule
public final TestRule chain = RuleChain.outerRule(component).around(main);
@Test
public void searchResultsDisplayAndAreScrollable() {
main.launchActivity(null);
List<Cat> mockCats = TestDataFactory.makeCats(5);
stubDataManagerGetCats(Single.just(mockCats));
onView(withId(R.id.lb_search_text_editor))
.perform(replaceText("cat"));
for (int i = 0; i < mockCats.size(); i++) {
checkItemAtPosition(mockCats.get(i));
}
}
private void checkItemAtPosition(Cat cat) { | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java
// public class TestComponentRule implements TestRule {
//
// private final TestComponent mTestComponent;
// private final Context mContext;
//
// public TestComponentRule(Context context) {
// mContext = context;
// AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context);
// mTestComponent = DaggerTestComponent.builder()
// .applicationTestModule(new ApplicationTestModule(application))
// .build();
// }
//
// public Context getContext() {
// return mContext;
// }
//
// public DataManager getMockDataManager() {
// return mTestComponent.dataManager();
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// AndroidTvBoilerplateApplication application =
// AndroidTvBoilerplateApplication.get(mContext);
// application.setComponent(mTestComponent);
// base.evaluate();
// application.setComponent(null);
// }
// };
// }
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/search/SearchContentActivity.java
// public class SearchContentActivity extends BaseActivity {
//
// private SearchContentFragment mSearchContentFragment;
//
// public static Intent getStartIntent(Context context) {
// return new Intent(context, SearchContentActivity.class);
// }
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_search);
//
// mSearchContentFragment = (SearchContentFragment) getFragmentManager()
// .findFragmentById(R.id.search_fragment);
// }
//
// @Override
// public boolean onSearchRequested() {
// if (mSearchContentFragment.hasResults()) {
// startActivity(new Intent(this, SearchContentActivity.class));
// } else {
// mSearchContentFragment.startRecognition();
// }
// return true;
// }
//
// }
//
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/util/CustomMatchers.java
// public static Matcher<View> withItemText(final String itemText, final int parentId) {
// checkArgument(!TextUtils.isEmpty(itemText), "itemText cannot be null or empty");
// return new TypeSafeMatcher<View>() {
// @Override
// public boolean matchesSafely(View item) {
// return allOf(isDescendantOfA(withId(parentId)),
// withText(itemText)).matches(item);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("is isDescendantOfA RecyclerView with text " + itemText);
// }
// };
// }
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/SearchContentActivityTest.java
import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.test.common.rules.TestComponentRule;
import com.hitherejoe.androidtvboilerplate.ui.search.SearchContentActivity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import java.util.List;
import rx.Single;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.hitherejoe.androidtvboilerplate.util.CustomMatchers.withItemText;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.when;
package com.hitherejoe.androidtvboilerplate;
@RunWith(AndroidJUnit4.class)
public class SearchContentActivityTest {
public final TestComponentRule component =
new TestComponentRule(InstrumentationRegistry.getTargetContext());
public final ActivityTestRule<SearchContentActivity> main =
new ActivityTestRule<>(SearchContentActivity.class, false, false);
@Rule
public final TestRule chain = RuleChain.outerRule(component).around(main);
@Test
public void searchResultsDisplayAndAreScrollable() {
main.launchActivity(null);
List<Cat> mockCats = TestDataFactory.makeCats(5);
stubDataManagerGetCats(Single.just(mockCats));
onView(withId(R.id.lb_search_text_editor))
.perform(replaceText("cat"));
for (int i = 0; i < mockCats.size(); i++) {
checkItemAtPosition(mockCats.get(i));
}
}
private void checkItemAtPosition(Cat cat) { | onView(withItemText(cat.name, R.id.lb_results_frame)).perform(click()); |
hitherejoe/AndroidTvBoilerplate | app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
| import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID; | package com.hitherejoe.androidtvboilerplate.test.common;
public class TestDataFactory {
public static String generateRandomString() {
return UUID.randomUUID().toString().substring(0, 5);
}
| // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
package com.hitherejoe.androidtvboilerplate.test.common;
public class TestDataFactory {
public static String generateRandomString() {
return UUID.randomUUID().toString().substring(0, 5);
}
| public static Cat makeCat(String unique) { |
hitherejoe/AndroidTvBoilerplate | app/src/test/java/com/hitherejoe/androidtvboilerplate/data/DataManagerTest.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/local/PreferencesHelper.java
// @Singleton
// public class PreferencesHelper {
//
// private final SharedPreferences mPref;
//
// public static final String PREF_FILE_NAME = "tv_boilerplate_pref_file";
// private static final String PREF_KEY_ACCESS_TOKEN = "PREF_KEY_ACCESS_TOKEN";
//
// @Inject
// public PreferencesHelper(@ApplicationContext Context context) {
// mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
// }
//
// public void clear() {
// mPref.edit().clear().apply();
// }
//
// public void putAccessToken(String accessToken) {
// mPref.edit().putString(PREF_KEY_ACCESS_TOKEN, accessToken).apply();
// }
//
// @Nullable
// public String getAccessToken() {
// return mPref.getString(PREF_KEY_ACCESS_TOKEN, null);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/remote/AndroidTvBoilerplateService.java
// public interface AndroidTvBoilerplateService {
//
// String ENDPOINT = "https://your.endpoint.com/";
//
// /********
// * Helper class that sets up a new services
// *******/
// class Creator {
// public static AndroidTvBoilerplateService newVineyardService() {
// OkHttpClient client = new OkHttpClient();
// client.interceptors().add(new Interceptor() {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Response response = chain.proceed(chain.request());
// // Catch unauthorised error
// return response;
// }
// });
//
// HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
// interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// client.interceptors().add(interceptor);
//
// Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(AndroidTvBoilerplateService.ENDPOINT)
// .client(client)
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .build();
// return retrofit.create(AndroidTvBoilerplateService.class);
// }
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
| import com.hitherejoe.androidtvboilerplate.data.local.PreferencesHelper;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.data.remote.AndroidTvBoilerplateService;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.List;
import rx.observers.TestSubscriber; | package com.hitherejoe.androidtvboilerplate.data;
@RunWith(MockitoJUnitRunner.class)
public class DataManagerTest {
| // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/local/PreferencesHelper.java
// @Singleton
// public class PreferencesHelper {
//
// private final SharedPreferences mPref;
//
// public static final String PREF_FILE_NAME = "tv_boilerplate_pref_file";
// private static final String PREF_KEY_ACCESS_TOKEN = "PREF_KEY_ACCESS_TOKEN";
//
// @Inject
// public PreferencesHelper(@ApplicationContext Context context) {
// mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
// }
//
// public void clear() {
// mPref.edit().clear().apply();
// }
//
// public void putAccessToken(String accessToken) {
// mPref.edit().putString(PREF_KEY_ACCESS_TOKEN, accessToken).apply();
// }
//
// @Nullable
// public String getAccessToken() {
// return mPref.getString(PREF_KEY_ACCESS_TOKEN, null);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/remote/AndroidTvBoilerplateService.java
// public interface AndroidTvBoilerplateService {
//
// String ENDPOINT = "https://your.endpoint.com/";
//
// /********
// * Helper class that sets up a new services
// *******/
// class Creator {
// public static AndroidTvBoilerplateService newVineyardService() {
// OkHttpClient client = new OkHttpClient();
// client.interceptors().add(new Interceptor() {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Response response = chain.proceed(chain.request());
// // Catch unauthorised error
// return response;
// }
// });
//
// HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
// interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// client.interceptors().add(interceptor);
//
// Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(AndroidTvBoilerplateService.ENDPOINT)
// .client(client)
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .build();
// return retrofit.create(AndroidTvBoilerplateService.class);
// }
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/data/DataManagerTest.java
import com.hitherejoe.androidtvboilerplate.data.local.PreferencesHelper;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.data.remote.AndroidTvBoilerplateService;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.List;
import rx.observers.TestSubscriber;
package com.hitherejoe.androidtvboilerplate.data;
@RunWith(MockitoJUnitRunner.class)
public class DataManagerTest {
| @Mock AndroidTvBoilerplateService mMockAndroidTvBoilerplateService; |
hitherejoe/AndroidTvBoilerplate | app/src/test/java/com/hitherejoe/androidtvboilerplate/data/DataManagerTest.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/local/PreferencesHelper.java
// @Singleton
// public class PreferencesHelper {
//
// private final SharedPreferences mPref;
//
// public static final String PREF_FILE_NAME = "tv_boilerplate_pref_file";
// private static final String PREF_KEY_ACCESS_TOKEN = "PREF_KEY_ACCESS_TOKEN";
//
// @Inject
// public PreferencesHelper(@ApplicationContext Context context) {
// mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
// }
//
// public void clear() {
// mPref.edit().clear().apply();
// }
//
// public void putAccessToken(String accessToken) {
// mPref.edit().putString(PREF_KEY_ACCESS_TOKEN, accessToken).apply();
// }
//
// @Nullable
// public String getAccessToken() {
// return mPref.getString(PREF_KEY_ACCESS_TOKEN, null);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/remote/AndroidTvBoilerplateService.java
// public interface AndroidTvBoilerplateService {
//
// String ENDPOINT = "https://your.endpoint.com/";
//
// /********
// * Helper class that sets up a new services
// *******/
// class Creator {
// public static AndroidTvBoilerplateService newVineyardService() {
// OkHttpClient client = new OkHttpClient();
// client.interceptors().add(new Interceptor() {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Response response = chain.proceed(chain.request());
// // Catch unauthorised error
// return response;
// }
// });
//
// HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
// interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// client.interceptors().add(interceptor);
//
// Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(AndroidTvBoilerplateService.ENDPOINT)
// .client(client)
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .build();
// return retrofit.create(AndroidTvBoilerplateService.class);
// }
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
| import com.hitherejoe.androidtvboilerplate.data.local.PreferencesHelper;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.data.remote.AndroidTvBoilerplateService;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.List;
import rx.observers.TestSubscriber; | package com.hitherejoe.androidtvboilerplate.data;
@RunWith(MockitoJUnitRunner.class)
public class DataManagerTest {
@Mock AndroidTvBoilerplateService mMockAndroidTvBoilerplateService; | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/local/PreferencesHelper.java
// @Singleton
// public class PreferencesHelper {
//
// private final SharedPreferences mPref;
//
// public static final String PREF_FILE_NAME = "tv_boilerplate_pref_file";
// private static final String PREF_KEY_ACCESS_TOKEN = "PREF_KEY_ACCESS_TOKEN";
//
// @Inject
// public PreferencesHelper(@ApplicationContext Context context) {
// mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
// }
//
// public void clear() {
// mPref.edit().clear().apply();
// }
//
// public void putAccessToken(String accessToken) {
// mPref.edit().putString(PREF_KEY_ACCESS_TOKEN, accessToken).apply();
// }
//
// @Nullable
// public String getAccessToken() {
// return mPref.getString(PREF_KEY_ACCESS_TOKEN, null);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/remote/AndroidTvBoilerplateService.java
// public interface AndroidTvBoilerplateService {
//
// String ENDPOINT = "https://your.endpoint.com/";
//
// /********
// * Helper class that sets up a new services
// *******/
// class Creator {
// public static AndroidTvBoilerplateService newVineyardService() {
// OkHttpClient client = new OkHttpClient();
// client.interceptors().add(new Interceptor() {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Response response = chain.proceed(chain.request());
// // Catch unauthorised error
// return response;
// }
// });
//
// HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
// interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// client.interceptors().add(interceptor);
//
// Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(AndroidTvBoilerplateService.ENDPOINT)
// .client(client)
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .build();
// return retrofit.create(AndroidTvBoilerplateService.class);
// }
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/data/DataManagerTest.java
import com.hitherejoe.androidtvboilerplate.data.local.PreferencesHelper;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.data.remote.AndroidTvBoilerplateService;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.List;
import rx.observers.TestSubscriber;
package com.hitherejoe.androidtvboilerplate.data;
@RunWith(MockitoJUnitRunner.class)
public class DataManagerTest {
@Mock AndroidTvBoilerplateService mMockAndroidTvBoilerplateService; | @Mock PreferencesHelper mMockPreferencesHelper; |
hitherejoe/AndroidTvBoilerplate | app/src/test/java/com/hitherejoe/androidtvboilerplate/data/DataManagerTest.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/local/PreferencesHelper.java
// @Singleton
// public class PreferencesHelper {
//
// private final SharedPreferences mPref;
//
// public static final String PREF_FILE_NAME = "tv_boilerplate_pref_file";
// private static final String PREF_KEY_ACCESS_TOKEN = "PREF_KEY_ACCESS_TOKEN";
//
// @Inject
// public PreferencesHelper(@ApplicationContext Context context) {
// mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
// }
//
// public void clear() {
// mPref.edit().clear().apply();
// }
//
// public void putAccessToken(String accessToken) {
// mPref.edit().putString(PREF_KEY_ACCESS_TOKEN, accessToken).apply();
// }
//
// @Nullable
// public String getAccessToken() {
// return mPref.getString(PREF_KEY_ACCESS_TOKEN, null);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/remote/AndroidTvBoilerplateService.java
// public interface AndroidTvBoilerplateService {
//
// String ENDPOINT = "https://your.endpoint.com/";
//
// /********
// * Helper class that sets up a new services
// *******/
// class Creator {
// public static AndroidTvBoilerplateService newVineyardService() {
// OkHttpClient client = new OkHttpClient();
// client.interceptors().add(new Interceptor() {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Response response = chain.proceed(chain.request());
// // Catch unauthorised error
// return response;
// }
// });
//
// HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
// interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// client.interceptors().add(interceptor);
//
// Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(AndroidTvBoilerplateService.ENDPOINT)
// .client(client)
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .build();
// return retrofit.create(AndroidTvBoilerplateService.class);
// }
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
| import com.hitherejoe.androidtvboilerplate.data.local.PreferencesHelper;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.data.remote.AndroidTvBoilerplateService;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.List;
import rx.observers.TestSubscriber; | package com.hitherejoe.androidtvboilerplate.data;
@RunWith(MockitoJUnitRunner.class)
public class DataManagerTest {
@Mock AndroidTvBoilerplateService mMockAndroidTvBoilerplateService;
@Mock PreferencesHelper mMockPreferencesHelper;
private DataManager mDataManager;
@Before
public void setUp() {
mDataManager = new DataManager(mMockPreferencesHelper, mMockAndroidTvBoilerplateService);
}
@Test
public void getCatsCompletesAndEmitsCats() throws Exception { | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/local/PreferencesHelper.java
// @Singleton
// public class PreferencesHelper {
//
// private final SharedPreferences mPref;
//
// public static final String PREF_FILE_NAME = "tv_boilerplate_pref_file";
// private static final String PREF_KEY_ACCESS_TOKEN = "PREF_KEY_ACCESS_TOKEN";
//
// @Inject
// public PreferencesHelper(@ApplicationContext Context context) {
// mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
// }
//
// public void clear() {
// mPref.edit().clear().apply();
// }
//
// public void putAccessToken(String accessToken) {
// mPref.edit().putString(PREF_KEY_ACCESS_TOKEN, accessToken).apply();
// }
//
// @Nullable
// public String getAccessToken() {
// return mPref.getString(PREF_KEY_ACCESS_TOKEN, null);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/remote/AndroidTvBoilerplateService.java
// public interface AndroidTvBoilerplateService {
//
// String ENDPOINT = "https://your.endpoint.com/";
//
// /********
// * Helper class that sets up a new services
// *******/
// class Creator {
// public static AndroidTvBoilerplateService newVineyardService() {
// OkHttpClient client = new OkHttpClient();
// client.interceptors().add(new Interceptor() {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Response response = chain.proceed(chain.request());
// // Catch unauthorised error
// return response;
// }
// });
//
// HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
// interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// client.interceptors().add(interceptor);
//
// Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(AndroidTvBoilerplateService.ENDPOINT)
// .client(client)
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .build();
// return retrofit.create(AndroidTvBoilerplateService.class);
// }
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/data/DataManagerTest.java
import com.hitherejoe.androidtvboilerplate.data.local.PreferencesHelper;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.data.remote.AndroidTvBoilerplateService;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.List;
import rx.observers.TestSubscriber;
package com.hitherejoe.androidtvboilerplate.data;
@RunWith(MockitoJUnitRunner.class)
public class DataManagerTest {
@Mock AndroidTvBoilerplateService mMockAndroidTvBoilerplateService;
@Mock PreferencesHelper mMockPreferencesHelper;
private DataManager mDataManager;
@Before
public void setUp() {
mDataManager = new DataManager(mMockPreferencesHelper, mMockAndroidTvBoilerplateService);
}
@Test
public void getCatsCompletesAndEmitsCats() throws Exception { | List<Cat> mockCats = TestDataFactory.makeCats(10); |
hitherejoe/AndroidTvBoilerplate | app/src/test/java/com/hitherejoe/androidtvboilerplate/data/DataManagerTest.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/local/PreferencesHelper.java
// @Singleton
// public class PreferencesHelper {
//
// private final SharedPreferences mPref;
//
// public static final String PREF_FILE_NAME = "tv_boilerplate_pref_file";
// private static final String PREF_KEY_ACCESS_TOKEN = "PREF_KEY_ACCESS_TOKEN";
//
// @Inject
// public PreferencesHelper(@ApplicationContext Context context) {
// mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
// }
//
// public void clear() {
// mPref.edit().clear().apply();
// }
//
// public void putAccessToken(String accessToken) {
// mPref.edit().putString(PREF_KEY_ACCESS_TOKEN, accessToken).apply();
// }
//
// @Nullable
// public String getAccessToken() {
// return mPref.getString(PREF_KEY_ACCESS_TOKEN, null);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/remote/AndroidTvBoilerplateService.java
// public interface AndroidTvBoilerplateService {
//
// String ENDPOINT = "https://your.endpoint.com/";
//
// /********
// * Helper class that sets up a new services
// *******/
// class Creator {
// public static AndroidTvBoilerplateService newVineyardService() {
// OkHttpClient client = new OkHttpClient();
// client.interceptors().add(new Interceptor() {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Response response = chain.proceed(chain.request());
// // Catch unauthorised error
// return response;
// }
// });
//
// HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
// interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// client.interceptors().add(interceptor);
//
// Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(AndroidTvBoilerplateService.ENDPOINT)
// .client(client)
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .build();
// return retrofit.create(AndroidTvBoilerplateService.class);
// }
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
| import com.hitherejoe.androidtvboilerplate.data.local.PreferencesHelper;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.data.remote.AndroidTvBoilerplateService;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.List;
import rx.observers.TestSubscriber; | package com.hitherejoe.androidtvboilerplate.data;
@RunWith(MockitoJUnitRunner.class)
public class DataManagerTest {
@Mock AndroidTvBoilerplateService mMockAndroidTvBoilerplateService;
@Mock PreferencesHelper mMockPreferencesHelper;
private DataManager mDataManager;
@Before
public void setUp() {
mDataManager = new DataManager(mMockPreferencesHelper, mMockAndroidTvBoilerplateService);
}
@Test
public void getCatsCompletesAndEmitsCats() throws Exception { | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/local/PreferencesHelper.java
// @Singleton
// public class PreferencesHelper {
//
// private final SharedPreferences mPref;
//
// public static final String PREF_FILE_NAME = "tv_boilerplate_pref_file";
// private static final String PREF_KEY_ACCESS_TOKEN = "PREF_KEY_ACCESS_TOKEN";
//
// @Inject
// public PreferencesHelper(@ApplicationContext Context context) {
// mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
// }
//
// public void clear() {
// mPref.edit().clear().apply();
// }
//
// public void putAccessToken(String accessToken) {
// mPref.edit().putString(PREF_KEY_ACCESS_TOKEN, accessToken).apply();
// }
//
// @Nullable
// public String getAccessToken() {
// return mPref.getString(PREF_KEY_ACCESS_TOKEN, null);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/remote/AndroidTvBoilerplateService.java
// public interface AndroidTvBoilerplateService {
//
// String ENDPOINT = "https://your.endpoint.com/";
//
// /********
// * Helper class that sets up a new services
// *******/
// class Creator {
// public static AndroidTvBoilerplateService newVineyardService() {
// OkHttpClient client = new OkHttpClient();
// client.interceptors().add(new Interceptor() {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Response response = chain.proceed(chain.request());
// // Catch unauthorised error
// return response;
// }
// });
//
// HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
// interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// client.interceptors().add(interceptor);
//
// Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(AndroidTvBoilerplateService.ENDPOINT)
// .client(client)
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .build();
// return retrofit.create(AndroidTvBoilerplateService.class);
// }
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/data/DataManagerTest.java
import com.hitherejoe.androidtvboilerplate.data.local.PreferencesHelper;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.data.remote.AndroidTvBoilerplateService;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.List;
import rx.observers.TestSubscriber;
package com.hitherejoe.androidtvboilerplate.data;
@RunWith(MockitoJUnitRunner.class)
public class DataManagerTest {
@Mock AndroidTvBoilerplateService mMockAndroidTvBoilerplateService;
@Mock PreferencesHelper mMockPreferencesHelper;
private DataManager mDataManager;
@Before
public void setUp() {
mDataManager = new DataManager(mMockPreferencesHelper, mMockAndroidTvBoilerplateService);
}
@Test
public void getCatsCompletesAndEmitsCats() throws Exception { | List<Cat> mockCats = TestDataFactory.makeCats(10); |
hitherejoe/AndroidTvBoilerplate | app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/injection/module/ApplicationTestModule.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/local/PreferencesHelper.java
// @Singleton
// public class PreferencesHelper {
//
// private final SharedPreferences mPref;
//
// public static final String PREF_FILE_NAME = "tv_boilerplate_pref_file";
// private static final String PREF_KEY_ACCESS_TOKEN = "PREF_KEY_ACCESS_TOKEN";
//
// @Inject
// public PreferencesHelper(@ApplicationContext Context context) {
// mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
// }
//
// public void clear() {
// mPref.edit().clear().apply();
// }
//
// public void putAccessToken(String accessToken) {
// mPref.edit().putString(PREF_KEY_ACCESS_TOKEN, accessToken).apply();
// }
//
// @Nullable
// public String getAccessToken() {
// return mPref.getString(PREF_KEY_ACCESS_TOKEN, null);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/remote/AndroidTvBoilerplateService.java
// public interface AndroidTvBoilerplateService {
//
// String ENDPOINT = "https://your.endpoint.com/";
//
// /********
// * Helper class that sets up a new services
// *******/
// class Creator {
// public static AndroidTvBoilerplateService newVineyardService() {
// OkHttpClient client = new OkHttpClient();
// client.interceptors().add(new Interceptor() {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Response response = chain.proceed(chain.request());
// // Catch unauthorised error
// return response;
// }
// });
//
// HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
// interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// client.interceptors().add(interceptor);
//
// Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(AndroidTvBoilerplateService.ENDPOINT)
// .client(client)
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .build();
// return retrofit.create(AndroidTvBoilerplateService.class);
// }
// }
//
// }
| import android.app.Application;
import android.content.Context;
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.local.PreferencesHelper;
import com.hitherejoe.androidtvboilerplate.data.remote.AndroidTvBoilerplateService;
import com.hitherejoe.androidtvboilerplate.injection.ApplicationContext;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import rx.subscriptions.CompositeSubscription;
import static org.mockito.Mockito.mock; | package com.hitherejoe.androidtvboilerplate.test.common.injection.module;
/**
* Provides application-level dependencies for an app running on a testing environment
* This allows injecting mocks if necessary.
*/
@Module
public class ApplicationTestModule {
private final Application mApplication;
public ApplicationTestModule(Application application) {
mApplication = application;
}
@Provides
Application provideApplication() {
return mApplication;
}
@Provides
@ApplicationContext
Context provideContext() {
return mApplication;
}
@Provides
CompositeSubscription provideCompositeSubscription() {
return new CompositeSubscription();
}
/************* MOCKS *************/
@Provides
@Singleton | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/local/PreferencesHelper.java
// @Singleton
// public class PreferencesHelper {
//
// private final SharedPreferences mPref;
//
// public static final String PREF_FILE_NAME = "tv_boilerplate_pref_file";
// private static final String PREF_KEY_ACCESS_TOKEN = "PREF_KEY_ACCESS_TOKEN";
//
// @Inject
// public PreferencesHelper(@ApplicationContext Context context) {
// mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
// }
//
// public void clear() {
// mPref.edit().clear().apply();
// }
//
// public void putAccessToken(String accessToken) {
// mPref.edit().putString(PREF_KEY_ACCESS_TOKEN, accessToken).apply();
// }
//
// @Nullable
// public String getAccessToken() {
// return mPref.getString(PREF_KEY_ACCESS_TOKEN, null);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/remote/AndroidTvBoilerplateService.java
// public interface AndroidTvBoilerplateService {
//
// String ENDPOINT = "https://your.endpoint.com/";
//
// /********
// * Helper class that sets up a new services
// *******/
// class Creator {
// public static AndroidTvBoilerplateService newVineyardService() {
// OkHttpClient client = new OkHttpClient();
// client.interceptors().add(new Interceptor() {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Response response = chain.proceed(chain.request());
// // Catch unauthorised error
// return response;
// }
// });
//
// HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
// interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// client.interceptors().add(interceptor);
//
// Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(AndroidTvBoilerplateService.ENDPOINT)
// .client(client)
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .build();
// return retrofit.create(AndroidTvBoilerplateService.class);
// }
// }
//
// }
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/injection/module/ApplicationTestModule.java
import android.app.Application;
import android.content.Context;
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.local.PreferencesHelper;
import com.hitherejoe.androidtvboilerplate.data.remote.AndroidTvBoilerplateService;
import com.hitherejoe.androidtvboilerplate.injection.ApplicationContext;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import rx.subscriptions.CompositeSubscription;
import static org.mockito.Mockito.mock;
package com.hitherejoe.androidtvboilerplate.test.common.injection.module;
/**
* Provides application-level dependencies for an app running on a testing environment
* This allows injecting mocks if necessary.
*/
@Module
public class ApplicationTestModule {
private final Application mApplication;
public ApplicationTestModule(Application application) {
mApplication = application;
}
@Provides
Application provideApplication() {
return mApplication;
}
@Provides
@ApplicationContext
Context provideContext() {
return mApplication;
}
@Provides
CompositeSubscription provideCompositeSubscription() {
return new CompositeSubscription();
}
/************* MOCKS *************/
@Provides
@Singleton | DataManager provideDataManager() { |
hitherejoe/AndroidTvBoilerplate | app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/injection/module/ApplicationTestModule.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/local/PreferencesHelper.java
// @Singleton
// public class PreferencesHelper {
//
// private final SharedPreferences mPref;
//
// public static final String PREF_FILE_NAME = "tv_boilerplate_pref_file";
// private static final String PREF_KEY_ACCESS_TOKEN = "PREF_KEY_ACCESS_TOKEN";
//
// @Inject
// public PreferencesHelper(@ApplicationContext Context context) {
// mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
// }
//
// public void clear() {
// mPref.edit().clear().apply();
// }
//
// public void putAccessToken(String accessToken) {
// mPref.edit().putString(PREF_KEY_ACCESS_TOKEN, accessToken).apply();
// }
//
// @Nullable
// public String getAccessToken() {
// return mPref.getString(PREF_KEY_ACCESS_TOKEN, null);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/remote/AndroidTvBoilerplateService.java
// public interface AndroidTvBoilerplateService {
//
// String ENDPOINT = "https://your.endpoint.com/";
//
// /********
// * Helper class that sets up a new services
// *******/
// class Creator {
// public static AndroidTvBoilerplateService newVineyardService() {
// OkHttpClient client = new OkHttpClient();
// client.interceptors().add(new Interceptor() {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Response response = chain.proceed(chain.request());
// // Catch unauthorised error
// return response;
// }
// });
//
// HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
// interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// client.interceptors().add(interceptor);
//
// Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(AndroidTvBoilerplateService.ENDPOINT)
// .client(client)
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .build();
// return retrofit.create(AndroidTvBoilerplateService.class);
// }
// }
//
// }
| import android.app.Application;
import android.content.Context;
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.local.PreferencesHelper;
import com.hitherejoe.androidtvboilerplate.data.remote.AndroidTvBoilerplateService;
import com.hitherejoe.androidtvboilerplate.injection.ApplicationContext;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import rx.subscriptions.CompositeSubscription;
import static org.mockito.Mockito.mock; | package com.hitherejoe.androidtvboilerplate.test.common.injection.module;
/**
* Provides application-level dependencies for an app running on a testing environment
* This allows injecting mocks if necessary.
*/
@Module
public class ApplicationTestModule {
private final Application mApplication;
public ApplicationTestModule(Application application) {
mApplication = application;
}
@Provides
Application provideApplication() {
return mApplication;
}
@Provides
@ApplicationContext
Context provideContext() {
return mApplication;
}
@Provides
CompositeSubscription provideCompositeSubscription() {
return new CompositeSubscription();
}
/************* MOCKS *************/
@Provides
@Singleton
DataManager provideDataManager() {
return mock(DataManager.class);
}
@Provides
@Singleton | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/local/PreferencesHelper.java
// @Singleton
// public class PreferencesHelper {
//
// private final SharedPreferences mPref;
//
// public static final String PREF_FILE_NAME = "tv_boilerplate_pref_file";
// private static final String PREF_KEY_ACCESS_TOKEN = "PREF_KEY_ACCESS_TOKEN";
//
// @Inject
// public PreferencesHelper(@ApplicationContext Context context) {
// mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
// }
//
// public void clear() {
// mPref.edit().clear().apply();
// }
//
// public void putAccessToken(String accessToken) {
// mPref.edit().putString(PREF_KEY_ACCESS_TOKEN, accessToken).apply();
// }
//
// @Nullable
// public String getAccessToken() {
// return mPref.getString(PREF_KEY_ACCESS_TOKEN, null);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/remote/AndroidTvBoilerplateService.java
// public interface AndroidTvBoilerplateService {
//
// String ENDPOINT = "https://your.endpoint.com/";
//
// /********
// * Helper class that sets up a new services
// *******/
// class Creator {
// public static AndroidTvBoilerplateService newVineyardService() {
// OkHttpClient client = new OkHttpClient();
// client.interceptors().add(new Interceptor() {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Response response = chain.proceed(chain.request());
// // Catch unauthorised error
// return response;
// }
// });
//
// HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
// interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// client.interceptors().add(interceptor);
//
// Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(AndroidTvBoilerplateService.ENDPOINT)
// .client(client)
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .build();
// return retrofit.create(AndroidTvBoilerplateService.class);
// }
// }
//
// }
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/injection/module/ApplicationTestModule.java
import android.app.Application;
import android.content.Context;
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.local.PreferencesHelper;
import com.hitherejoe.androidtvboilerplate.data.remote.AndroidTvBoilerplateService;
import com.hitherejoe.androidtvboilerplate.injection.ApplicationContext;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import rx.subscriptions.CompositeSubscription;
import static org.mockito.Mockito.mock;
package com.hitherejoe.androidtvboilerplate.test.common.injection.module;
/**
* Provides application-level dependencies for an app running on a testing environment
* This allows injecting mocks if necessary.
*/
@Module
public class ApplicationTestModule {
private final Application mApplication;
public ApplicationTestModule(Application application) {
mApplication = application;
}
@Provides
Application provideApplication() {
return mApplication;
}
@Provides
@ApplicationContext
Context provideContext() {
return mApplication;
}
@Provides
CompositeSubscription provideCompositeSubscription() {
return new CompositeSubscription();
}
/************* MOCKS *************/
@Provides
@Singleton
DataManager provideDataManager() {
return mock(DataManager.class);
}
@Provides
@Singleton | PreferencesHelper providePreferencesHelper() { |
hitherejoe/AndroidTvBoilerplate | app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/injection/module/ApplicationTestModule.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/local/PreferencesHelper.java
// @Singleton
// public class PreferencesHelper {
//
// private final SharedPreferences mPref;
//
// public static final String PREF_FILE_NAME = "tv_boilerplate_pref_file";
// private static final String PREF_KEY_ACCESS_TOKEN = "PREF_KEY_ACCESS_TOKEN";
//
// @Inject
// public PreferencesHelper(@ApplicationContext Context context) {
// mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
// }
//
// public void clear() {
// mPref.edit().clear().apply();
// }
//
// public void putAccessToken(String accessToken) {
// mPref.edit().putString(PREF_KEY_ACCESS_TOKEN, accessToken).apply();
// }
//
// @Nullable
// public String getAccessToken() {
// return mPref.getString(PREF_KEY_ACCESS_TOKEN, null);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/remote/AndroidTvBoilerplateService.java
// public interface AndroidTvBoilerplateService {
//
// String ENDPOINT = "https://your.endpoint.com/";
//
// /********
// * Helper class that sets up a new services
// *******/
// class Creator {
// public static AndroidTvBoilerplateService newVineyardService() {
// OkHttpClient client = new OkHttpClient();
// client.interceptors().add(new Interceptor() {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Response response = chain.proceed(chain.request());
// // Catch unauthorised error
// return response;
// }
// });
//
// HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
// interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// client.interceptors().add(interceptor);
//
// Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(AndroidTvBoilerplateService.ENDPOINT)
// .client(client)
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .build();
// return retrofit.create(AndroidTvBoilerplateService.class);
// }
// }
//
// }
| import android.app.Application;
import android.content.Context;
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.local.PreferencesHelper;
import com.hitherejoe.androidtvboilerplate.data.remote.AndroidTvBoilerplateService;
import com.hitherejoe.androidtvboilerplate.injection.ApplicationContext;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import rx.subscriptions.CompositeSubscription;
import static org.mockito.Mockito.mock; | package com.hitherejoe.androidtvboilerplate.test.common.injection.module;
/**
* Provides application-level dependencies for an app running on a testing environment
* This allows injecting mocks if necessary.
*/
@Module
public class ApplicationTestModule {
private final Application mApplication;
public ApplicationTestModule(Application application) {
mApplication = application;
}
@Provides
Application provideApplication() {
return mApplication;
}
@Provides
@ApplicationContext
Context provideContext() {
return mApplication;
}
@Provides
CompositeSubscription provideCompositeSubscription() {
return new CompositeSubscription();
}
/************* MOCKS *************/
@Provides
@Singleton
DataManager provideDataManager() {
return mock(DataManager.class);
}
@Provides
@Singleton
PreferencesHelper providePreferencesHelper() {
return mock(PreferencesHelper.class);
}
@Provides
@Singleton | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/local/PreferencesHelper.java
// @Singleton
// public class PreferencesHelper {
//
// private final SharedPreferences mPref;
//
// public static final String PREF_FILE_NAME = "tv_boilerplate_pref_file";
// private static final String PREF_KEY_ACCESS_TOKEN = "PREF_KEY_ACCESS_TOKEN";
//
// @Inject
// public PreferencesHelper(@ApplicationContext Context context) {
// mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
// }
//
// public void clear() {
// mPref.edit().clear().apply();
// }
//
// public void putAccessToken(String accessToken) {
// mPref.edit().putString(PREF_KEY_ACCESS_TOKEN, accessToken).apply();
// }
//
// @Nullable
// public String getAccessToken() {
// return mPref.getString(PREF_KEY_ACCESS_TOKEN, null);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/remote/AndroidTvBoilerplateService.java
// public interface AndroidTvBoilerplateService {
//
// String ENDPOINT = "https://your.endpoint.com/";
//
// /********
// * Helper class that sets up a new services
// *******/
// class Creator {
// public static AndroidTvBoilerplateService newVineyardService() {
// OkHttpClient client = new OkHttpClient();
// client.interceptors().add(new Interceptor() {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Response response = chain.proceed(chain.request());
// // Catch unauthorised error
// return response;
// }
// });
//
// HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
// interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// client.interceptors().add(interceptor);
//
// Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(AndroidTvBoilerplateService.ENDPOINT)
// .client(client)
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .build();
// return retrofit.create(AndroidTvBoilerplateService.class);
// }
// }
//
// }
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/injection/module/ApplicationTestModule.java
import android.app.Application;
import android.content.Context;
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.local.PreferencesHelper;
import com.hitherejoe.androidtvboilerplate.data.remote.AndroidTvBoilerplateService;
import com.hitherejoe.androidtvboilerplate.injection.ApplicationContext;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import rx.subscriptions.CompositeSubscription;
import static org.mockito.Mockito.mock;
package com.hitherejoe.androidtvboilerplate.test.common.injection.module;
/**
* Provides application-level dependencies for an app running on a testing environment
* This allows injecting mocks if necessary.
*/
@Module
public class ApplicationTestModule {
private final Application mApplication;
public ApplicationTestModule(Application application) {
mApplication = application;
}
@Provides
Application provideApplication() {
return mApplication;
}
@Provides
@ApplicationContext
Context provideContext() {
return mApplication;
}
@Provides
CompositeSubscription provideCompositeSubscription() {
return new CompositeSubscription();
}
/************* MOCKS *************/
@Provides
@Singleton
DataManager provideDataManager() {
return mock(DataManager.class);
}
@Provides
@Singleton
PreferencesHelper providePreferencesHelper() {
return mock(PreferencesHelper.class);
}
@Provides
@Singleton | AndroidTvBoilerplateService provideAndroidTvBoilerplateService() { |
hitherejoe/AndroidTvBoilerplate | app/src/test/java/com/hitherejoe/androidtvboilerplate/ui/search/SearchContentPresenterTest.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/util/RxSchedulersOverrideRule.java
// public class RxSchedulersOverrideRule implements TestRule {
//
// private final RxJavaSchedulersHook mRxJavaSchedulersHook = new RxJavaSchedulersHook() {
// @Override
// public Scheduler getIOScheduler() {
// return Schedulers.immediate();
// }
//
// @Override
// public Scheduler getNewThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// private final RxAndroidSchedulersHook mRxAndroidSchedulersHook = new RxAndroidSchedulersHook() {
// @Override
// public Scheduler getMainThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// // Hack to get around RxJavaPlugins.reset() not being public
// // See https://github.com/ReactiveX/RxJava/issues/2297
// // Hopefully the method will be public in new releases of RxAndroid and we can remove the hack.
// private void callResetViaReflectionIn(RxJavaPlugins rxJavaPlugins)
// throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
// Method method = rxJavaPlugins.getClass().getDeclaredMethod("reset");
// method.setAccessible(true);
// method.invoke(rxJavaPlugins);
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// RxAndroidPlugins.getInstance().reset();
// RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook);
//
// base.evaluate();
//
// RxAndroidPlugins.getInstance().reset();
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// }
// };
// }
// }
| import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.util.RxSchedulersOverrideRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.List;
import rx.Single;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; | package com.hitherejoe.androidtvboilerplate.ui.search;
@RunWith(MockitoJUnitRunner.class)
public class SearchContentPresenterTest {
@Mock SearchContentMvpView mMockSearchContentMvpView; | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/util/RxSchedulersOverrideRule.java
// public class RxSchedulersOverrideRule implements TestRule {
//
// private final RxJavaSchedulersHook mRxJavaSchedulersHook = new RxJavaSchedulersHook() {
// @Override
// public Scheduler getIOScheduler() {
// return Schedulers.immediate();
// }
//
// @Override
// public Scheduler getNewThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// private final RxAndroidSchedulersHook mRxAndroidSchedulersHook = new RxAndroidSchedulersHook() {
// @Override
// public Scheduler getMainThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// // Hack to get around RxJavaPlugins.reset() not being public
// // See https://github.com/ReactiveX/RxJava/issues/2297
// // Hopefully the method will be public in new releases of RxAndroid and we can remove the hack.
// private void callResetViaReflectionIn(RxJavaPlugins rxJavaPlugins)
// throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
// Method method = rxJavaPlugins.getClass().getDeclaredMethod("reset");
// method.setAccessible(true);
// method.invoke(rxJavaPlugins);
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// RxAndroidPlugins.getInstance().reset();
// RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook);
//
// base.evaluate();
//
// RxAndroidPlugins.getInstance().reset();
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// }
// };
// }
// }
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/ui/search/SearchContentPresenterTest.java
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.util.RxSchedulersOverrideRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.List;
import rx.Single;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
package com.hitherejoe.androidtvboilerplate.ui.search;
@RunWith(MockitoJUnitRunner.class)
public class SearchContentPresenterTest {
@Mock SearchContentMvpView mMockSearchContentMvpView; | @Mock DataManager mMockDataManager; |
hitherejoe/AndroidTvBoilerplate | app/src/test/java/com/hitherejoe/androidtvboilerplate/ui/search/SearchContentPresenterTest.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/util/RxSchedulersOverrideRule.java
// public class RxSchedulersOverrideRule implements TestRule {
//
// private final RxJavaSchedulersHook mRxJavaSchedulersHook = new RxJavaSchedulersHook() {
// @Override
// public Scheduler getIOScheduler() {
// return Schedulers.immediate();
// }
//
// @Override
// public Scheduler getNewThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// private final RxAndroidSchedulersHook mRxAndroidSchedulersHook = new RxAndroidSchedulersHook() {
// @Override
// public Scheduler getMainThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// // Hack to get around RxJavaPlugins.reset() not being public
// // See https://github.com/ReactiveX/RxJava/issues/2297
// // Hopefully the method will be public in new releases of RxAndroid and we can remove the hack.
// private void callResetViaReflectionIn(RxJavaPlugins rxJavaPlugins)
// throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
// Method method = rxJavaPlugins.getClass().getDeclaredMethod("reset");
// method.setAccessible(true);
// method.invoke(rxJavaPlugins);
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// RxAndroidPlugins.getInstance().reset();
// RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook);
//
// base.evaluate();
//
// RxAndroidPlugins.getInstance().reset();
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// }
// };
// }
// }
| import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.util.RxSchedulersOverrideRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.List;
import rx.Single;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; | package com.hitherejoe.androidtvboilerplate.ui.search;
@RunWith(MockitoJUnitRunner.class)
public class SearchContentPresenterTest {
@Mock SearchContentMvpView mMockSearchContentMvpView;
@Mock DataManager mMockDataManager;
private SearchContentPresenter mSearchContentPresenter;
@Rule | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/util/RxSchedulersOverrideRule.java
// public class RxSchedulersOverrideRule implements TestRule {
//
// private final RxJavaSchedulersHook mRxJavaSchedulersHook = new RxJavaSchedulersHook() {
// @Override
// public Scheduler getIOScheduler() {
// return Schedulers.immediate();
// }
//
// @Override
// public Scheduler getNewThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// private final RxAndroidSchedulersHook mRxAndroidSchedulersHook = new RxAndroidSchedulersHook() {
// @Override
// public Scheduler getMainThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// // Hack to get around RxJavaPlugins.reset() not being public
// // See https://github.com/ReactiveX/RxJava/issues/2297
// // Hopefully the method will be public in new releases of RxAndroid and we can remove the hack.
// private void callResetViaReflectionIn(RxJavaPlugins rxJavaPlugins)
// throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
// Method method = rxJavaPlugins.getClass().getDeclaredMethod("reset");
// method.setAccessible(true);
// method.invoke(rxJavaPlugins);
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// RxAndroidPlugins.getInstance().reset();
// RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook);
//
// base.evaluate();
//
// RxAndroidPlugins.getInstance().reset();
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// }
// };
// }
// }
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/ui/search/SearchContentPresenterTest.java
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.util.RxSchedulersOverrideRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.List;
import rx.Single;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
package com.hitherejoe.androidtvboilerplate.ui.search;
@RunWith(MockitoJUnitRunner.class)
public class SearchContentPresenterTest {
@Mock SearchContentMvpView mMockSearchContentMvpView;
@Mock DataManager mMockDataManager;
private SearchContentPresenter mSearchContentPresenter;
@Rule | public final RxSchedulersOverrideRule mOverrideSchedulersRule = new RxSchedulersOverrideRule(); |
hitherejoe/AndroidTvBoilerplate | app/src/test/java/com/hitherejoe/androidtvboilerplate/ui/search/SearchContentPresenterTest.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/util/RxSchedulersOverrideRule.java
// public class RxSchedulersOverrideRule implements TestRule {
//
// private final RxJavaSchedulersHook mRxJavaSchedulersHook = new RxJavaSchedulersHook() {
// @Override
// public Scheduler getIOScheduler() {
// return Schedulers.immediate();
// }
//
// @Override
// public Scheduler getNewThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// private final RxAndroidSchedulersHook mRxAndroidSchedulersHook = new RxAndroidSchedulersHook() {
// @Override
// public Scheduler getMainThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// // Hack to get around RxJavaPlugins.reset() not being public
// // See https://github.com/ReactiveX/RxJava/issues/2297
// // Hopefully the method will be public in new releases of RxAndroid and we can remove the hack.
// private void callResetViaReflectionIn(RxJavaPlugins rxJavaPlugins)
// throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
// Method method = rxJavaPlugins.getClass().getDeclaredMethod("reset");
// method.setAccessible(true);
// method.invoke(rxJavaPlugins);
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// RxAndroidPlugins.getInstance().reset();
// RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook);
//
// base.evaluate();
//
// RxAndroidPlugins.getInstance().reset();
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// }
// };
// }
// }
| import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.util.RxSchedulersOverrideRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.List;
import rx.Single;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; | package com.hitherejoe.androidtvboilerplate.ui.search;
@RunWith(MockitoJUnitRunner.class)
public class SearchContentPresenterTest {
@Mock SearchContentMvpView mMockSearchContentMvpView;
@Mock DataManager mMockDataManager;
private SearchContentPresenter mSearchContentPresenter;
@Rule
public final RxSchedulersOverrideRule mOverrideSchedulersRule = new RxSchedulersOverrideRule();
@Before
public void setUp() {
mSearchContentPresenter = new SearchContentPresenter(mMockDataManager);
mSearchContentPresenter.attachView(mMockSearchContentMvpView);
}
@After
public void detachView() {
mSearchContentPresenter.detachView();
}
@Test
public void getCatsSuccessful() { | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/util/RxSchedulersOverrideRule.java
// public class RxSchedulersOverrideRule implements TestRule {
//
// private final RxJavaSchedulersHook mRxJavaSchedulersHook = new RxJavaSchedulersHook() {
// @Override
// public Scheduler getIOScheduler() {
// return Schedulers.immediate();
// }
//
// @Override
// public Scheduler getNewThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// private final RxAndroidSchedulersHook mRxAndroidSchedulersHook = new RxAndroidSchedulersHook() {
// @Override
// public Scheduler getMainThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// // Hack to get around RxJavaPlugins.reset() not being public
// // See https://github.com/ReactiveX/RxJava/issues/2297
// // Hopefully the method will be public in new releases of RxAndroid and we can remove the hack.
// private void callResetViaReflectionIn(RxJavaPlugins rxJavaPlugins)
// throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
// Method method = rxJavaPlugins.getClass().getDeclaredMethod("reset");
// method.setAccessible(true);
// method.invoke(rxJavaPlugins);
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// RxAndroidPlugins.getInstance().reset();
// RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook);
//
// base.evaluate();
//
// RxAndroidPlugins.getInstance().reset();
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// }
// };
// }
// }
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/ui/search/SearchContentPresenterTest.java
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.util.RxSchedulersOverrideRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.List;
import rx.Single;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
package com.hitherejoe.androidtvboilerplate.ui.search;
@RunWith(MockitoJUnitRunner.class)
public class SearchContentPresenterTest {
@Mock SearchContentMvpView mMockSearchContentMvpView;
@Mock DataManager mMockDataManager;
private SearchContentPresenter mSearchContentPresenter;
@Rule
public final RxSchedulersOverrideRule mOverrideSchedulersRule = new RxSchedulersOverrideRule();
@Before
public void setUp() {
mSearchContentPresenter = new SearchContentPresenter(mMockDataManager);
mSearchContentPresenter.attachView(mMockSearchContentMvpView);
}
@After
public void detachView() {
mSearchContentPresenter.detachView();
}
@Test
public void getCatsSuccessful() { | List<Cat> cats = TestDataFactory.makeCats(10); |
hitherejoe/AndroidTvBoilerplate | app/src/test/java/com/hitherejoe/androidtvboilerplate/ui/search/SearchContentPresenterTest.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/util/RxSchedulersOverrideRule.java
// public class RxSchedulersOverrideRule implements TestRule {
//
// private final RxJavaSchedulersHook mRxJavaSchedulersHook = new RxJavaSchedulersHook() {
// @Override
// public Scheduler getIOScheduler() {
// return Schedulers.immediate();
// }
//
// @Override
// public Scheduler getNewThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// private final RxAndroidSchedulersHook mRxAndroidSchedulersHook = new RxAndroidSchedulersHook() {
// @Override
// public Scheduler getMainThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// // Hack to get around RxJavaPlugins.reset() not being public
// // See https://github.com/ReactiveX/RxJava/issues/2297
// // Hopefully the method will be public in new releases of RxAndroid and we can remove the hack.
// private void callResetViaReflectionIn(RxJavaPlugins rxJavaPlugins)
// throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
// Method method = rxJavaPlugins.getClass().getDeclaredMethod("reset");
// method.setAccessible(true);
// method.invoke(rxJavaPlugins);
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// RxAndroidPlugins.getInstance().reset();
// RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook);
//
// base.evaluate();
//
// RxAndroidPlugins.getInstance().reset();
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// }
// };
// }
// }
| import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.util.RxSchedulersOverrideRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.List;
import rx.Single;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; | package com.hitherejoe.androidtvboilerplate.ui.search;
@RunWith(MockitoJUnitRunner.class)
public class SearchContentPresenterTest {
@Mock SearchContentMvpView mMockSearchContentMvpView;
@Mock DataManager mMockDataManager;
private SearchContentPresenter mSearchContentPresenter;
@Rule
public final RxSchedulersOverrideRule mOverrideSchedulersRule = new RxSchedulersOverrideRule();
@Before
public void setUp() {
mSearchContentPresenter = new SearchContentPresenter(mMockDataManager);
mSearchContentPresenter.attachView(mMockSearchContentMvpView);
}
@After
public void detachView() {
mSearchContentPresenter.detachView();
}
@Test
public void getCatsSuccessful() { | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/util/RxSchedulersOverrideRule.java
// public class RxSchedulersOverrideRule implements TestRule {
//
// private final RxJavaSchedulersHook mRxJavaSchedulersHook = new RxJavaSchedulersHook() {
// @Override
// public Scheduler getIOScheduler() {
// return Schedulers.immediate();
// }
//
// @Override
// public Scheduler getNewThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// private final RxAndroidSchedulersHook mRxAndroidSchedulersHook = new RxAndroidSchedulersHook() {
// @Override
// public Scheduler getMainThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// // Hack to get around RxJavaPlugins.reset() not being public
// // See https://github.com/ReactiveX/RxJava/issues/2297
// // Hopefully the method will be public in new releases of RxAndroid and we can remove the hack.
// private void callResetViaReflectionIn(RxJavaPlugins rxJavaPlugins)
// throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
// Method method = rxJavaPlugins.getClass().getDeclaredMethod("reset");
// method.setAccessible(true);
// method.invoke(rxJavaPlugins);
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// RxAndroidPlugins.getInstance().reset();
// RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook);
//
// base.evaluate();
//
// RxAndroidPlugins.getInstance().reset();
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// }
// };
// }
// }
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/ui/search/SearchContentPresenterTest.java
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.util.RxSchedulersOverrideRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.List;
import rx.Single;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
package com.hitherejoe.androidtvboilerplate.ui.search;
@RunWith(MockitoJUnitRunner.class)
public class SearchContentPresenterTest {
@Mock SearchContentMvpView mMockSearchContentMvpView;
@Mock DataManager mMockDataManager;
private SearchContentPresenter mSearchContentPresenter;
@Rule
public final RxSchedulersOverrideRule mOverrideSchedulersRule = new RxSchedulersOverrideRule();
@Before
public void setUp() {
mSearchContentPresenter = new SearchContentPresenter(mMockDataManager);
mSearchContentPresenter.attachView(mMockSearchContentMvpView);
}
@After
public void detachView() {
mSearchContentPresenter.detachView();
}
@Test
public void getCatsSuccessful() { | List<Cat> cats = TestDataFactory.makeCats(10); |
hitherejoe/AndroidTvBoilerplate | app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/local/PreferencesHelper.java
// @Singleton
// public class PreferencesHelper {
//
// private final SharedPreferences mPref;
//
// public static final String PREF_FILE_NAME = "tv_boilerplate_pref_file";
// private static final String PREF_KEY_ACCESS_TOKEN = "PREF_KEY_ACCESS_TOKEN";
//
// @Inject
// public PreferencesHelper(@ApplicationContext Context context) {
// mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
// }
//
// public void clear() {
// mPref.edit().clear().apply();
// }
//
// public void putAccessToken(String accessToken) {
// mPref.edit().putString(PREF_KEY_ACCESS_TOKEN, accessToken).apply();
// }
//
// @Nullable
// public String getAccessToken() {
// return mPref.getString(PREF_KEY_ACCESS_TOKEN, null);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/remote/AndroidTvBoilerplateService.java
// public interface AndroidTvBoilerplateService {
//
// String ENDPOINT = "https://your.endpoint.com/";
//
// /********
// * Helper class that sets up a new services
// *******/
// class Creator {
// public static AndroidTvBoilerplateService newVineyardService() {
// OkHttpClient client = new OkHttpClient();
// client.interceptors().add(new Interceptor() {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Response response = chain.proceed(chain.request());
// // Catch unauthorised error
// return response;
// }
// });
//
// HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
// interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// client.interceptors().add(interceptor);
//
// Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(AndroidTvBoilerplateService.ENDPOINT)
// .client(client)
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .build();
// return retrofit.create(AndroidTvBoilerplateService.class);
// }
// }
//
// }
| import com.hitherejoe.androidtvboilerplate.data.local.PreferencesHelper;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.data.remote.AndroidTvBoilerplateService;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import rx.Single; | package com.hitherejoe.androidtvboilerplate.data;
@Singleton
public class DataManager {
| // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/local/PreferencesHelper.java
// @Singleton
// public class PreferencesHelper {
//
// private final SharedPreferences mPref;
//
// public static final String PREF_FILE_NAME = "tv_boilerplate_pref_file";
// private static final String PREF_KEY_ACCESS_TOKEN = "PREF_KEY_ACCESS_TOKEN";
//
// @Inject
// public PreferencesHelper(@ApplicationContext Context context) {
// mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
// }
//
// public void clear() {
// mPref.edit().clear().apply();
// }
//
// public void putAccessToken(String accessToken) {
// mPref.edit().putString(PREF_KEY_ACCESS_TOKEN, accessToken).apply();
// }
//
// @Nullable
// public String getAccessToken() {
// return mPref.getString(PREF_KEY_ACCESS_TOKEN, null);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/remote/AndroidTvBoilerplateService.java
// public interface AndroidTvBoilerplateService {
//
// String ENDPOINT = "https://your.endpoint.com/";
//
// /********
// * Helper class that sets up a new services
// *******/
// class Creator {
// public static AndroidTvBoilerplateService newVineyardService() {
// OkHttpClient client = new OkHttpClient();
// client.interceptors().add(new Interceptor() {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Response response = chain.proceed(chain.request());
// // Catch unauthorised error
// return response;
// }
// });
//
// HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
// interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// client.interceptors().add(interceptor);
//
// Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(AndroidTvBoilerplateService.ENDPOINT)
// .client(client)
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .build();
// return retrofit.create(AndroidTvBoilerplateService.class);
// }
// }
//
// }
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
import com.hitherejoe.androidtvboilerplate.data.local.PreferencesHelper;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.data.remote.AndroidTvBoilerplateService;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import rx.Single;
package com.hitherejoe.androidtvboilerplate.data;
@Singleton
public class DataManager {
| private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService; |
hitherejoe/AndroidTvBoilerplate | app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/local/PreferencesHelper.java
// @Singleton
// public class PreferencesHelper {
//
// private final SharedPreferences mPref;
//
// public static final String PREF_FILE_NAME = "tv_boilerplate_pref_file";
// private static final String PREF_KEY_ACCESS_TOKEN = "PREF_KEY_ACCESS_TOKEN";
//
// @Inject
// public PreferencesHelper(@ApplicationContext Context context) {
// mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
// }
//
// public void clear() {
// mPref.edit().clear().apply();
// }
//
// public void putAccessToken(String accessToken) {
// mPref.edit().putString(PREF_KEY_ACCESS_TOKEN, accessToken).apply();
// }
//
// @Nullable
// public String getAccessToken() {
// return mPref.getString(PREF_KEY_ACCESS_TOKEN, null);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/remote/AndroidTvBoilerplateService.java
// public interface AndroidTvBoilerplateService {
//
// String ENDPOINT = "https://your.endpoint.com/";
//
// /********
// * Helper class that sets up a new services
// *******/
// class Creator {
// public static AndroidTvBoilerplateService newVineyardService() {
// OkHttpClient client = new OkHttpClient();
// client.interceptors().add(new Interceptor() {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Response response = chain.proceed(chain.request());
// // Catch unauthorised error
// return response;
// }
// });
//
// HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
// interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// client.interceptors().add(interceptor);
//
// Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(AndroidTvBoilerplateService.ENDPOINT)
// .client(client)
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .build();
// return retrofit.create(AndroidTvBoilerplateService.class);
// }
// }
//
// }
| import com.hitherejoe.androidtvboilerplate.data.local.PreferencesHelper;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.data.remote.AndroidTvBoilerplateService;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import rx.Single; | package com.hitherejoe.androidtvboilerplate.data;
@Singleton
public class DataManager {
private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService; | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/local/PreferencesHelper.java
// @Singleton
// public class PreferencesHelper {
//
// private final SharedPreferences mPref;
//
// public static final String PREF_FILE_NAME = "tv_boilerplate_pref_file";
// private static final String PREF_KEY_ACCESS_TOKEN = "PREF_KEY_ACCESS_TOKEN";
//
// @Inject
// public PreferencesHelper(@ApplicationContext Context context) {
// mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
// }
//
// public void clear() {
// mPref.edit().clear().apply();
// }
//
// public void putAccessToken(String accessToken) {
// mPref.edit().putString(PREF_KEY_ACCESS_TOKEN, accessToken).apply();
// }
//
// @Nullable
// public String getAccessToken() {
// return mPref.getString(PREF_KEY_ACCESS_TOKEN, null);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/remote/AndroidTvBoilerplateService.java
// public interface AndroidTvBoilerplateService {
//
// String ENDPOINT = "https://your.endpoint.com/";
//
// /********
// * Helper class that sets up a new services
// *******/
// class Creator {
// public static AndroidTvBoilerplateService newVineyardService() {
// OkHttpClient client = new OkHttpClient();
// client.interceptors().add(new Interceptor() {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Response response = chain.proceed(chain.request());
// // Catch unauthorised error
// return response;
// }
// });
//
// HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
// interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// client.interceptors().add(interceptor);
//
// Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(AndroidTvBoilerplateService.ENDPOINT)
// .client(client)
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .build();
// return retrofit.create(AndroidTvBoilerplateService.class);
// }
// }
//
// }
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
import com.hitherejoe.androidtvboilerplate.data.local.PreferencesHelper;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.data.remote.AndroidTvBoilerplateService;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import rx.Single;
package com.hitherejoe.androidtvboilerplate.data;
@Singleton
public class DataManager {
private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService; | private final PreferencesHelper mPreferencesHelper; |
hitherejoe/AndroidTvBoilerplate | app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/local/PreferencesHelper.java
// @Singleton
// public class PreferencesHelper {
//
// private final SharedPreferences mPref;
//
// public static final String PREF_FILE_NAME = "tv_boilerplate_pref_file";
// private static final String PREF_KEY_ACCESS_TOKEN = "PREF_KEY_ACCESS_TOKEN";
//
// @Inject
// public PreferencesHelper(@ApplicationContext Context context) {
// mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
// }
//
// public void clear() {
// mPref.edit().clear().apply();
// }
//
// public void putAccessToken(String accessToken) {
// mPref.edit().putString(PREF_KEY_ACCESS_TOKEN, accessToken).apply();
// }
//
// @Nullable
// public String getAccessToken() {
// return mPref.getString(PREF_KEY_ACCESS_TOKEN, null);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/remote/AndroidTvBoilerplateService.java
// public interface AndroidTvBoilerplateService {
//
// String ENDPOINT = "https://your.endpoint.com/";
//
// /********
// * Helper class that sets up a new services
// *******/
// class Creator {
// public static AndroidTvBoilerplateService newVineyardService() {
// OkHttpClient client = new OkHttpClient();
// client.interceptors().add(new Interceptor() {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Response response = chain.proceed(chain.request());
// // Catch unauthorised error
// return response;
// }
// });
//
// HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
// interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// client.interceptors().add(interceptor);
//
// Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(AndroidTvBoilerplateService.ENDPOINT)
// .client(client)
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .build();
// return retrofit.create(AndroidTvBoilerplateService.class);
// }
// }
//
// }
| import com.hitherejoe.androidtvboilerplate.data.local.PreferencesHelper;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.data.remote.AndroidTvBoilerplateService;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import rx.Single; | package com.hitherejoe.androidtvboilerplate.data;
@Singleton
public class DataManager {
private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
private final PreferencesHelper mPreferencesHelper;
@Inject
public DataManager(PreferencesHelper preferencesHelper,
AndroidTvBoilerplateService androidTvBoilerplateService) {
mPreferencesHelper = preferencesHelper;
mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
}
public PreferencesHelper getPreferencesHelper() {
return mPreferencesHelper;
}
| // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/local/PreferencesHelper.java
// @Singleton
// public class PreferencesHelper {
//
// private final SharedPreferences mPref;
//
// public static final String PREF_FILE_NAME = "tv_boilerplate_pref_file";
// private static final String PREF_KEY_ACCESS_TOKEN = "PREF_KEY_ACCESS_TOKEN";
//
// @Inject
// public PreferencesHelper(@ApplicationContext Context context) {
// mPref = context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
// }
//
// public void clear() {
// mPref.edit().clear().apply();
// }
//
// public void putAccessToken(String accessToken) {
// mPref.edit().putString(PREF_KEY_ACCESS_TOKEN, accessToken).apply();
// }
//
// @Nullable
// public String getAccessToken() {
// return mPref.getString(PREF_KEY_ACCESS_TOKEN, null);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/remote/AndroidTvBoilerplateService.java
// public interface AndroidTvBoilerplateService {
//
// String ENDPOINT = "https://your.endpoint.com/";
//
// /********
// * Helper class that sets up a new services
// *******/
// class Creator {
// public static AndroidTvBoilerplateService newVineyardService() {
// OkHttpClient client = new OkHttpClient();
// client.interceptors().add(new Interceptor() {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Response response = chain.proceed(chain.request());
// // Catch unauthorised error
// return response;
// }
// });
//
// HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
// interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// client.interceptors().add(interceptor);
//
// Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(AndroidTvBoilerplateService.ENDPOINT)
// .client(client)
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .build();
// return retrofit.create(AndroidTvBoilerplateService.class);
// }
// }
//
// }
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
import com.hitherejoe.androidtvboilerplate.data.local.PreferencesHelper;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.data.remote.AndroidTvBoilerplateService;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import rx.Single;
package com.hitherejoe.androidtvboilerplate.data;
@Singleton
public class DataManager {
private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
private final PreferencesHelper mPreferencesHelper;
@Inject
public DataManager(PreferencesHelper preferencesHelper,
AndroidTvBoilerplateService androidTvBoilerplateService) {
mPreferencesHelper = preferencesHelper;
mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
}
public PreferencesHelper getPreferencesHelper() {
return mPreferencesHelper;
}
| public Single<List<Cat>> getCats(List<Cat> cats) { |
hitherejoe/AndroidTvBoilerplate | app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/search/SearchContentPresenter.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/base/BasePresenter.java
// public class BasePresenter<T extends MvpView> implements Presenter<T> {
//
// private T mMvpView;
//
// @Override
// public void attachView(T mvpView) {
// mMvpView = mvpView;
// }
//
// @Override
// public void detachView() {
// mMvpView = null;
// }
//
// public boolean isViewAttached() {
// return mMvpView != null;
// }
//
// public T getMvpView() {
// return mMvpView;
// }
//
// public void checkViewAttached() {
// if (!isViewAttached()) throw new MvpViewNotAttachedException();
// }
//
// public static class MvpViewNotAttachedException extends RuntimeException {
// public MvpViewNotAttachedException() {
// super("Please call Presenter.attachView(MvpView) before" +
// " requesting data to the Presenter");
// }
// }
// }
| import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.ui.base.BasePresenter;
import java.util.List;
import javax.inject.Inject;
import rx.SingleSubscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import timber.log.Timber; | package com.hitherejoe.androidtvboilerplate.ui.search;
public class SearchContentPresenter extends BasePresenter<SearchContentMvpView> {
private Subscription mSubscription; | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/base/BasePresenter.java
// public class BasePresenter<T extends MvpView> implements Presenter<T> {
//
// private T mMvpView;
//
// @Override
// public void attachView(T mvpView) {
// mMvpView = mvpView;
// }
//
// @Override
// public void detachView() {
// mMvpView = null;
// }
//
// public boolean isViewAttached() {
// return mMvpView != null;
// }
//
// public T getMvpView() {
// return mMvpView;
// }
//
// public void checkViewAttached() {
// if (!isViewAttached()) throw new MvpViewNotAttachedException();
// }
//
// public static class MvpViewNotAttachedException extends RuntimeException {
// public MvpViewNotAttachedException() {
// super("Please call Presenter.attachView(MvpView) before" +
// " requesting data to the Presenter");
// }
// }
// }
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/search/SearchContentPresenter.java
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.ui.base.BasePresenter;
import java.util.List;
import javax.inject.Inject;
import rx.SingleSubscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import timber.log.Timber;
package com.hitherejoe.androidtvboilerplate.ui.search;
public class SearchContentPresenter extends BasePresenter<SearchContentMvpView> {
private Subscription mSubscription; | private final DataManager mDataManager; |
hitherejoe/AndroidTvBoilerplate | app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/search/SearchContentPresenter.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/base/BasePresenter.java
// public class BasePresenter<T extends MvpView> implements Presenter<T> {
//
// private T mMvpView;
//
// @Override
// public void attachView(T mvpView) {
// mMvpView = mvpView;
// }
//
// @Override
// public void detachView() {
// mMvpView = null;
// }
//
// public boolean isViewAttached() {
// return mMvpView != null;
// }
//
// public T getMvpView() {
// return mMvpView;
// }
//
// public void checkViewAttached() {
// if (!isViewAttached()) throw new MvpViewNotAttachedException();
// }
//
// public static class MvpViewNotAttachedException extends RuntimeException {
// public MvpViewNotAttachedException() {
// super("Please call Presenter.attachView(MvpView) before" +
// " requesting data to the Presenter");
// }
// }
// }
| import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.ui.base.BasePresenter;
import java.util.List;
import javax.inject.Inject;
import rx.SingleSubscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import timber.log.Timber; | package com.hitherejoe.androidtvboilerplate.ui.search;
public class SearchContentPresenter extends BasePresenter<SearchContentMvpView> {
private Subscription mSubscription;
private final DataManager mDataManager;
@Inject
public SearchContentPresenter(DataManager dataManager) {
mDataManager = dataManager;
}
@Override
public void detachView() {
super.detachView();
if (mSubscription != null) mSubscription.unsubscribe();
}
| // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/base/BasePresenter.java
// public class BasePresenter<T extends MvpView> implements Presenter<T> {
//
// private T mMvpView;
//
// @Override
// public void attachView(T mvpView) {
// mMvpView = mvpView;
// }
//
// @Override
// public void detachView() {
// mMvpView = null;
// }
//
// public boolean isViewAttached() {
// return mMvpView != null;
// }
//
// public T getMvpView() {
// return mMvpView;
// }
//
// public void checkViewAttached() {
// if (!isViewAttached()) throw new MvpViewNotAttachedException();
// }
//
// public static class MvpViewNotAttachedException extends RuntimeException {
// public MvpViewNotAttachedException() {
// super("Please call Presenter.attachView(MvpView) before" +
// " requesting data to the Presenter");
// }
// }
// }
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/search/SearchContentPresenter.java
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.ui.base.BasePresenter;
import java.util.List;
import javax.inject.Inject;
import rx.SingleSubscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import timber.log.Timber;
package com.hitherejoe.androidtvboilerplate.ui.search;
public class SearchContentPresenter extends BasePresenter<SearchContentMvpView> {
private Subscription mSubscription;
private final DataManager mDataManager;
@Inject
public SearchContentPresenter(DataManager dataManager) {
mDataManager = dataManager;
}
@Override
public void detachView() {
super.detachView();
if (mSubscription != null) mSubscription.unsubscribe();
}
| public void searchCats(List<Cat> cats) { |
hitherejoe/AndroidTvBoilerplate | app/src/test/java/com/hitherejoe/androidtvboilerplate/ui/content/ContentPresenterTest.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/util/RxSchedulersOverrideRule.java
// public class RxSchedulersOverrideRule implements TestRule {
//
// private final RxJavaSchedulersHook mRxJavaSchedulersHook = new RxJavaSchedulersHook() {
// @Override
// public Scheduler getIOScheduler() {
// return Schedulers.immediate();
// }
//
// @Override
// public Scheduler getNewThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// private final RxAndroidSchedulersHook mRxAndroidSchedulersHook = new RxAndroidSchedulersHook() {
// @Override
// public Scheduler getMainThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// // Hack to get around RxJavaPlugins.reset() not being public
// // See https://github.com/ReactiveX/RxJava/issues/2297
// // Hopefully the method will be public in new releases of RxAndroid and we can remove the hack.
// private void callResetViaReflectionIn(RxJavaPlugins rxJavaPlugins)
// throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
// Method method = rxJavaPlugins.getClass().getDeclaredMethod("reset");
// method.setAccessible(true);
// method.invoke(rxJavaPlugins);
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// RxAndroidPlugins.getInstance().reset();
// RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook);
//
// base.evaluate();
//
// RxAndroidPlugins.getInstance().reset();
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// }
// };
// }
// }
| import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.util.RxSchedulersOverrideRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.List;
import rx.Single;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; | package com.hitherejoe.androidtvboilerplate.ui.content;
@RunWith(MockitoJUnitRunner.class)
public class ContentPresenterTest {
@Mock ContentMvpView mMockContentMvpView; | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/util/RxSchedulersOverrideRule.java
// public class RxSchedulersOverrideRule implements TestRule {
//
// private final RxJavaSchedulersHook mRxJavaSchedulersHook = new RxJavaSchedulersHook() {
// @Override
// public Scheduler getIOScheduler() {
// return Schedulers.immediate();
// }
//
// @Override
// public Scheduler getNewThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// private final RxAndroidSchedulersHook mRxAndroidSchedulersHook = new RxAndroidSchedulersHook() {
// @Override
// public Scheduler getMainThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// // Hack to get around RxJavaPlugins.reset() not being public
// // See https://github.com/ReactiveX/RxJava/issues/2297
// // Hopefully the method will be public in new releases of RxAndroid and we can remove the hack.
// private void callResetViaReflectionIn(RxJavaPlugins rxJavaPlugins)
// throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
// Method method = rxJavaPlugins.getClass().getDeclaredMethod("reset");
// method.setAccessible(true);
// method.invoke(rxJavaPlugins);
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// RxAndroidPlugins.getInstance().reset();
// RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook);
//
// base.evaluate();
//
// RxAndroidPlugins.getInstance().reset();
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// }
// };
// }
// }
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/ui/content/ContentPresenterTest.java
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.util.RxSchedulersOverrideRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.List;
import rx.Single;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
package com.hitherejoe.androidtvboilerplate.ui.content;
@RunWith(MockitoJUnitRunner.class)
public class ContentPresenterTest {
@Mock ContentMvpView mMockContentMvpView; | @Mock DataManager mMockDataManager; |
hitherejoe/AndroidTvBoilerplate | app/src/test/java/com/hitherejoe/androidtvboilerplate/ui/content/ContentPresenterTest.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/util/RxSchedulersOverrideRule.java
// public class RxSchedulersOverrideRule implements TestRule {
//
// private final RxJavaSchedulersHook mRxJavaSchedulersHook = new RxJavaSchedulersHook() {
// @Override
// public Scheduler getIOScheduler() {
// return Schedulers.immediate();
// }
//
// @Override
// public Scheduler getNewThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// private final RxAndroidSchedulersHook mRxAndroidSchedulersHook = new RxAndroidSchedulersHook() {
// @Override
// public Scheduler getMainThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// // Hack to get around RxJavaPlugins.reset() not being public
// // See https://github.com/ReactiveX/RxJava/issues/2297
// // Hopefully the method will be public in new releases of RxAndroid and we can remove the hack.
// private void callResetViaReflectionIn(RxJavaPlugins rxJavaPlugins)
// throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
// Method method = rxJavaPlugins.getClass().getDeclaredMethod("reset");
// method.setAccessible(true);
// method.invoke(rxJavaPlugins);
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// RxAndroidPlugins.getInstance().reset();
// RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook);
//
// base.evaluate();
//
// RxAndroidPlugins.getInstance().reset();
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// }
// };
// }
// }
| import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.util.RxSchedulersOverrideRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.List;
import rx.Single;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; | package com.hitherejoe.androidtvboilerplate.ui.content;
@RunWith(MockitoJUnitRunner.class)
public class ContentPresenterTest {
@Mock ContentMvpView mMockContentMvpView;
@Mock DataManager mMockDataManager;
private ContentPresenter mContentPresenter;
@Rule | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/util/RxSchedulersOverrideRule.java
// public class RxSchedulersOverrideRule implements TestRule {
//
// private final RxJavaSchedulersHook mRxJavaSchedulersHook = new RxJavaSchedulersHook() {
// @Override
// public Scheduler getIOScheduler() {
// return Schedulers.immediate();
// }
//
// @Override
// public Scheduler getNewThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// private final RxAndroidSchedulersHook mRxAndroidSchedulersHook = new RxAndroidSchedulersHook() {
// @Override
// public Scheduler getMainThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// // Hack to get around RxJavaPlugins.reset() not being public
// // See https://github.com/ReactiveX/RxJava/issues/2297
// // Hopefully the method will be public in new releases of RxAndroid and we can remove the hack.
// private void callResetViaReflectionIn(RxJavaPlugins rxJavaPlugins)
// throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
// Method method = rxJavaPlugins.getClass().getDeclaredMethod("reset");
// method.setAccessible(true);
// method.invoke(rxJavaPlugins);
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// RxAndroidPlugins.getInstance().reset();
// RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook);
//
// base.evaluate();
//
// RxAndroidPlugins.getInstance().reset();
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// }
// };
// }
// }
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/ui/content/ContentPresenterTest.java
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.util.RxSchedulersOverrideRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.List;
import rx.Single;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
package com.hitherejoe.androidtvboilerplate.ui.content;
@RunWith(MockitoJUnitRunner.class)
public class ContentPresenterTest {
@Mock ContentMvpView mMockContentMvpView;
@Mock DataManager mMockDataManager;
private ContentPresenter mContentPresenter;
@Rule | public final RxSchedulersOverrideRule mOverrideSchedulersRule = new RxSchedulersOverrideRule(); |
hitherejoe/AndroidTvBoilerplate | app/src/test/java/com/hitherejoe/androidtvboilerplate/ui/content/ContentPresenterTest.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/util/RxSchedulersOverrideRule.java
// public class RxSchedulersOverrideRule implements TestRule {
//
// private final RxJavaSchedulersHook mRxJavaSchedulersHook = new RxJavaSchedulersHook() {
// @Override
// public Scheduler getIOScheduler() {
// return Schedulers.immediate();
// }
//
// @Override
// public Scheduler getNewThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// private final RxAndroidSchedulersHook mRxAndroidSchedulersHook = new RxAndroidSchedulersHook() {
// @Override
// public Scheduler getMainThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// // Hack to get around RxJavaPlugins.reset() not being public
// // See https://github.com/ReactiveX/RxJava/issues/2297
// // Hopefully the method will be public in new releases of RxAndroid and we can remove the hack.
// private void callResetViaReflectionIn(RxJavaPlugins rxJavaPlugins)
// throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
// Method method = rxJavaPlugins.getClass().getDeclaredMethod("reset");
// method.setAccessible(true);
// method.invoke(rxJavaPlugins);
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// RxAndroidPlugins.getInstance().reset();
// RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook);
//
// base.evaluate();
//
// RxAndroidPlugins.getInstance().reset();
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// }
// };
// }
// }
| import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.util.RxSchedulersOverrideRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.List;
import rx.Single;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; | package com.hitherejoe.androidtvboilerplate.ui.content;
@RunWith(MockitoJUnitRunner.class)
public class ContentPresenterTest {
@Mock ContentMvpView mMockContentMvpView;
@Mock DataManager mMockDataManager;
private ContentPresenter mContentPresenter;
@Rule
public final RxSchedulersOverrideRule mOverrideSchedulersRule = new RxSchedulersOverrideRule();
@Before
public void setUp() {
mContentPresenter = new ContentPresenter(mMockDataManager);
mContentPresenter.attachView(mMockContentMvpView);
}
@After
public void detachView() {
mContentPresenter.detachView();
}
@Test
public void getCatsSuccessful() { | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/util/RxSchedulersOverrideRule.java
// public class RxSchedulersOverrideRule implements TestRule {
//
// private final RxJavaSchedulersHook mRxJavaSchedulersHook = new RxJavaSchedulersHook() {
// @Override
// public Scheduler getIOScheduler() {
// return Schedulers.immediate();
// }
//
// @Override
// public Scheduler getNewThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// private final RxAndroidSchedulersHook mRxAndroidSchedulersHook = new RxAndroidSchedulersHook() {
// @Override
// public Scheduler getMainThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// // Hack to get around RxJavaPlugins.reset() not being public
// // See https://github.com/ReactiveX/RxJava/issues/2297
// // Hopefully the method will be public in new releases of RxAndroid and we can remove the hack.
// private void callResetViaReflectionIn(RxJavaPlugins rxJavaPlugins)
// throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
// Method method = rxJavaPlugins.getClass().getDeclaredMethod("reset");
// method.setAccessible(true);
// method.invoke(rxJavaPlugins);
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// RxAndroidPlugins.getInstance().reset();
// RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook);
//
// base.evaluate();
//
// RxAndroidPlugins.getInstance().reset();
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// }
// };
// }
// }
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/ui/content/ContentPresenterTest.java
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.util.RxSchedulersOverrideRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.List;
import rx.Single;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
package com.hitherejoe.androidtvboilerplate.ui.content;
@RunWith(MockitoJUnitRunner.class)
public class ContentPresenterTest {
@Mock ContentMvpView mMockContentMvpView;
@Mock DataManager mMockDataManager;
private ContentPresenter mContentPresenter;
@Rule
public final RxSchedulersOverrideRule mOverrideSchedulersRule = new RxSchedulersOverrideRule();
@Before
public void setUp() {
mContentPresenter = new ContentPresenter(mMockDataManager);
mContentPresenter.attachView(mMockContentMvpView);
}
@After
public void detachView() {
mContentPresenter.detachView();
}
@Test
public void getCatsSuccessful() { | List<Cat> cats = TestDataFactory.makeCats(10); |
hitherejoe/AndroidTvBoilerplate | app/src/test/java/com/hitherejoe/androidtvboilerplate/ui/content/ContentPresenterTest.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/util/RxSchedulersOverrideRule.java
// public class RxSchedulersOverrideRule implements TestRule {
//
// private final RxJavaSchedulersHook mRxJavaSchedulersHook = new RxJavaSchedulersHook() {
// @Override
// public Scheduler getIOScheduler() {
// return Schedulers.immediate();
// }
//
// @Override
// public Scheduler getNewThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// private final RxAndroidSchedulersHook mRxAndroidSchedulersHook = new RxAndroidSchedulersHook() {
// @Override
// public Scheduler getMainThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// // Hack to get around RxJavaPlugins.reset() not being public
// // See https://github.com/ReactiveX/RxJava/issues/2297
// // Hopefully the method will be public in new releases of RxAndroid and we can remove the hack.
// private void callResetViaReflectionIn(RxJavaPlugins rxJavaPlugins)
// throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
// Method method = rxJavaPlugins.getClass().getDeclaredMethod("reset");
// method.setAccessible(true);
// method.invoke(rxJavaPlugins);
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// RxAndroidPlugins.getInstance().reset();
// RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook);
//
// base.evaluate();
//
// RxAndroidPlugins.getInstance().reset();
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// }
// };
// }
// }
| import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.util.RxSchedulersOverrideRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.List;
import rx.Single;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; | package com.hitherejoe.androidtvboilerplate.ui.content;
@RunWith(MockitoJUnitRunner.class)
public class ContentPresenterTest {
@Mock ContentMvpView mMockContentMvpView;
@Mock DataManager mMockDataManager;
private ContentPresenter mContentPresenter;
@Rule
public final RxSchedulersOverrideRule mOverrideSchedulersRule = new RxSchedulersOverrideRule();
@Before
public void setUp() {
mContentPresenter = new ContentPresenter(mMockDataManager);
mContentPresenter.attachView(mMockContentMvpView);
}
@After
public void detachView() {
mContentPresenter.detachView();
}
@Test
public void getCatsSuccessful() { | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/DataManager.java
// @Singleton
// public class DataManager {
//
// private final AndroidTvBoilerplateService mTvAndroidTvBoilerplateService;
// private final PreferencesHelper mPreferencesHelper;
//
// @Inject
// public DataManager(PreferencesHelper preferencesHelper,
// AndroidTvBoilerplateService androidTvBoilerplateService) {
// mPreferencesHelper = preferencesHelper;
// mTvAndroidTvBoilerplateService = androidTvBoilerplateService;
// }
//
// public PreferencesHelper getPreferencesHelper() {
// return mPreferencesHelper;
// }
//
// public Single<List<Cat>> getCats(List<Cat> cats) {
// // This just for example, usually here we'd make an API request and not pass a useless
// // list of cats back that we passed in!
// return Single.just(cats);
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/util/RxSchedulersOverrideRule.java
// public class RxSchedulersOverrideRule implements TestRule {
//
// private final RxJavaSchedulersHook mRxJavaSchedulersHook = new RxJavaSchedulersHook() {
// @Override
// public Scheduler getIOScheduler() {
// return Schedulers.immediate();
// }
//
// @Override
// public Scheduler getNewThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// private final RxAndroidSchedulersHook mRxAndroidSchedulersHook = new RxAndroidSchedulersHook() {
// @Override
// public Scheduler getMainThreadScheduler() {
// return Schedulers.immediate();
// }
// };
//
// // Hack to get around RxJavaPlugins.reset() not being public
// // See https://github.com/ReactiveX/RxJava/issues/2297
// // Hopefully the method will be public in new releases of RxAndroid and we can remove the hack.
// private void callResetViaReflectionIn(RxJavaPlugins rxJavaPlugins)
// throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
// Method method = rxJavaPlugins.getClass().getDeclaredMethod("reset");
// method.setAccessible(true);
// method.invoke(rxJavaPlugins);
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// RxAndroidPlugins.getInstance().reset();
// RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook);
//
// base.evaluate();
//
// RxAndroidPlugins.getInstance().reset();
// callResetViaReflectionIn(RxJavaPlugins.getInstance());
// }
// };
// }
// }
// Path: app/src/test/java/com/hitherejoe/androidtvboilerplate/ui/content/ContentPresenterTest.java
import com.hitherejoe.androidtvboilerplate.data.DataManager;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.util.RxSchedulersOverrideRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.List;
import rx.Single;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
package com.hitherejoe.androidtvboilerplate.ui.content;
@RunWith(MockitoJUnitRunner.class)
public class ContentPresenterTest {
@Mock ContentMvpView mMockContentMvpView;
@Mock DataManager mMockDataManager;
private ContentPresenter mContentPresenter;
@Rule
public final RxSchedulersOverrideRule mOverrideSchedulersRule = new RxSchedulersOverrideRule();
@Before
public void setUp() {
mContentPresenter = new ContentPresenter(mMockDataManager);
mContentPresenter.attachView(mMockContentMvpView);
}
@After
public void detachView() {
mContentPresenter.detachView();
}
@Test
public void getCatsSuccessful() { | List<Cat> cats = TestDataFactory.makeCats(10); |
hitherejoe/AndroidTvBoilerplate | app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/base/BaseActivity.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/AndroidTvBoilerplateApplication.java
// public class AndroidTvBoilerplateApplication extends Application {
//
// ApplicationComponent mApplicationComponent;
//
// @Override
// public void onCreate() {
// super.onCreate();
// if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree());
//
// mApplicationComponent = DaggerApplicationComponent.builder()
// .applicationModule(new ApplicationModule(this))
// .build();
// }
//
// public static AndroidTvBoilerplateApplication get(Context context) {
// return (AndroidTvBoilerplateApplication) context.getApplicationContext();
// }
//
// // Needed to replace the component with a test specific one
// public void setComponent(ApplicationComponent applicationComponent) {
// mApplicationComponent = applicationComponent;
// }
//
// public ApplicationComponent getComponent() {
// if (mApplicationComponent == null) {
// mApplicationComponent = DaggerApplicationComponent.builder()
// .applicationModule(new ApplicationModule(this))
// .build();
// }
// return mApplicationComponent;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/injection/component/ActivityComponent.java
// @PerActivity
// @Component(dependencies = ApplicationComponent.class, modules = ActivityModule.class)
// public interface ActivityComponent {
//
// void inject(ContentFragment contentFragment);
// void inject(SearchContentFragment searchContentFragment);
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/injection/module/ActivityModule.java
// @Module
// public class ActivityModule {
//
// private Activity mActivity;
//
// public ActivityModule(Activity activity) {
// mActivity = activity;
// }
//
// @Provides
// Activity provideActivity() {
// return mActivity;
// }
//
// @Provides
// @ActivityContext
// Context providesContext() {
// return mActivity;
// }
// }
| import android.app.Activity;
import android.os.Bundle;
import android.view.MenuItem;
import com.hitherejoe.androidtvboilerplate.AndroidTvBoilerplateApplication;
import com.hitherejoe.androidtvboilerplate.injection.component.ActivityComponent;
import com.hitherejoe.androidtvboilerplate.injection.component.DaggerActivityComponent;
import com.hitherejoe.androidtvboilerplate.injection.module.ActivityModule; | package com.hitherejoe.androidtvboilerplate.ui.base;
public class BaseActivity extends Activity {
private ActivityComponent mActivityComponent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public ActivityComponent activityComponent() {
if (mActivityComponent == null) {
mActivityComponent = DaggerActivityComponent.builder() | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/AndroidTvBoilerplateApplication.java
// public class AndroidTvBoilerplateApplication extends Application {
//
// ApplicationComponent mApplicationComponent;
//
// @Override
// public void onCreate() {
// super.onCreate();
// if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree());
//
// mApplicationComponent = DaggerApplicationComponent.builder()
// .applicationModule(new ApplicationModule(this))
// .build();
// }
//
// public static AndroidTvBoilerplateApplication get(Context context) {
// return (AndroidTvBoilerplateApplication) context.getApplicationContext();
// }
//
// // Needed to replace the component with a test specific one
// public void setComponent(ApplicationComponent applicationComponent) {
// mApplicationComponent = applicationComponent;
// }
//
// public ApplicationComponent getComponent() {
// if (mApplicationComponent == null) {
// mApplicationComponent = DaggerApplicationComponent.builder()
// .applicationModule(new ApplicationModule(this))
// .build();
// }
// return mApplicationComponent;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/injection/component/ActivityComponent.java
// @PerActivity
// @Component(dependencies = ApplicationComponent.class, modules = ActivityModule.class)
// public interface ActivityComponent {
//
// void inject(ContentFragment contentFragment);
// void inject(SearchContentFragment searchContentFragment);
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/injection/module/ActivityModule.java
// @Module
// public class ActivityModule {
//
// private Activity mActivity;
//
// public ActivityModule(Activity activity) {
// mActivity = activity;
// }
//
// @Provides
// Activity provideActivity() {
// return mActivity;
// }
//
// @Provides
// @ActivityContext
// Context providesContext() {
// return mActivity;
// }
// }
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/base/BaseActivity.java
import android.app.Activity;
import android.os.Bundle;
import android.view.MenuItem;
import com.hitherejoe.androidtvboilerplate.AndroidTvBoilerplateApplication;
import com.hitherejoe.androidtvboilerplate.injection.component.ActivityComponent;
import com.hitherejoe.androidtvboilerplate.injection.component.DaggerActivityComponent;
import com.hitherejoe.androidtvboilerplate.injection.module.ActivityModule;
package com.hitherejoe.androidtvboilerplate.ui.base;
public class BaseActivity extends Activity {
private ActivityComponent mActivityComponent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public ActivityComponent activityComponent() {
if (mActivityComponent == null) {
mActivityComponent = DaggerActivityComponent.builder() | .activityModule(new ActivityModule(this)) |
hitherejoe/AndroidTvBoilerplate | app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/base/BaseActivity.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/AndroidTvBoilerplateApplication.java
// public class AndroidTvBoilerplateApplication extends Application {
//
// ApplicationComponent mApplicationComponent;
//
// @Override
// public void onCreate() {
// super.onCreate();
// if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree());
//
// mApplicationComponent = DaggerApplicationComponent.builder()
// .applicationModule(new ApplicationModule(this))
// .build();
// }
//
// public static AndroidTvBoilerplateApplication get(Context context) {
// return (AndroidTvBoilerplateApplication) context.getApplicationContext();
// }
//
// // Needed to replace the component with a test specific one
// public void setComponent(ApplicationComponent applicationComponent) {
// mApplicationComponent = applicationComponent;
// }
//
// public ApplicationComponent getComponent() {
// if (mApplicationComponent == null) {
// mApplicationComponent = DaggerApplicationComponent.builder()
// .applicationModule(new ApplicationModule(this))
// .build();
// }
// return mApplicationComponent;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/injection/component/ActivityComponent.java
// @PerActivity
// @Component(dependencies = ApplicationComponent.class, modules = ActivityModule.class)
// public interface ActivityComponent {
//
// void inject(ContentFragment contentFragment);
// void inject(SearchContentFragment searchContentFragment);
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/injection/module/ActivityModule.java
// @Module
// public class ActivityModule {
//
// private Activity mActivity;
//
// public ActivityModule(Activity activity) {
// mActivity = activity;
// }
//
// @Provides
// Activity provideActivity() {
// return mActivity;
// }
//
// @Provides
// @ActivityContext
// Context providesContext() {
// return mActivity;
// }
// }
| import android.app.Activity;
import android.os.Bundle;
import android.view.MenuItem;
import com.hitherejoe.androidtvboilerplate.AndroidTvBoilerplateApplication;
import com.hitherejoe.androidtvboilerplate.injection.component.ActivityComponent;
import com.hitherejoe.androidtvboilerplate.injection.component.DaggerActivityComponent;
import com.hitherejoe.androidtvboilerplate.injection.module.ActivityModule; | package com.hitherejoe.androidtvboilerplate.ui.base;
public class BaseActivity extends Activity {
private ActivityComponent mActivityComponent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public ActivityComponent activityComponent() {
if (mActivityComponent == null) {
mActivityComponent = DaggerActivityComponent.builder()
.activityModule(new ActivityModule(this)) | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/AndroidTvBoilerplateApplication.java
// public class AndroidTvBoilerplateApplication extends Application {
//
// ApplicationComponent mApplicationComponent;
//
// @Override
// public void onCreate() {
// super.onCreate();
// if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree());
//
// mApplicationComponent = DaggerApplicationComponent.builder()
// .applicationModule(new ApplicationModule(this))
// .build();
// }
//
// public static AndroidTvBoilerplateApplication get(Context context) {
// return (AndroidTvBoilerplateApplication) context.getApplicationContext();
// }
//
// // Needed to replace the component with a test specific one
// public void setComponent(ApplicationComponent applicationComponent) {
// mApplicationComponent = applicationComponent;
// }
//
// public ApplicationComponent getComponent() {
// if (mApplicationComponent == null) {
// mApplicationComponent = DaggerApplicationComponent.builder()
// .applicationModule(new ApplicationModule(this))
// .build();
// }
// return mApplicationComponent;
// }
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/injection/component/ActivityComponent.java
// @PerActivity
// @Component(dependencies = ApplicationComponent.class, modules = ActivityModule.class)
// public interface ActivityComponent {
//
// void inject(ContentFragment contentFragment);
// void inject(SearchContentFragment searchContentFragment);
//
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/injection/module/ActivityModule.java
// @Module
// public class ActivityModule {
//
// private Activity mActivity;
//
// public ActivityModule(Activity activity) {
// mActivity = activity;
// }
//
// @Provides
// Activity provideActivity() {
// return mActivity;
// }
//
// @Provides
// @ActivityContext
// Context providesContext() {
// return mActivity;
// }
// }
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/base/BaseActivity.java
import android.app.Activity;
import android.os.Bundle;
import android.view.MenuItem;
import com.hitherejoe.androidtvboilerplate.AndroidTvBoilerplateApplication;
import com.hitherejoe.androidtvboilerplate.injection.component.ActivityComponent;
import com.hitherejoe.androidtvboilerplate.injection.component.DaggerActivityComponent;
import com.hitherejoe.androidtvboilerplate.injection.module.ActivityModule;
package com.hitherejoe.androidtvboilerplate.ui.base;
public class BaseActivity extends Activity {
private ActivityComponent mActivityComponent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public ActivityComponent activityComponent() {
if (mActivityComponent == null) {
mActivityComponent = DaggerActivityComponent.builder()
.activityModule(new ActivityModule(this)) | .applicationComponent(AndroidTvBoilerplateApplication.get(this).getComponent()) |
hitherejoe/AndroidTvBoilerplate | app/src/main/java/com/hitherejoe/androidtvboilerplate/injection/module/ApplicationModule.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/remote/AndroidTvBoilerplateService.java
// public interface AndroidTvBoilerplateService {
//
// String ENDPOINT = "https://your.endpoint.com/";
//
// /********
// * Helper class that sets up a new services
// *******/
// class Creator {
// public static AndroidTvBoilerplateService newVineyardService() {
// OkHttpClient client = new OkHttpClient();
// client.interceptors().add(new Interceptor() {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Response response = chain.proceed(chain.request());
// // Catch unauthorised error
// return response;
// }
// });
//
// HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
// interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// client.interceptors().add(interceptor);
//
// Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(AndroidTvBoilerplateService.ENDPOINT)
// .client(client)
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .build();
// return retrofit.create(AndroidTvBoilerplateService.class);
// }
// }
//
// }
| import android.app.Application;
import android.content.Context;
import com.hitherejoe.androidtvboilerplate.data.remote.AndroidTvBoilerplateService;
import com.hitherejoe.androidtvboilerplate.injection.ApplicationContext;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import rx.subscriptions.CompositeSubscription; | package com.hitherejoe.androidtvboilerplate.injection.module;
/**
* Provide application-level dependencies. Mainly singleton object that can be injected from
* anywhere in the app.
*/
@Module
public class ApplicationModule {
protected final Application mApplication;
public ApplicationModule(Application application) {
mApplication = application;
}
@Provides
@ApplicationContext
Context provideContext() {
return mApplication;
}
@Provides
@Singleton
Application provideApplication() {
return mApplication;
}
@Provides
CompositeSubscription provideCompositeSubscription() {
return new CompositeSubscription();
}
@Provides
@Singleton | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/remote/AndroidTvBoilerplateService.java
// public interface AndroidTvBoilerplateService {
//
// String ENDPOINT = "https://your.endpoint.com/";
//
// /********
// * Helper class that sets up a new services
// *******/
// class Creator {
// public static AndroidTvBoilerplateService newVineyardService() {
// OkHttpClient client = new OkHttpClient();
// client.interceptors().add(new Interceptor() {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Response response = chain.proceed(chain.request());
// // Catch unauthorised error
// return response;
// }
// });
//
// HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
// interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// client.interceptors().add(interceptor);
//
// Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(AndroidTvBoilerplateService.ENDPOINT)
// .client(client)
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .build();
// return retrofit.create(AndroidTvBoilerplateService.class);
// }
// }
//
// }
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/injection/module/ApplicationModule.java
import android.app.Application;
import android.content.Context;
import com.hitherejoe.androidtvboilerplate.data.remote.AndroidTvBoilerplateService;
import com.hitherejoe.androidtvboilerplate.injection.ApplicationContext;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import rx.subscriptions.CompositeSubscription;
package com.hitherejoe.androidtvboilerplate.injection.module;
/**
* Provide application-level dependencies. Mainly singleton object that can be injected from
* anywhere in the app.
*/
@Module
public class ApplicationModule {
protected final Application mApplication;
public ApplicationModule(Application application) {
mApplication = application;
}
@Provides
@ApplicationContext
Context provideContext() {
return mApplication;
}
@Provides
@Singleton
Application provideApplication() {
return mApplication;
}
@Provides
CompositeSubscription provideCompositeSubscription() {
return new CompositeSubscription();
}
@Provides
@Singleton | AndroidTvBoilerplateService provideVineyardService() { |
hitherejoe/AndroidTvBoilerplate | app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/ContentActivityTest.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java
// public class TestComponentRule implements TestRule {
//
// private final TestComponent mTestComponent;
// private final Context mContext;
//
// public TestComponentRule(Context context) {
// mContext = context;
// AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context);
// mTestComponent = DaggerTestComponent.builder()
// .applicationTestModule(new ApplicationTestModule(application))
// .build();
// }
//
// public Context getContext() {
// return mContext;
// }
//
// public DataManager getMockDataManager() {
// return mTestComponent.dataManager();
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// AndroidTvBoilerplateApplication application =
// AndroidTvBoilerplateApplication.get(mContext);
// application.setComponent(mTestComponent);
// base.evaluate();
// application.setComponent(null);
// }
// };
// }
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/content/ContentActivity.java
// public class ContentActivity extends BaseActivity {
//
// @Bind(R.id.frame_container) FrameLayout mFragmentContainer;
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
// ButterKnife.bind(this);
//
// getFragmentManager().beginTransaction()
// .replace(mFragmentContainer.getId(), ContentFragment.newInstance()).commit();
// }
//
// @Override
// public boolean onSearchRequested() {
// startActivity(SearchContentActivity.getStartIntent(this));
// return true;
// }
//
// }
//
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/util/CustomMatchers.java
// public static Matcher<View> withItemText(final String itemText, final int parentId) {
// checkArgument(!TextUtils.isEmpty(itemText), "itemText cannot be null or empty");
// return new TypeSafeMatcher<View>() {
// @Override
// public boolean matchesSafely(View item) {
// return allOf(isDescendantOfA(withId(parentId)),
// withText(itemText)).matches(item);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("is isDescendantOfA RecyclerView with text " + itemText);
// }
// };
// }
| import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.contrib.RecyclerViewActions;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.test.common.rules.TestComponentRule;
import com.hitherejoe.androidtvboilerplate.ui.content.ContentActivity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import java.util.List;
import rx.Single;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.hitherejoe.androidtvboilerplate.util.CustomMatchers.withItemText;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.when; | package com.hitherejoe.androidtvboilerplate;
@RunWith(AndroidJUnit4.class)
public class ContentActivityTest {
| // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java
// public class TestComponentRule implements TestRule {
//
// private final TestComponent mTestComponent;
// private final Context mContext;
//
// public TestComponentRule(Context context) {
// mContext = context;
// AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context);
// mTestComponent = DaggerTestComponent.builder()
// .applicationTestModule(new ApplicationTestModule(application))
// .build();
// }
//
// public Context getContext() {
// return mContext;
// }
//
// public DataManager getMockDataManager() {
// return mTestComponent.dataManager();
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// AndroidTvBoilerplateApplication application =
// AndroidTvBoilerplateApplication.get(mContext);
// application.setComponent(mTestComponent);
// base.evaluate();
// application.setComponent(null);
// }
// };
// }
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/content/ContentActivity.java
// public class ContentActivity extends BaseActivity {
//
// @Bind(R.id.frame_container) FrameLayout mFragmentContainer;
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
// ButterKnife.bind(this);
//
// getFragmentManager().beginTransaction()
// .replace(mFragmentContainer.getId(), ContentFragment.newInstance()).commit();
// }
//
// @Override
// public boolean onSearchRequested() {
// startActivity(SearchContentActivity.getStartIntent(this));
// return true;
// }
//
// }
//
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/util/CustomMatchers.java
// public static Matcher<View> withItemText(final String itemText, final int parentId) {
// checkArgument(!TextUtils.isEmpty(itemText), "itemText cannot be null or empty");
// return new TypeSafeMatcher<View>() {
// @Override
// public boolean matchesSafely(View item) {
// return allOf(isDescendantOfA(withId(parentId)),
// withText(itemText)).matches(item);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("is isDescendantOfA RecyclerView with text " + itemText);
// }
// };
// }
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/ContentActivityTest.java
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.contrib.RecyclerViewActions;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.test.common.rules.TestComponentRule;
import com.hitherejoe.androidtvboilerplate.ui.content.ContentActivity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import java.util.List;
import rx.Single;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.hitherejoe.androidtvboilerplate.util.CustomMatchers.withItemText;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.when;
package com.hitherejoe.androidtvboilerplate;
@RunWith(AndroidJUnit4.class)
public class ContentActivityTest {
| public final TestComponentRule component = |
hitherejoe/AndroidTvBoilerplate | app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/ContentActivityTest.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java
// public class TestComponentRule implements TestRule {
//
// private final TestComponent mTestComponent;
// private final Context mContext;
//
// public TestComponentRule(Context context) {
// mContext = context;
// AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context);
// mTestComponent = DaggerTestComponent.builder()
// .applicationTestModule(new ApplicationTestModule(application))
// .build();
// }
//
// public Context getContext() {
// return mContext;
// }
//
// public DataManager getMockDataManager() {
// return mTestComponent.dataManager();
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// AndroidTvBoilerplateApplication application =
// AndroidTvBoilerplateApplication.get(mContext);
// application.setComponent(mTestComponent);
// base.evaluate();
// application.setComponent(null);
// }
// };
// }
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/content/ContentActivity.java
// public class ContentActivity extends BaseActivity {
//
// @Bind(R.id.frame_container) FrameLayout mFragmentContainer;
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
// ButterKnife.bind(this);
//
// getFragmentManager().beginTransaction()
// .replace(mFragmentContainer.getId(), ContentFragment.newInstance()).commit();
// }
//
// @Override
// public boolean onSearchRequested() {
// startActivity(SearchContentActivity.getStartIntent(this));
// return true;
// }
//
// }
//
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/util/CustomMatchers.java
// public static Matcher<View> withItemText(final String itemText, final int parentId) {
// checkArgument(!TextUtils.isEmpty(itemText), "itemText cannot be null or empty");
// return new TypeSafeMatcher<View>() {
// @Override
// public boolean matchesSafely(View item) {
// return allOf(isDescendantOfA(withId(parentId)),
// withText(itemText)).matches(item);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("is isDescendantOfA RecyclerView with text " + itemText);
// }
// };
// }
| import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.contrib.RecyclerViewActions;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.test.common.rules.TestComponentRule;
import com.hitherejoe.androidtvboilerplate.ui.content.ContentActivity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import java.util.List;
import rx.Single;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.hitherejoe.androidtvboilerplate.util.CustomMatchers.withItemText;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.when; | package com.hitherejoe.androidtvboilerplate;
@RunWith(AndroidJUnit4.class)
public class ContentActivityTest {
public final TestComponentRule component =
new TestComponentRule(InstrumentationRegistry.getTargetContext()); | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java
// public class TestComponentRule implements TestRule {
//
// private final TestComponent mTestComponent;
// private final Context mContext;
//
// public TestComponentRule(Context context) {
// mContext = context;
// AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context);
// mTestComponent = DaggerTestComponent.builder()
// .applicationTestModule(new ApplicationTestModule(application))
// .build();
// }
//
// public Context getContext() {
// return mContext;
// }
//
// public DataManager getMockDataManager() {
// return mTestComponent.dataManager();
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// AndroidTvBoilerplateApplication application =
// AndroidTvBoilerplateApplication.get(mContext);
// application.setComponent(mTestComponent);
// base.evaluate();
// application.setComponent(null);
// }
// };
// }
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/content/ContentActivity.java
// public class ContentActivity extends BaseActivity {
//
// @Bind(R.id.frame_container) FrameLayout mFragmentContainer;
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
// ButterKnife.bind(this);
//
// getFragmentManager().beginTransaction()
// .replace(mFragmentContainer.getId(), ContentFragment.newInstance()).commit();
// }
//
// @Override
// public boolean onSearchRequested() {
// startActivity(SearchContentActivity.getStartIntent(this));
// return true;
// }
//
// }
//
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/util/CustomMatchers.java
// public static Matcher<View> withItemText(final String itemText, final int parentId) {
// checkArgument(!TextUtils.isEmpty(itemText), "itemText cannot be null or empty");
// return new TypeSafeMatcher<View>() {
// @Override
// public boolean matchesSafely(View item) {
// return allOf(isDescendantOfA(withId(parentId)),
// withText(itemText)).matches(item);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("is isDescendantOfA RecyclerView with text " + itemText);
// }
// };
// }
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/ContentActivityTest.java
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.contrib.RecyclerViewActions;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.test.common.rules.TestComponentRule;
import com.hitherejoe.androidtvboilerplate.ui.content.ContentActivity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import java.util.List;
import rx.Single;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.hitherejoe.androidtvboilerplate.util.CustomMatchers.withItemText;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.when;
package com.hitherejoe.androidtvboilerplate;
@RunWith(AndroidJUnit4.class)
public class ContentActivityTest {
public final TestComponentRule component =
new TestComponentRule(InstrumentationRegistry.getTargetContext()); | public final ActivityTestRule<ContentActivity> main = |
hitherejoe/AndroidTvBoilerplate | app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/ContentActivityTest.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java
// public class TestComponentRule implements TestRule {
//
// private final TestComponent mTestComponent;
// private final Context mContext;
//
// public TestComponentRule(Context context) {
// mContext = context;
// AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context);
// mTestComponent = DaggerTestComponent.builder()
// .applicationTestModule(new ApplicationTestModule(application))
// .build();
// }
//
// public Context getContext() {
// return mContext;
// }
//
// public DataManager getMockDataManager() {
// return mTestComponent.dataManager();
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// AndroidTvBoilerplateApplication application =
// AndroidTvBoilerplateApplication.get(mContext);
// application.setComponent(mTestComponent);
// base.evaluate();
// application.setComponent(null);
// }
// };
// }
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/content/ContentActivity.java
// public class ContentActivity extends BaseActivity {
//
// @Bind(R.id.frame_container) FrameLayout mFragmentContainer;
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
// ButterKnife.bind(this);
//
// getFragmentManager().beginTransaction()
// .replace(mFragmentContainer.getId(), ContentFragment.newInstance()).commit();
// }
//
// @Override
// public boolean onSearchRequested() {
// startActivity(SearchContentActivity.getStartIntent(this));
// return true;
// }
//
// }
//
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/util/CustomMatchers.java
// public static Matcher<View> withItemText(final String itemText, final int parentId) {
// checkArgument(!TextUtils.isEmpty(itemText), "itemText cannot be null or empty");
// return new TypeSafeMatcher<View>() {
// @Override
// public boolean matchesSafely(View item) {
// return allOf(isDescendantOfA(withId(parentId)),
// withText(itemText)).matches(item);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("is isDescendantOfA RecyclerView with text " + itemText);
// }
// };
// }
| import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.contrib.RecyclerViewActions;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.test.common.rules.TestComponentRule;
import com.hitherejoe.androidtvboilerplate.ui.content.ContentActivity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import java.util.List;
import rx.Single;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.hitherejoe.androidtvboilerplate.util.CustomMatchers.withItemText;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.when; | package com.hitherejoe.androidtvboilerplate;
@RunWith(AndroidJUnit4.class)
public class ContentActivityTest {
public final TestComponentRule component =
new TestComponentRule(InstrumentationRegistry.getTargetContext());
public final ActivityTestRule<ContentActivity> main =
new ActivityTestRule<>(ContentActivity.class, false, false);
@Rule
public final TestRule chain = RuleChain.outerRule(component).around(main);
@Test
public void postsDisplayAndAreBrowseable() { | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java
// public class TestComponentRule implements TestRule {
//
// private final TestComponent mTestComponent;
// private final Context mContext;
//
// public TestComponentRule(Context context) {
// mContext = context;
// AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context);
// mTestComponent = DaggerTestComponent.builder()
// .applicationTestModule(new ApplicationTestModule(application))
// .build();
// }
//
// public Context getContext() {
// return mContext;
// }
//
// public DataManager getMockDataManager() {
// return mTestComponent.dataManager();
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// AndroidTvBoilerplateApplication application =
// AndroidTvBoilerplateApplication.get(mContext);
// application.setComponent(mTestComponent);
// base.evaluate();
// application.setComponent(null);
// }
// };
// }
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/content/ContentActivity.java
// public class ContentActivity extends BaseActivity {
//
// @Bind(R.id.frame_container) FrameLayout mFragmentContainer;
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
// ButterKnife.bind(this);
//
// getFragmentManager().beginTransaction()
// .replace(mFragmentContainer.getId(), ContentFragment.newInstance()).commit();
// }
//
// @Override
// public boolean onSearchRequested() {
// startActivity(SearchContentActivity.getStartIntent(this));
// return true;
// }
//
// }
//
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/util/CustomMatchers.java
// public static Matcher<View> withItemText(final String itemText, final int parentId) {
// checkArgument(!TextUtils.isEmpty(itemText), "itemText cannot be null or empty");
// return new TypeSafeMatcher<View>() {
// @Override
// public boolean matchesSafely(View item) {
// return allOf(isDescendantOfA(withId(parentId)),
// withText(itemText)).matches(item);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("is isDescendantOfA RecyclerView with text " + itemText);
// }
// };
// }
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/ContentActivityTest.java
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.contrib.RecyclerViewActions;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.test.common.rules.TestComponentRule;
import com.hitherejoe.androidtvboilerplate.ui.content.ContentActivity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import java.util.List;
import rx.Single;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.hitherejoe.androidtvboilerplate.util.CustomMatchers.withItemText;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.when;
package com.hitherejoe.androidtvboilerplate;
@RunWith(AndroidJUnit4.class)
public class ContentActivityTest {
public final TestComponentRule component =
new TestComponentRule(InstrumentationRegistry.getTargetContext());
public final ActivityTestRule<ContentActivity> main =
new ActivityTestRule<>(ContentActivity.class, false, false);
@Rule
public final TestRule chain = RuleChain.outerRule(component).around(main);
@Test
public void postsDisplayAndAreBrowseable() { | List<Cat> mockcats = TestDataFactory.makeCats(5); |
hitherejoe/AndroidTvBoilerplate | app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/ContentActivityTest.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java
// public class TestComponentRule implements TestRule {
//
// private final TestComponent mTestComponent;
// private final Context mContext;
//
// public TestComponentRule(Context context) {
// mContext = context;
// AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context);
// mTestComponent = DaggerTestComponent.builder()
// .applicationTestModule(new ApplicationTestModule(application))
// .build();
// }
//
// public Context getContext() {
// return mContext;
// }
//
// public DataManager getMockDataManager() {
// return mTestComponent.dataManager();
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// AndroidTvBoilerplateApplication application =
// AndroidTvBoilerplateApplication.get(mContext);
// application.setComponent(mTestComponent);
// base.evaluate();
// application.setComponent(null);
// }
// };
// }
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/content/ContentActivity.java
// public class ContentActivity extends BaseActivity {
//
// @Bind(R.id.frame_container) FrameLayout mFragmentContainer;
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
// ButterKnife.bind(this);
//
// getFragmentManager().beginTransaction()
// .replace(mFragmentContainer.getId(), ContentFragment.newInstance()).commit();
// }
//
// @Override
// public boolean onSearchRequested() {
// startActivity(SearchContentActivity.getStartIntent(this));
// return true;
// }
//
// }
//
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/util/CustomMatchers.java
// public static Matcher<View> withItemText(final String itemText, final int parentId) {
// checkArgument(!TextUtils.isEmpty(itemText), "itemText cannot be null or empty");
// return new TypeSafeMatcher<View>() {
// @Override
// public boolean matchesSafely(View item) {
// return allOf(isDescendantOfA(withId(parentId)),
// withText(itemText)).matches(item);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("is isDescendantOfA RecyclerView with text " + itemText);
// }
// };
// }
| import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.contrib.RecyclerViewActions;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.test.common.rules.TestComponentRule;
import com.hitherejoe.androidtvboilerplate.ui.content.ContentActivity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import java.util.List;
import rx.Single;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.hitherejoe.androidtvboilerplate.util.CustomMatchers.withItemText;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.when; | package com.hitherejoe.androidtvboilerplate;
@RunWith(AndroidJUnit4.class)
public class ContentActivityTest {
public final TestComponentRule component =
new TestComponentRule(InstrumentationRegistry.getTargetContext());
public final ActivityTestRule<ContentActivity> main =
new ActivityTestRule<>(ContentActivity.class, false, false);
@Rule
public final TestRule chain = RuleChain.outerRule(component).around(main);
@Test
public void postsDisplayAndAreBrowseable() { | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java
// public class TestComponentRule implements TestRule {
//
// private final TestComponent mTestComponent;
// private final Context mContext;
//
// public TestComponentRule(Context context) {
// mContext = context;
// AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context);
// mTestComponent = DaggerTestComponent.builder()
// .applicationTestModule(new ApplicationTestModule(application))
// .build();
// }
//
// public Context getContext() {
// return mContext;
// }
//
// public DataManager getMockDataManager() {
// return mTestComponent.dataManager();
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// AndroidTvBoilerplateApplication application =
// AndroidTvBoilerplateApplication.get(mContext);
// application.setComponent(mTestComponent);
// base.evaluate();
// application.setComponent(null);
// }
// };
// }
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/content/ContentActivity.java
// public class ContentActivity extends BaseActivity {
//
// @Bind(R.id.frame_container) FrameLayout mFragmentContainer;
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
// ButterKnife.bind(this);
//
// getFragmentManager().beginTransaction()
// .replace(mFragmentContainer.getId(), ContentFragment.newInstance()).commit();
// }
//
// @Override
// public boolean onSearchRequested() {
// startActivity(SearchContentActivity.getStartIntent(this));
// return true;
// }
//
// }
//
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/util/CustomMatchers.java
// public static Matcher<View> withItemText(final String itemText, final int parentId) {
// checkArgument(!TextUtils.isEmpty(itemText), "itemText cannot be null or empty");
// return new TypeSafeMatcher<View>() {
// @Override
// public boolean matchesSafely(View item) {
// return allOf(isDescendantOfA(withId(parentId)),
// withText(itemText)).matches(item);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("is isDescendantOfA RecyclerView with text " + itemText);
// }
// };
// }
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/ContentActivityTest.java
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.contrib.RecyclerViewActions;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.test.common.rules.TestComponentRule;
import com.hitherejoe.androidtvboilerplate.ui.content.ContentActivity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import java.util.List;
import rx.Single;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.hitherejoe.androidtvboilerplate.util.CustomMatchers.withItemText;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.when;
package com.hitherejoe.androidtvboilerplate;
@RunWith(AndroidJUnit4.class)
public class ContentActivityTest {
public final TestComponentRule component =
new TestComponentRule(InstrumentationRegistry.getTargetContext());
public final ActivityTestRule<ContentActivity> main =
new ActivityTestRule<>(ContentActivity.class, false, false);
@Rule
public final TestRule chain = RuleChain.outerRule(component).around(main);
@Test
public void postsDisplayAndAreBrowseable() { | List<Cat> mockcats = TestDataFactory.makeCats(5); |
hitherejoe/AndroidTvBoilerplate | app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/ContentActivityTest.java | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java
// public class TestComponentRule implements TestRule {
//
// private final TestComponent mTestComponent;
// private final Context mContext;
//
// public TestComponentRule(Context context) {
// mContext = context;
// AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context);
// mTestComponent = DaggerTestComponent.builder()
// .applicationTestModule(new ApplicationTestModule(application))
// .build();
// }
//
// public Context getContext() {
// return mContext;
// }
//
// public DataManager getMockDataManager() {
// return mTestComponent.dataManager();
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// AndroidTvBoilerplateApplication application =
// AndroidTvBoilerplateApplication.get(mContext);
// application.setComponent(mTestComponent);
// base.evaluate();
// application.setComponent(null);
// }
// };
// }
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/content/ContentActivity.java
// public class ContentActivity extends BaseActivity {
//
// @Bind(R.id.frame_container) FrameLayout mFragmentContainer;
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
// ButterKnife.bind(this);
//
// getFragmentManager().beginTransaction()
// .replace(mFragmentContainer.getId(), ContentFragment.newInstance()).commit();
// }
//
// @Override
// public boolean onSearchRequested() {
// startActivity(SearchContentActivity.getStartIntent(this));
// return true;
// }
//
// }
//
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/util/CustomMatchers.java
// public static Matcher<View> withItemText(final String itemText, final int parentId) {
// checkArgument(!TextUtils.isEmpty(itemText), "itemText cannot be null or empty");
// return new TypeSafeMatcher<View>() {
// @Override
// public boolean matchesSafely(View item) {
// return allOf(isDescendantOfA(withId(parentId)),
// withText(itemText)).matches(item);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("is isDescendantOfA RecyclerView with text " + itemText);
// }
// };
// }
| import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.contrib.RecyclerViewActions;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.test.common.rules.TestComponentRule;
import com.hitherejoe.androidtvboilerplate.ui.content.ContentActivity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import java.util.List;
import rx.Single;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.hitherejoe.androidtvboilerplate.util.CustomMatchers.withItemText;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.when; | package com.hitherejoe.androidtvboilerplate;
@RunWith(AndroidJUnit4.class)
public class ContentActivityTest {
public final TestComponentRule component =
new TestComponentRule(InstrumentationRegistry.getTargetContext());
public final ActivityTestRule<ContentActivity> main =
new ActivityTestRule<>(ContentActivity.class, false, false);
@Rule
public final TestRule chain = RuleChain.outerRule(component).around(main);
@Test
public void postsDisplayAndAreBrowseable() {
List<Cat> mockcats = TestDataFactory.makeCats(5);
stubDataManagerGetCats(Single.just(mockcats));
main.launchActivity(null);
onView(withId(R.id.browse_headers))
.perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));
for (int i = 0; i < mockcats.size(); i++) {
checkItemAtPosition(mockcats.get(i), i);
}
}
private void checkItemAtPosition(Cat cat, int position) {
if (position > 0) { | // Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/data/model/Cat.java
// public class Cat {
// public String name;
// public String description;
// public String imageUrl;
//
// public Cat() {
//
// }
//
// public Cat(String name, String description, String imageUrl) {
// this.name = name;
// this.description = description;
// this.imageUrl = imageUrl;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/TestDataFactory.java
// public class TestDataFactory {
//
// public static String generateRandomString() {
// return UUID.randomUUID().toString().substring(0, 5);
// }
//
// public static Cat makeCat(String unique) {
// Cat cat = new Cat();
// cat.name = "Name " + unique;
// cat.description = "Description " + unique;
// cat.imageUrl = generateRandomString();
// return cat;
// }
//
// public static List<Cat> makeCats(int count) {
// List<Cat> cats = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// cats.add(makeCat(String.valueOf(i)));
// }
// return cats;
// }
//
// }
//
// Path: app/src/commonTest/java/com/hitherejoe/androidtvboilerplate/test/common/rules/TestComponentRule.java
// public class TestComponentRule implements TestRule {
//
// private final TestComponent mTestComponent;
// private final Context mContext;
//
// public TestComponentRule(Context context) {
// mContext = context;
// AndroidTvBoilerplateApplication application = AndroidTvBoilerplateApplication.get(context);
// mTestComponent = DaggerTestComponent.builder()
// .applicationTestModule(new ApplicationTestModule(application))
// .build();
// }
//
// public Context getContext() {
// return mContext;
// }
//
// public DataManager getMockDataManager() {
// return mTestComponent.dataManager();
// }
//
// @Override
// public Statement apply(final Statement base, Description description) {
// return new Statement() {
// @Override
// public void evaluate() throws Throwable {
// AndroidTvBoilerplateApplication application =
// AndroidTvBoilerplateApplication.get(mContext);
// application.setComponent(mTestComponent);
// base.evaluate();
// application.setComponent(null);
// }
// };
// }
// }
//
// Path: app/src/main/java/com/hitherejoe/androidtvboilerplate/ui/content/ContentActivity.java
// public class ContentActivity extends BaseActivity {
//
// @Bind(R.id.frame_container) FrameLayout mFragmentContainer;
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
// ButterKnife.bind(this);
//
// getFragmentManager().beginTransaction()
// .replace(mFragmentContainer.getId(), ContentFragment.newInstance()).commit();
// }
//
// @Override
// public boolean onSearchRequested() {
// startActivity(SearchContentActivity.getStartIntent(this));
// return true;
// }
//
// }
//
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/util/CustomMatchers.java
// public static Matcher<View> withItemText(final String itemText, final int parentId) {
// checkArgument(!TextUtils.isEmpty(itemText), "itemText cannot be null or empty");
// return new TypeSafeMatcher<View>() {
// @Override
// public boolean matchesSafely(View item) {
// return allOf(isDescendantOfA(withId(parentId)),
// withText(itemText)).matches(item);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("is isDescendantOfA RecyclerView with text " + itemText);
// }
// };
// }
// Path: app/src/androidTest/java/com/hitherejoe/androidtvboilerplate/ContentActivityTest.java
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.contrib.RecyclerViewActions;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.hitherejoe.androidtvboilerplate.data.model.Cat;
import com.hitherejoe.androidtvboilerplate.test.common.TestDataFactory;
import com.hitherejoe.androidtvboilerplate.test.common.rules.TestComponentRule;
import com.hitherejoe.androidtvboilerplate.ui.content.ContentActivity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import java.util.List;
import rx.Single;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.hitherejoe.androidtvboilerplate.util.CustomMatchers.withItemText;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.when;
package com.hitherejoe.androidtvboilerplate;
@RunWith(AndroidJUnit4.class)
public class ContentActivityTest {
public final TestComponentRule component =
new TestComponentRule(InstrumentationRegistry.getTargetContext());
public final ActivityTestRule<ContentActivity> main =
new ActivityTestRule<>(ContentActivity.class, false, false);
@Rule
public final TestRule chain = RuleChain.outerRule(component).around(main);
@Test
public void postsDisplayAndAreBrowseable() {
List<Cat> mockcats = TestDataFactory.makeCats(5);
stubDataManagerGetCats(Single.just(mockcats));
main.launchActivity(null);
onView(withId(R.id.browse_headers))
.perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));
for (int i = 0; i < mockcats.size(); i++) {
checkItemAtPosition(mockcats.get(i), i);
}
}
private void checkItemAtPosition(Cat cat, int position) {
if (position > 0) { | onView(withItemText(cat.name, R.id.browse_container_dock)).perform(click()); |
nwaldispuehl/java-lame | src/main/java/net/sourceforge/lame/mp3/LongBlockConstrain.java | // Path: src/main/java/net/sourceforge/lame/mp3/VBRQuantize.java
// protected static class algo_t {
// alloc_sf_f alloc;
// float[] xr34orig;
// LameInternalFlags gfc;
// GrInfo cod_info;
// int mingain_l;
// int mingain_s[] = new int[3];
// }
| import net.sourceforge.lame.mp3.VBRQuantize.algo_t;
| package net.sourceforge.lame.mp3;
final class LongBlockConstrain implements VBRQuantize.alloc_sf_f {
/**
*
*/
private final VBRQuantize vbrQuantize;
/**
* @param vbrQuantize
*/
LongBlockConstrain(VBRQuantize vbrQuantize) {
this.vbrQuantize = vbrQuantize;
}
/**
* ***************************************************************
* <p/>
* long block scalefacs
* <p/>
* ****************************************************************
*/
| // Path: src/main/java/net/sourceforge/lame/mp3/VBRQuantize.java
// protected static class algo_t {
// alloc_sf_f alloc;
// float[] xr34orig;
// LameInternalFlags gfc;
// GrInfo cod_info;
// int mingain_l;
// int mingain_s[] = new int[3];
// }
// Path: src/main/java/net/sourceforge/lame/mp3/LongBlockConstrain.java
import net.sourceforge.lame.mp3.VBRQuantize.algo_t;
package net.sourceforge.lame.mp3;
final class LongBlockConstrain implements VBRQuantize.alloc_sf_f {
/**
*
*/
private final VBRQuantize vbrQuantize;
/**
* @param vbrQuantize
*/
LongBlockConstrain(VBRQuantize vbrQuantize) {
this.vbrQuantize = vbrQuantize;
}
/**
* ***************************************************************
* <p/>
* long block scalefacs
* <p/>
* ****************************************************************
*/
| public void alloc(algo_t that, int[] vbrsf, int[] vbrsfmin, int vbrmax) {
|
nwaldispuehl/java-lame | src/main/java/net/sourceforge/lame/mpg/Layer3.java | // Path: src/main/java/net/sourceforge/lame/mpg/Huffman.java
// public static class newhuff {
// public final int linbits;
// public final short[] table;
// public newhuff(int bits, short[] t) {
// linbits = bits;
// table = t;
// }
// }
| import net.sourceforge.lame.mpg.Huffman.newhuff;
import net.sourceforge.lame.mpg.Interface.ISynth;
import net.sourceforge.lame.mpg.MPG123.III_sideinfo;
import net.sourceforge.lame.mpg.MPG123.gr_info_s;
import net.sourceforge.lame.mpg.MPGLib.ProcessedBytes;
import net.sourceforge.lame.mpg.MPGLib.mpstr_tag;
| }
/* end MDH crash fix */
if (gr_infos.block_type == 2) {
/*
* decoding with short or mixed mode BandIndex table
*/
int i, max[] = new int[4];
int step = 0, lwin = 0, cb = 0;
float v = 0.0f;
int[] m;
int mc;
int mPos = 0;
if (gr_infos.mixed_block_flag != 0) {
max[3] = -1;
max[0] = max[1] = max[2] = 2;
m = map[sfreq][0];
mPos = 0;
me = mapend[sfreq][0];
} else {
max[0] = max[1] = max[2] = max[3] = -1;
/* max[3] not really needed in this case */
m = map[sfreq][1];
mPos = 0;
me = mapend[sfreq][1];
}
mc = 0;
for (i = 0; i < 2; i++) {
int lp = l[i];
| // Path: src/main/java/net/sourceforge/lame/mpg/Huffman.java
// public static class newhuff {
// public final int linbits;
// public final short[] table;
// public newhuff(int bits, short[] t) {
// linbits = bits;
// table = t;
// }
// }
// Path: src/main/java/net/sourceforge/lame/mpg/Layer3.java
import net.sourceforge.lame.mpg.Huffman.newhuff;
import net.sourceforge.lame.mpg.Interface.ISynth;
import net.sourceforge.lame.mpg.MPG123.III_sideinfo;
import net.sourceforge.lame.mpg.MPG123.gr_info_s;
import net.sourceforge.lame.mpg.MPGLib.ProcessedBytes;
import net.sourceforge.lame.mpg.MPGLib.mpstr_tag;
}
/* end MDH crash fix */
if (gr_infos.block_type == 2) {
/*
* decoding with short or mixed mode BandIndex table
*/
int i, max[] = new int[4];
int step = 0, lwin = 0, cb = 0;
float v = 0.0f;
int[] m;
int mc;
int mPos = 0;
if (gr_infos.mixed_block_flag != 0) {
max[3] = -1;
max[0] = max[1] = max[2] = 2;
m = map[sfreq][0];
mPos = 0;
me = mapend[sfreq][0];
} else {
max[0] = max[1] = max[2] = max[3] = -1;
/* max[3] not really needed in this case */
m = map[sfreq][1];
mPos = 0;
me = mapend[sfreq][1];
}
mc = 0;
for (i = 0; i < 2; i++) {
int lp = l[i];
| newhuff[] h = Huffman.ht;
|
nwaldispuehl/java-lame | src/main/java/net/sourceforge/lame/mp3/Parse.java | // Path: src/main/java/net/sourceforge/lame/mp3/GetAudio.java
// public enum SoundFileFormat {
// sf_unknown, sf_raw, sf_wave, sf_aiff,
// /**
// * MPEG Layer 1, aka mpg
// */
// sf_mp1,
// /**
// * MPEG Layer 2
// */
// sf_mp2,
// /**
// * MPEG Layer 3
// */
// sf_mp3,
// /**
// * MPEG Layer 1,2 or 3; whatever .mp3, .mp2, .mp1 or .mpg contains
// */
// sf_mp123, sf_ogg
// }
| import java.util.Scanner;
import net.sourceforge.lame.mp3.GetAudio.SoundFileFormat;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteOrder;
import java.util.ArrayList;
| /*
* Command line parsing related functions
*
* Copyright (c) 1999 Mark Taylor
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/* $Id: Parse.java,v 1.33 2012/03/23 10:02:29 kenchis Exp $ */
package net.sourceforge.lame.mp3;
public class Parse {
private static boolean INTERNAL_OPTS = false;
/**
* force byte swapping default=0
*/
public boolean swapbytes = false;
/**
* Verbosity
*/
public int silent;
public boolean embedded;
public boolean brhist;
/**
* to use Frank's time status display
*/
public float update_interval;
/**
* to adjust the number of samples truncated during decode
*/
public int mp3_delay;
/**
* user specified the value of the mp3 encoder delay to assume for decoding
*/
public boolean mp3_delay_set;
public boolean disable_wav_header;
/**
* print info whether waveform clips
*/
public boolean print_clipping_info;
/**
* WAV signed
*/
public boolean in_signed = true;
public ByteOrder in_endian = ByteOrder.LITTLE_ENDIAN;
public int in_bitwidth = 16;
ID3Tag id3;
Presets pre;
private Usage usage = new Usage();
private Version version = new Version();
/**
* Input: sound file format.
*/
| // Path: src/main/java/net/sourceforge/lame/mp3/GetAudio.java
// public enum SoundFileFormat {
// sf_unknown, sf_raw, sf_wave, sf_aiff,
// /**
// * MPEG Layer 1, aka mpg
// */
// sf_mp1,
// /**
// * MPEG Layer 2
// */
// sf_mp2,
// /**
// * MPEG Layer 3
// */
// sf_mp3,
// /**
// * MPEG Layer 1,2 or 3; whatever .mp3, .mp2, .mp1 or .mpg contains
// */
// sf_mp123, sf_ogg
// }
// Path: src/main/java/net/sourceforge/lame/mp3/Parse.java
import java.util.Scanner;
import net.sourceforge.lame.mp3.GetAudio.SoundFileFormat;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteOrder;
import java.util.ArrayList;
/*
* Command line parsing related functions
*
* Copyright (c) 1999 Mark Taylor
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/* $Id: Parse.java,v 1.33 2012/03/23 10:02:29 kenchis Exp $ */
package net.sourceforge.lame.mp3;
public class Parse {
private static boolean INTERNAL_OPTS = false;
/**
* force byte swapping default=0
*/
public boolean swapbytes = false;
/**
* Verbosity
*/
public int silent;
public boolean embedded;
public boolean brhist;
/**
* to use Frank's time status display
*/
public float update_interval;
/**
* to adjust the number of samples truncated during decode
*/
public int mp3_delay;
/**
* user specified the value of the mp3 encoder delay to assume for decoding
*/
public boolean mp3_delay_set;
public boolean disable_wav_header;
/**
* print info whether waveform clips
*/
public boolean print_clipping_info;
/**
* WAV signed
*/
public boolean in_signed = true;
public ByteOrder in_endian = ByteOrder.LITTLE_ENDIAN;
public int in_bitwidth = 16;
ID3Tag id3;
Presets pre;
private Usage usage = new Usage();
private Version version = new Version();
/**
* Input: sound file format.
*/
| private GetAudio.SoundFileFormat inputFormat;
|
OpenChain-Project/Online-Self-Certification-Web-App | src/org/openchain/certification/utility/EmailUtility.java | // Path: src/org/openchain/certification/I18N.java
// public final class I18N {
//
// static final Logger logger = LoggerFactory.getLogger(I18N.class);
//
// private static final String BASE_RESOURCE_NAME = "messages"; //$NON-NLS-1$
//
// /**
// * @param key Key for the resource file
// * @param language tag in IETF RFC 5646 format
// * @return
// */
// public static String getMessage(String key, String language, Object... args) {
// if (language == null) {
// language = User.DEFAULT_LANGUAGE;
// }
// Locale locale = Locale.forLanguageTag(language);
// if (locale == null) {
// logger.warn("Language "+language+" not supported by Java. Using default language"); //$NON-NLS-1$ //$NON-NLS-2$
// locale = Locale.forLanguageTag(User.DEFAULT_LANGUAGE);
// if (locale == null) {
// logger.error("No locale for the default language"); //$NON-NLS-1$
// throw(new RuntimeException("No local for the default language")); //$NON-NLS-1$
// }
// }
// ResourceBundle.Control utf8Control = new Utf8ResourceBundleControl();
// ResourceBundle bundle = ResourceBundle.getBundle(BASE_RESOURCE_NAME, locale, utf8Control);
// String template = bundle.getString(key);
// try {
// MessageFormat mf = new MessageFormat(template, locale);
// return mf.format(args, new StringBuffer(), null).toString();
// } catch(IllegalArgumentException ex) {
// logger.error("Invalid argument for message template with key `"+key+"`: "+template, ex);
// return template;
// }
// }
//
// }
| import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient;
import com.amazonaws.services.simpleemail.model.Body;
import com.amazonaws.services.simpleemail.model.Content;
import com.amazonaws.services.simpleemail.model.Destination;
import com.amazonaws.services.simpleemail.model.GetSendQuotaResult;
import com.amazonaws.services.simpleemail.model.Message;
import com.amazonaws.services.simpleemail.model.SendEmailRequest;
import java.util.List;
import java.util.UUID;
import javax.servlet.ServletConfig;
import org.openchain.certification.I18N;
import org.openchain.certification.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions; | /**
* Copyright (c) 2016 Source Auditor Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.openchain.certification.utility;
/**
* Utility for managing emails including the verification emails and the
* password reset email.
*
* This class uses the Amazon SES email services.
* @author Gary O'Neall
*
*/
public class EmailUtility {
static final Logger logger = LoggerFactory.getLogger(EmailUtility.class);
private static final String ACCESS_KEY_VAR = "AWS_ACCESS_KEY_ID"; //$NON-NLS-1$
private static final String SECRET_KEY_VAR = "AWS_SECRET_ACCESS_KEY"; //$NON-NLS-1$
private static AmazonSimpleEmailServiceClient getEmailClient(ServletConfig config, String language) throws EmailUtilException {
String regionName = config.getServletContext().getInitParameter("email_ses_region"); //$NON-NLS-1$
if (regionName == null || regionName.isEmpty()) {
logger.error("Missing email_ses_region parameter in the web.xml file"); //$NON-NLS-1$ | // Path: src/org/openchain/certification/I18N.java
// public final class I18N {
//
// static final Logger logger = LoggerFactory.getLogger(I18N.class);
//
// private static final String BASE_RESOURCE_NAME = "messages"; //$NON-NLS-1$
//
// /**
// * @param key Key for the resource file
// * @param language tag in IETF RFC 5646 format
// * @return
// */
// public static String getMessage(String key, String language, Object... args) {
// if (language == null) {
// language = User.DEFAULT_LANGUAGE;
// }
// Locale locale = Locale.forLanguageTag(language);
// if (locale == null) {
// logger.warn("Language "+language+" not supported by Java. Using default language"); //$NON-NLS-1$ //$NON-NLS-2$
// locale = Locale.forLanguageTag(User.DEFAULT_LANGUAGE);
// if (locale == null) {
// logger.error("No locale for the default language"); //$NON-NLS-1$
// throw(new RuntimeException("No local for the default language")); //$NON-NLS-1$
// }
// }
// ResourceBundle.Control utf8Control = new Utf8ResourceBundleControl();
// ResourceBundle bundle = ResourceBundle.getBundle(BASE_RESOURCE_NAME, locale, utf8Control);
// String template = bundle.getString(key);
// try {
// MessageFormat mf = new MessageFormat(template, locale);
// return mf.format(args, new StringBuffer(), null).toString();
// } catch(IllegalArgumentException ex) {
// logger.error("Invalid argument for message template with key `"+key+"`: "+template, ex);
// return template;
// }
// }
//
// }
// Path: src/org/openchain/certification/utility/EmailUtility.java
import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient;
import com.amazonaws.services.simpleemail.model.Body;
import com.amazonaws.services.simpleemail.model.Content;
import com.amazonaws.services.simpleemail.model.Destination;
import com.amazonaws.services.simpleemail.model.GetSendQuotaResult;
import com.amazonaws.services.simpleemail.model.Message;
import com.amazonaws.services.simpleemail.model.SendEmailRequest;
import java.util.List;
import java.util.UUID;
import javax.servlet.ServletConfig;
import org.openchain.certification.I18N;
import org.openchain.certification.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
/**
* Copyright (c) 2016 Source Auditor Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.openchain.certification.utility;
/**
* Utility for managing emails including the verification emails and the
* password reset email.
*
* This class uses the Amazon SES email services.
* @author Gary O'Neall
*
*/
public class EmailUtility {
static final Logger logger = LoggerFactory.getLogger(EmailUtility.class);
private static final String ACCESS_KEY_VAR = "AWS_ACCESS_KEY_ID"; //$NON-NLS-1$
private static final String SECRET_KEY_VAR = "AWS_SECRET_ACCESS_KEY"; //$NON-NLS-1$
private static AmazonSimpleEmailServiceClient getEmailClient(ServletConfig config, String language) throws EmailUtilException {
String regionName = config.getServletContext().getInitParameter("email_ses_region"); //$NON-NLS-1$
if (regionName == null || regionName.isEmpty()) {
logger.error("Missing email_ses_region parameter in the web.xml file"); //$NON-NLS-1$ | throw(new EmailUtilException(I18N.getMessage("EmailUtility.4",language))); //$NON-NLS-1$ |
OpenChain-Project/Online-Self-Certification-Web-App | src/org/openchain/certification/dbdao/UserDb.java | // Path: src/org/openchain/certification/InvalidUserException.java
// public class InvalidUserException extends Exception {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * @param arg0
// */
// public InvalidUserException(String arg0) {
// super(arg0);
// }
//
// /**
// * @param arg0
// */
// public InvalidUserException(Throwable arg0) {
// super(arg0);
// }
//
// /**
// * @param arg0
// * @param arg1
// */
// public InvalidUserException(String arg0, Throwable arg1) {
// super(arg0, arg1);
// }
//
// /**
// * @param arg0
// * @param arg1
// * @param arg2
// * @param arg3
// */
// public InvalidUserException(String arg0, Throwable arg1, boolean arg2,
// boolean arg3) {
// super(arg0, arg1, arg2, arg3);
// }
//
// }
| import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Savepoint;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletConfig;
import org.openchain.certification.InvalidUserException;
import org.openchain.certification.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | user.setEmail(result.getString("email")); //$NON-NLS-1$
user.setName(result.getString("name")); //$NON-NLS-1$
user.setPasswordReset(result.getBoolean("passwordReset")); //$NON-NLS-1$
user.setPasswordToken(result.getString("password_token")); //$NON-NLS-1$
user.setUsername(result.getString("username")); //$NON-NLS-1$
user.setUuid(result.getString("uuid")); //$NON-NLS-1$
user.setVerificationExpirationDate(result.getDate("verificationExpirationDate")); //$NON-NLS-1$
user.setVerified(result.getBoolean("verified")); //$NON-NLS-1$
user.setOrganization(result.getString("organization")); //$NON-NLS-1$
user.setNamePermission(result.getBoolean("name_permission")); //$NON-NLS-1$
user.setEmailPermission(result.getBoolean("email_permission")); //$NON-NLS-1$
user.setLanguagePreference(result.getString("language")); //$NON-NLS-1$
retval.add(user);
}
return retval;
} finally {
if (result != null) {
result.close();
connection.commit();
}
}
}
/**
* Add a user to the database. The username must not already exist
* @param user
* @return a positive integer if successful
* @throws SQLException
* @throws InvalidUserException
*/ | // Path: src/org/openchain/certification/InvalidUserException.java
// public class InvalidUserException extends Exception {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * @param arg0
// */
// public InvalidUserException(String arg0) {
// super(arg0);
// }
//
// /**
// * @param arg0
// */
// public InvalidUserException(Throwable arg0) {
// super(arg0);
// }
//
// /**
// * @param arg0
// * @param arg1
// */
// public InvalidUserException(String arg0, Throwable arg1) {
// super(arg0, arg1);
// }
//
// /**
// * @param arg0
// * @param arg1
// * @param arg2
// * @param arg3
// */
// public InvalidUserException(String arg0, Throwable arg1, boolean arg2,
// boolean arg3) {
// super(arg0, arg1, arg2, arg3);
// }
//
// }
// Path: src/org/openchain/certification/dbdao/UserDb.java
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Savepoint;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletConfig;
import org.openchain.certification.InvalidUserException;
import org.openchain.certification.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
user.setEmail(result.getString("email")); //$NON-NLS-1$
user.setName(result.getString("name")); //$NON-NLS-1$
user.setPasswordReset(result.getBoolean("passwordReset")); //$NON-NLS-1$
user.setPasswordToken(result.getString("password_token")); //$NON-NLS-1$
user.setUsername(result.getString("username")); //$NON-NLS-1$
user.setUuid(result.getString("uuid")); //$NON-NLS-1$
user.setVerificationExpirationDate(result.getDate("verificationExpirationDate")); //$NON-NLS-1$
user.setVerified(result.getBoolean("verified")); //$NON-NLS-1$
user.setOrganization(result.getString("organization")); //$NON-NLS-1$
user.setNamePermission(result.getBoolean("name_permission")); //$NON-NLS-1$
user.setEmailPermission(result.getBoolean("email_permission")); //$NON-NLS-1$
user.setLanguagePreference(result.getString("language")); //$NON-NLS-1$
retval.add(user);
}
return retval;
} finally {
if (result != null) {
result.close();
connection.commit();
}
}
}
/**
* Add a user to the database. The username must not already exist
* @param user
* @return a positive integer if successful
* @throws SQLException
* @throws InvalidUserException
*/ | public synchronized int addUser(User user) throws SQLException, InvalidUserException { |
OpenChain-Project/Online-Self-Certification-Web-App | src/org/openchain/certification/git/QuestionnaireGitRepo.java | // Path: src/org/openchain/certification/I18N.java
// public final class I18N {
//
// static final Logger logger = LoggerFactory.getLogger(I18N.class);
//
// private static final String BASE_RESOURCE_NAME = "messages"; //$NON-NLS-1$
//
// /**
// * @param key Key for the resource file
// * @param language tag in IETF RFC 5646 format
// * @return
// */
// public static String getMessage(String key, String language, Object... args) {
// if (language == null) {
// language = User.DEFAULT_LANGUAGE;
// }
// Locale locale = Locale.forLanguageTag(language);
// if (locale == null) {
// logger.warn("Language "+language+" not supported by Java. Using default language"); //$NON-NLS-1$ //$NON-NLS-2$
// locale = Locale.forLanguageTag(User.DEFAULT_LANGUAGE);
// if (locale == null) {
// logger.error("No locale for the default language"); //$NON-NLS-1$
// throw(new RuntimeException("No local for the default language")); //$NON-NLS-1$
// }
// }
// ResourceBundle.Control utf8Control = new Utf8ResourceBundleControl();
// ResourceBundle bundle = ResourceBundle.getBundle(BASE_RESOURCE_NAME, locale, utf8Control);
// String template = bundle.getString(key);
// try {
// MessageFormat mf = new MessageFormat(template, locale);
// return mf.format(args, new StringBuffer(), null).toString();
// } catch(IllegalArgumentException ex) {
// logger.error("Invalid argument for message template with key `"+key+"`: "+template, ex);
// return template;
// }
// }
//
// }
| import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;
import org.eclipse.jgit.api.CloneCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.CanceledException;
import org.eclipse.jgit.api.errors.CheckoutConflictException;
import org.eclipse.jgit.api.errors.DetachedHeadException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidConfigurationException;
import org.eclipse.jgit.api.errors.InvalidRefNameException;
import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.api.errors.NoHeadException;
import org.eclipse.jgit.api.errors.RefAlreadyExistsException;
import org.eclipse.jgit.api.errors.RefNotAdvertisedException;
import org.eclipse.jgit.api.errors.RefNotFoundException;
import org.eclipse.jgit.api.errors.TransportException;
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
import org.eclipse.jgit.errors.AmbiguousObjectException;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.RevisionSyntaxException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryBuilder;
import org.openchain.certification.I18N;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | /**
* Copyright (c) 2018 Source Auditor Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.openchain.certification.git;
/**
* @author Gary O'Neall
*
* This singleton class is used to access the Conformance Questionnaire Git Repository (https://github.com/OpenChain-Project/conformance-questionnaire)
*
* The following is a typical worflow:
* - Refresh the repo by calling <code>refresh()</code>. This will pull the latest from the repository
* - Lock the repository so that no one else will checkout a different version
* - Checkout a specific commit or tag by calling <code>File checkout(String tag, String commitRef)</code>
* - Access the checked out files using the directory return value from checkout
* - Unlock the repository
*/
public class QuestionnaireGitRepo {
public static final String QUESTIONNAIRE_PREFIX = "questionnaire"; //$NON-NLS-1$
public static final String QUESTIONNAIRE_SUFFIX = ".json"; //$NON-NLS-1$
public class QuestionnaireFileIterator implements Iterator<File> {
private File[] jsonFiles;
private int jsonFileIndex = 0;
private String language;
/**
* @param repoDir Directory containing the questionnaire repository
* @param language Language for the logged in user
* @throws GitRepoException
*/
public QuestionnaireFileIterator(File repoDir, String language) throws GitRepoException {
this.language = language;
if (repoDir == null) {
logger.error("Null repository in new Questionnaire File Iterator"); //$NON-NLS-1$ | // Path: src/org/openchain/certification/I18N.java
// public final class I18N {
//
// static final Logger logger = LoggerFactory.getLogger(I18N.class);
//
// private static final String BASE_RESOURCE_NAME = "messages"; //$NON-NLS-1$
//
// /**
// * @param key Key for the resource file
// * @param language tag in IETF RFC 5646 format
// * @return
// */
// public static String getMessage(String key, String language, Object... args) {
// if (language == null) {
// language = User.DEFAULT_LANGUAGE;
// }
// Locale locale = Locale.forLanguageTag(language);
// if (locale == null) {
// logger.warn("Language "+language+" not supported by Java. Using default language"); //$NON-NLS-1$ //$NON-NLS-2$
// locale = Locale.forLanguageTag(User.DEFAULT_LANGUAGE);
// if (locale == null) {
// logger.error("No locale for the default language"); //$NON-NLS-1$
// throw(new RuntimeException("No local for the default language")); //$NON-NLS-1$
// }
// }
// ResourceBundle.Control utf8Control = new Utf8ResourceBundleControl();
// ResourceBundle bundle = ResourceBundle.getBundle(BASE_RESOURCE_NAME, locale, utf8Control);
// String template = bundle.getString(key);
// try {
// MessageFormat mf = new MessageFormat(template, locale);
// return mf.format(args, new StringBuffer(), null).toString();
// } catch(IllegalArgumentException ex) {
// logger.error("Invalid argument for message template with key `"+key+"`: "+template, ex);
// return template;
// }
// }
//
// }
// Path: src/org/openchain/certification/git/QuestionnaireGitRepo.java
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;
import org.eclipse.jgit.api.CloneCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.CanceledException;
import org.eclipse.jgit.api.errors.CheckoutConflictException;
import org.eclipse.jgit.api.errors.DetachedHeadException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidConfigurationException;
import org.eclipse.jgit.api.errors.InvalidRefNameException;
import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.api.errors.NoHeadException;
import org.eclipse.jgit.api.errors.RefAlreadyExistsException;
import org.eclipse.jgit.api.errors.RefNotAdvertisedException;
import org.eclipse.jgit.api.errors.RefNotFoundException;
import org.eclipse.jgit.api.errors.TransportException;
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
import org.eclipse.jgit.errors.AmbiguousObjectException;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.RevisionSyntaxException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryBuilder;
import org.openchain.certification.I18N;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Copyright (c) 2018 Source Auditor Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.openchain.certification.git;
/**
* @author Gary O'Neall
*
* This singleton class is used to access the Conformance Questionnaire Git Repository (https://github.com/OpenChain-Project/conformance-questionnaire)
*
* The following is a typical worflow:
* - Refresh the repo by calling <code>refresh()</code>. This will pull the latest from the repository
* - Lock the repository so that no one else will checkout a different version
* - Checkout a specific commit or tag by calling <code>File checkout(String tag, String commitRef)</code>
* - Access the checked out files using the directory return value from checkout
* - Unlock the repository
*/
public class QuestionnaireGitRepo {
public static final String QUESTIONNAIRE_PREFIX = "questionnaire"; //$NON-NLS-1$
public static final String QUESTIONNAIRE_SUFFIX = ".json"; //$NON-NLS-1$
public class QuestionnaireFileIterator implements Iterator<File> {
private File[] jsonFiles;
private int jsonFileIndex = 0;
private String language;
/**
* @param repoDir Directory containing the questionnaire repository
* @param language Language for the logged in user
* @throws GitRepoException
*/
public QuestionnaireFileIterator(File repoDir, String language) throws GitRepoException {
this.language = language;
if (repoDir == null) {
logger.error("Null repository in new Questionnaire File Iterator"); //$NON-NLS-1$ | throw new GitRepoException(I18N.getMessage("QuestionnaireGitRepo.0", language)); //$NON-NLS-1$ |
OpenChain-Project/Online-Self-Certification-Web-App | test/org/openchain/certification/dbdao/TestUserDb.java | // Path: src/org/openchain/certification/InvalidUserException.java
// public class InvalidUserException extends Exception {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * @param arg0
// */
// public InvalidUserException(String arg0) {
// super(arg0);
// }
//
// /**
// * @param arg0
// */
// public InvalidUserException(Throwable arg0) {
// super(arg0);
// }
//
// /**
// * @param arg0
// * @param arg1
// */
// public InvalidUserException(String arg0, Throwable arg1) {
// super(arg0, arg1);
// }
//
// /**
// * @param arg0
// * @param arg1
// * @param arg2
// * @param arg3
// */
// public InvalidUserException(String arg0, Throwable arg1, boolean arg2,
// boolean arg3) {
// super(arg0, arg1, arg2, arg3);
// }
//
// }
//
// Path: test/org/openchain/certification/TestHelper.java
// public class TestHelper {
//
// public static final String TEST_DB_NAME = "openchain_test";
// public static final String TEST_DB_USER_NAME = "openchain_test";
// public static final String TEST_DB_PASSWORD = "openchain_test";
// public static final String TEST_DB_HOST = "localhost";
// public static final int TEST_DB_PORT = 5432;
// static final PGSimpleDataSource dataSource = new PGSimpleDataSource();
// static {
// dataSource.setDatabaseName(TEST_DB_NAME);
// dataSource.setUser(TEST_DB_USER_NAME);
// dataSource.setPassword(TEST_DB_PASSWORD);
// dataSource.setServerName(TEST_DB_HOST);
// dataSource.setPortNumber(TEST_DB_PORT);
// }
//
// static final ServletConfig TEST_SERVLET_CONFIG = new MockServletConfig();
//
// public static Connection getConnection() throws SQLException {
// return dataSource.getConnection();
// }
//
// public static ServletConfig getTestServletConfig() {
// return TEST_SERVLET_CONFIG;
// }
//
// /**
// * Deletes ALL the data in the database
// * @param con
// * @throws SQLException
// */
// public static void truncateDatabase(Connection con) throws SQLException {
// Statement stmt = null;
// try {
// stmt = con.createStatement();
// stmt.executeUpdate("truncate answer, survey_response, openchain_user, question, section, spec");
// } finally {
// if (stmt != null) {
// stmt.close();
// }
// }
// }
//
// }
| import static org.junit.Assert.*;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.UUID;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openchain.certification.InvalidUserException;
import org.openchain.certification.TestHelper;
import org.openchain.certification.model.User; | package org.openchain.certification.dbdao;
public class TestUserDb {
Connection con;
@Before
public void setUp() throws Exception { | // Path: src/org/openchain/certification/InvalidUserException.java
// public class InvalidUserException extends Exception {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * @param arg0
// */
// public InvalidUserException(String arg0) {
// super(arg0);
// }
//
// /**
// * @param arg0
// */
// public InvalidUserException(Throwable arg0) {
// super(arg0);
// }
//
// /**
// * @param arg0
// * @param arg1
// */
// public InvalidUserException(String arg0, Throwable arg1) {
// super(arg0, arg1);
// }
//
// /**
// * @param arg0
// * @param arg1
// * @param arg2
// * @param arg3
// */
// public InvalidUserException(String arg0, Throwable arg1, boolean arg2,
// boolean arg3) {
// super(arg0, arg1, arg2, arg3);
// }
//
// }
//
// Path: test/org/openchain/certification/TestHelper.java
// public class TestHelper {
//
// public static final String TEST_DB_NAME = "openchain_test";
// public static final String TEST_DB_USER_NAME = "openchain_test";
// public static final String TEST_DB_PASSWORD = "openchain_test";
// public static final String TEST_DB_HOST = "localhost";
// public static final int TEST_DB_PORT = 5432;
// static final PGSimpleDataSource dataSource = new PGSimpleDataSource();
// static {
// dataSource.setDatabaseName(TEST_DB_NAME);
// dataSource.setUser(TEST_DB_USER_NAME);
// dataSource.setPassword(TEST_DB_PASSWORD);
// dataSource.setServerName(TEST_DB_HOST);
// dataSource.setPortNumber(TEST_DB_PORT);
// }
//
// static final ServletConfig TEST_SERVLET_CONFIG = new MockServletConfig();
//
// public static Connection getConnection() throws SQLException {
// return dataSource.getConnection();
// }
//
// public static ServletConfig getTestServletConfig() {
// return TEST_SERVLET_CONFIG;
// }
//
// /**
// * Deletes ALL the data in the database
// * @param con
// * @throws SQLException
// */
// public static void truncateDatabase(Connection con) throws SQLException {
// Statement stmt = null;
// try {
// stmt = con.createStatement();
// stmt.executeUpdate("truncate answer, survey_response, openchain_user, question, section, spec");
// } finally {
// if (stmt != null) {
// stmt.close();
// }
// }
// }
//
// }
// Path: test/org/openchain/certification/dbdao/TestUserDb.java
import static org.junit.Assert.*;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.UUID;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openchain.certification.InvalidUserException;
import org.openchain.certification.TestHelper;
import org.openchain.certification.model.User;
package org.openchain.certification.dbdao;
public class TestUserDb {
Connection con;
@Before
public void setUp() throws Exception { | con = TestHelper.getConnection(); |
OpenChain-Project/Online-Self-Certification-Web-App | test/org/openchain/certification/dbdao/TestUserDb.java | // Path: src/org/openchain/certification/InvalidUserException.java
// public class InvalidUserException extends Exception {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * @param arg0
// */
// public InvalidUserException(String arg0) {
// super(arg0);
// }
//
// /**
// * @param arg0
// */
// public InvalidUserException(Throwable arg0) {
// super(arg0);
// }
//
// /**
// * @param arg0
// * @param arg1
// */
// public InvalidUserException(String arg0, Throwable arg1) {
// super(arg0, arg1);
// }
//
// /**
// * @param arg0
// * @param arg1
// * @param arg2
// * @param arg3
// */
// public InvalidUserException(String arg0, Throwable arg1, boolean arg2,
// boolean arg3) {
// super(arg0, arg1, arg2, arg3);
// }
//
// }
//
// Path: test/org/openchain/certification/TestHelper.java
// public class TestHelper {
//
// public static final String TEST_DB_NAME = "openchain_test";
// public static final String TEST_DB_USER_NAME = "openchain_test";
// public static final String TEST_DB_PASSWORD = "openchain_test";
// public static final String TEST_DB_HOST = "localhost";
// public static final int TEST_DB_PORT = 5432;
// static final PGSimpleDataSource dataSource = new PGSimpleDataSource();
// static {
// dataSource.setDatabaseName(TEST_DB_NAME);
// dataSource.setUser(TEST_DB_USER_NAME);
// dataSource.setPassword(TEST_DB_PASSWORD);
// dataSource.setServerName(TEST_DB_HOST);
// dataSource.setPortNumber(TEST_DB_PORT);
// }
//
// static final ServletConfig TEST_SERVLET_CONFIG = new MockServletConfig();
//
// public static Connection getConnection() throws SQLException {
// return dataSource.getConnection();
// }
//
// public static ServletConfig getTestServletConfig() {
// return TEST_SERVLET_CONFIG;
// }
//
// /**
// * Deletes ALL the data in the database
// * @param con
// * @throws SQLException
// */
// public static void truncateDatabase(Connection con) throws SQLException {
// Statement stmt = null;
// try {
// stmt = con.createStatement();
// stmt.executeUpdate("truncate answer, survey_response, openchain_user, question, section, spec");
// } finally {
// if (stmt != null) {
// stmt.close();
// }
// }
// }
//
// }
| import static org.junit.Assert.*;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.UUID;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openchain.certification.InvalidUserException;
import org.openchain.certification.TestHelper;
import org.openchain.certification.model.User; | package org.openchain.certification.dbdao;
public class TestUserDb {
Connection con;
@Before
public void setUp() throws Exception {
con = TestHelper.getConnection();
TestHelper.truncateDatabase(con);
}
@After
public void tearDown() throws Exception {
con.close();
}
@Test | // Path: src/org/openchain/certification/InvalidUserException.java
// public class InvalidUserException extends Exception {
//
// /**
// *
// */
// private static final long serialVersionUID = 1L;
//
// /**
// * @param arg0
// */
// public InvalidUserException(String arg0) {
// super(arg0);
// }
//
// /**
// * @param arg0
// */
// public InvalidUserException(Throwable arg0) {
// super(arg0);
// }
//
// /**
// * @param arg0
// * @param arg1
// */
// public InvalidUserException(String arg0, Throwable arg1) {
// super(arg0, arg1);
// }
//
// /**
// * @param arg0
// * @param arg1
// * @param arg2
// * @param arg3
// */
// public InvalidUserException(String arg0, Throwable arg1, boolean arg2,
// boolean arg3) {
// super(arg0, arg1, arg2, arg3);
// }
//
// }
//
// Path: test/org/openchain/certification/TestHelper.java
// public class TestHelper {
//
// public static final String TEST_DB_NAME = "openchain_test";
// public static final String TEST_DB_USER_NAME = "openchain_test";
// public static final String TEST_DB_PASSWORD = "openchain_test";
// public static final String TEST_DB_HOST = "localhost";
// public static final int TEST_DB_PORT = 5432;
// static final PGSimpleDataSource dataSource = new PGSimpleDataSource();
// static {
// dataSource.setDatabaseName(TEST_DB_NAME);
// dataSource.setUser(TEST_DB_USER_NAME);
// dataSource.setPassword(TEST_DB_PASSWORD);
// dataSource.setServerName(TEST_DB_HOST);
// dataSource.setPortNumber(TEST_DB_PORT);
// }
//
// static final ServletConfig TEST_SERVLET_CONFIG = new MockServletConfig();
//
// public static Connection getConnection() throws SQLException {
// return dataSource.getConnection();
// }
//
// public static ServletConfig getTestServletConfig() {
// return TEST_SERVLET_CONFIG;
// }
//
// /**
// * Deletes ALL the data in the database
// * @param con
// * @throws SQLException
// */
// public static void truncateDatabase(Connection con) throws SQLException {
// Statement stmt = null;
// try {
// stmt = con.createStatement();
// stmt.executeUpdate("truncate answer, survey_response, openchain_user, question, section, spec");
// } finally {
// if (stmt != null) {
// stmt.close();
// }
// }
// }
//
// }
// Path: test/org/openchain/certification/dbdao/TestUserDb.java
import static org.junit.Assert.*;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.UUID;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openchain.certification.InvalidUserException;
import org.openchain.certification.TestHelper;
import org.openchain.certification.model.User;
package org.openchain.certification.dbdao;
public class TestUserDb {
Connection con;
@Before
public void setUp() throws Exception {
con = TestHelper.getConnection();
TestHelper.truncateDatabase(con);
}
@After
public void tearDown() throws Exception {
con.close();
}
@Test | public void testAddUser() throws SQLException, InvalidUserException { |
OpenChain-Project/Online-Self-Certification-Web-App | src/org/openchain/certification/model/Question.java | // Path: src/org/openchain/certification/I18N.java
// public final class I18N {
//
// static final Logger logger = LoggerFactory.getLogger(I18N.class);
//
// private static final String BASE_RESOURCE_NAME = "messages"; //$NON-NLS-1$
//
// /**
// * @param key Key for the resource file
// * @param language tag in IETF RFC 5646 format
// * @return
// */
// public static String getMessage(String key, String language, Object... args) {
// if (language == null) {
// language = User.DEFAULT_LANGUAGE;
// }
// Locale locale = Locale.forLanguageTag(language);
// if (locale == null) {
// logger.warn("Language "+language+" not supported by Java. Using default language"); //$NON-NLS-1$ //$NON-NLS-2$
// locale = Locale.forLanguageTag(User.DEFAULT_LANGUAGE);
// if (locale == null) {
// logger.error("No locale for the default language"); //$NON-NLS-1$
// throw(new RuntimeException("No local for the default language")); //$NON-NLS-1$
// }
// }
// ResourceBundle.Control utf8Control = new Utf8ResourceBundleControl();
// ResourceBundle bundle = ResourceBundle.getBundle(BASE_RESOURCE_NAME, locale, utf8Control);
// String template = bundle.getString(key);
// try {
// MessageFormat mf = new MessageFormat(template, locale);
// return mf.format(args, new StringBuffer(), null).toString();
// } catch(IllegalArgumentException ex) {
// logger.error("Invalid argument for message template with key `"+key+"`: "+template, ex);
// return template;
// }
// }
//
// }
| import java.util.HashSet;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.openchain.certification.I18N;
import org.openchain.certification.model.YesNoQuestion.YesNo; | /**
* Copyright (c) 2016 Source Auditor Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.openchain.certification.model;
/**
* A question asked in the self certification
* @author Gary O'Neall
*
*/
public abstract class Question implements Comparable<Question> {
protected String question;
protected String sectionName;
private String number;
private String subQuestionOfNumber = null;
protected String type;
protected String specVersion;
transient static final Pattern NUMBER_PATTERN = Pattern.compile("(\\d+)(\\.\\d+)?(\\.\\d+)?"); //$NON-NLS-1$
transient static final Pattern NUM_ALPH_AROMAN_PATTERN = Pattern.compile("(\\d+)(\\.[a-z]+)?(\\.[ivxlmcd]+)?"); //$NON-NLS-1$
transient private Matcher numberMatch;
private String[] specReference = new String[0];
private String language;
/**
* @param question Text for the question
* @param sectionName Name of the section
* @param number Number of the question
* @param specVersion Version for the spec
* @param specRefs Specification reference numbers related to the question
* @param language tag in IETF RFC 5646 format
* @throws QuestionException
*/
public Question(String question, String sectionName, String number, String specVersion, String[] specRefs, String language) throws QuestionException {
if (specVersion == null) { | // Path: src/org/openchain/certification/I18N.java
// public final class I18N {
//
// static final Logger logger = LoggerFactory.getLogger(I18N.class);
//
// private static final String BASE_RESOURCE_NAME = "messages"; //$NON-NLS-1$
//
// /**
// * @param key Key for the resource file
// * @param language tag in IETF RFC 5646 format
// * @return
// */
// public static String getMessage(String key, String language, Object... args) {
// if (language == null) {
// language = User.DEFAULT_LANGUAGE;
// }
// Locale locale = Locale.forLanguageTag(language);
// if (locale == null) {
// logger.warn("Language "+language+" not supported by Java. Using default language"); //$NON-NLS-1$ //$NON-NLS-2$
// locale = Locale.forLanguageTag(User.DEFAULT_LANGUAGE);
// if (locale == null) {
// logger.error("No locale for the default language"); //$NON-NLS-1$
// throw(new RuntimeException("No local for the default language")); //$NON-NLS-1$
// }
// }
// ResourceBundle.Control utf8Control = new Utf8ResourceBundleControl();
// ResourceBundle bundle = ResourceBundle.getBundle(BASE_RESOURCE_NAME, locale, utf8Control);
// String template = bundle.getString(key);
// try {
// MessageFormat mf = new MessageFormat(template, locale);
// return mf.format(args, new StringBuffer(), null).toString();
// } catch(IllegalArgumentException ex) {
// logger.error("Invalid argument for message template with key `"+key+"`: "+template, ex);
// return template;
// }
// }
//
// }
// Path: src/org/openchain/certification/model/Question.java
import java.util.HashSet;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.openchain.certification.I18N;
import org.openchain.certification.model.YesNoQuestion.YesNo;
/**
* Copyright (c) 2016 Source Auditor Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.openchain.certification.model;
/**
* A question asked in the self certification
* @author Gary O'Neall
*
*/
public abstract class Question implements Comparable<Question> {
protected String question;
protected String sectionName;
private String number;
private String subQuestionOfNumber = null;
protected String type;
protected String specVersion;
transient static final Pattern NUMBER_PATTERN = Pattern.compile("(\\d+)(\\.\\d+)?(\\.\\d+)?"); //$NON-NLS-1$
transient static final Pattern NUM_ALPH_AROMAN_PATTERN = Pattern.compile("(\\d+)(\\.[a-z]+)?(\\.[ivxlmcd]+)?"); //$NON-NLS-1$
transient private Matcher numberMatch;
private String[] specReference = new String[0];
private String language;
/**
* @param question Text for the question
* @param sectionName Name of the section
* @param number Number of the question
* @param specVersion Version for the spec
* @param specRefs Specification reference numbers related to the question
* @param language tag in IETF RFC 5646 format
* @throws QuestionException
*/
public Question(String question, String sectionName, String number, String specVersion, String[] specRefs, String language) throws QuestionException {
if (specVersion == null) { | throw(new QuestionException(I18N.getMessage("Question.2",language))); //$NON-NLS-1$ |
OpenChain-Project/Online-Self-Certification-Web-App | src/org/openchain/certification/model/Survey.java | // Path: src/org/openchain/certification/I18N.java
// public final class I18N {
//
// static final Logger logger = LoggerFactory.getLogger(I18N.class);
//
// private static final String BASE_RESOURCE_NAME = "messages"; //$NON-NLS-1$
//
// /**
// * @param key Key for the resource file
// * @param language tag in IETF RFC 5646 format
// * @return
// */
// public static String getMessage(String key, String language, Object... args) {
// if (language == null) {
// language = User.DEFAULT_LANGUAGE;
// }
// Locale locale = Locale.forLanguageTag(language);
// if (locale == null) {
// logger.warn("Language "+language+" not supported by Java. Using default language"); //$NON-NLS-1$ //$NON-NLS-2$
// locale = Locale.forLanguageTag(User.DEFAULT_LANGUAGE);
// if (locale == null) {
// logger.error("No locale for the default language"); //$NON-NLS-1$
// throw(new RuntimeException("No local for the default language")); //$NON-NLS-1$
// }
// }
// ResourceBundle.Control utf8Control = new Utf8ResourceBundleControl();
// ResourceBundle bundle = ResourceBundle.getBundle(BASE_RESOURCE_NAME, locale, utf8Control);
// String template = bundle.getString(key);
// try {
// MessageFormat mf = new MessageFormat(template, locale);
// return mf.format(args, new StringBuffer(), null).toString();
// } catch(IllegalArgumentException ex) {
// logger.error("Invalid argument for message template with key `"+key+"`: "+template, ex);
// return template;
// }
// }
//
// }
| import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.HashSet;
import org.openchain.certification.I18N;
import com.opencsv.CSVWriter; | if (question instanceof SubQuestion) {
questionsWithSubquestions.put(question.getNumber(), (SubQuestion)question);
}
}
for (SubQuestion questionsWithSubquestion:questionsWithSubquestions.values()) {
for (Question subQuestion:questionsWithSubquestion.getAllSubquestions()) {
subQuestion.setSpecVersion(specV);
subQuestion.setLanguage(lang);
subQuestion.setSectionName(sectionName);
// Add the redundant subquestion of number
subQuestion.setSubQuestionOfNumber(questionsWithSubquestion.getNumber());
// Add the redundant copy of the subquestion to the section
section.getQuestions().add(subQuestion);
}
}
}
this.compactAndPretty = false;
}
/**
* @return List of any warnings due to an invalid survey
*/
public List<String> verify(String language) {
List<String> retval = new ArrayList<String>();
Set<String> existingSections = new HashSet<String>();
Set<String> existingQuestions = new HashSet<String>();
Set<String> foundSubQuestions = new HashSet<String>();
for (Section section:sections) {
// Check for duplication section names
if (existingSections.contains(section.getName())) { | // Path: src/org/openchain/certification/I18N.java
// public final class I18N {
//
// static final Logger logger = LoggerFactory.getLogger(I18N.class);
//
// private static final String BASE_RESOURCE_NAME = "messages"; //$NON-NLS-1$
//
// /**
// * @param key Key for the resource file
// * @param language tag in IETF RFC 5646 format
// * @return
// */
// public static String getMessage(String key, String language, Object... args) {
// if (language == null) {
// language = User.DEFAULT_LANGUAGE;
// }
// Locale locale = Locale.forLanguageTag(language);
// if (locale == null) {
// logger.warn("Language "+language+" not supported by Java. Using default language"); //$NON-NLS-1$ //$NON-NLS-2$
// locale = Locale.forLanguageTag(User.DEFAULT_LANGUAGE);
// if (locale == null) {
// logger.error("No locale for the default language"); //$NON-NLS-1$
// throw(new RuntimeException("No local for the default language")); //$NON-NLS-1$
// }
// }
// ResourceBundle.Control utf8Control = new Utf8ResourceBundleControl();
// ResourceBundle bundle = ResourceBundle.getBundle(BASE_RESOURCE_NAME, locale, utf8Control);
// String template = bundle.getString(key);
// try {
// MessageFormat mf = new MessageFormat(template, locale);
// return mf.format(args, new StringBuffer(), null).toString();
// } catch(IllegalArgumentException ex) {
// logger.error("Invalid argument for message template with key `"+key+"`: "+template, ex);
// return template;
// }
// }
//
// }
// Path: src/org/openchain/certification/model/Survey.java
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.HashSet;
import org.openchain.certification.I18N;
import com.opencsv.CSVWriter;
if (question instanceof SubQuestion) {
questionsWithSubquestions.put(question.getNumber(), (SubQuestion)question);
}
}
for (SubQuestion questionsWithSubquestion:questionsWithSubquestions.values()) {
for (Question subQuestion:questionsWithSubquestion.getAllSubquestions()) {
subQuestion.setSpecVersion(specV);
subQuestion.setLanguage(lang);
subQuestion.setSectionName(sectionName);
// Add the redundant subquestion of number
subQuestion.setSubQuestionOfNumber(questionsWithSubquestion.getNumber());
// Add the redundant copy of the subquestion to the section
section.getQuestions().add(subQuestion);
}
}
}
this.compactAndPretty = false;
}
/**
* @return List of any warnings due to an invalid survey
*/
public List<String> verify(String language) {
List<String> retval = new ArrayList<String>();
Set<String> existingSections = new HashSet<String>();
Set<String> existingQuestions = new HashSet<String>();
Set<String> foundSubQuestions = new HashSet<String>();
for (Section section:sections) {
// Check for duplication section names
if (existingSections.contains(section.getName())) { | retval.add(I18N.getMessage("Survey.1", language, section.getName())); //$NON-NLS-1$ |
paulirotta/cascade | cascade/src/main/java/com/reactivecascade/util/BindingContextUtil.java | // Path: cascade/src/main/java/com/reactivecascade/i/IActionOne.java
// public interface IActionOne<IN> extends IBaseAction<IN> {
// /**
// * Execute the action
// *
// * @param in input
// * @throws Exception to transition to {@link com.reactivecascade.i.IAltFuture.StateError}
// * @throws java.util.concurrent.CancellationException to {@link com.reactivecascade.i.IAltFuture.StateCancelled}
// */
// void call(@NonNull IN in) throws Exception;
// }
//
// Path: cascade/src/main/java/com/reactivecascade/i/IBindingContext.java
// public interface IBindingContext<T> {
// /**
// * Check if closed
// *
// * @return <code>true</code> if {@link #closeBindingContext(Object)} has not been called
// */
// boolean isOpen();
//
// /**
// * Trigger start of all binding context actions
// *
// * @param t the type of object controlling this binding's lifecycle
// */
// void openBindingContext(T t);
//
// /**
// * Trigger end of all binding context actions
// * @param t the type of object controlling this binding's lifecyle
// */
// void closeBindingContext(T t);
//
// /**
// * Add an action to be performed synchronously before the binding context open finishes
// *
// * @param action performed when binding starts
// */
// void onOpen(@NonNull IActionOne<T> action);
//
// /**
// * Add an action to be performed synchronously before the binding context close finishes
// *
// * @param action performed when binding ends
// */
// void onClose(@NonNull IActionOne<T> action);
// }
| import android.support.annotation.CallSuper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import com.reactivecascade.i.IActionOne;
import com.reactivecascade.i.IBindingContext;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicReference; | /*
This file is part of Reactive Cascade which is released under The MIT License.
See license.md , https://github.com/futurice/cascade and http://reactivecascade.com for details.
This is open source for the common good. Please contribute improvements by pull request or contact paulirotta@gmail.com
*/
package com.reactivecascade.util;
/**
* Default binding context implementations
*
* TODO WIP - this class is not yet complete and in-use
*/
public class BindingContextUtil {
private static final String TAG = BindingContextUtil.class.getSimpleName();
/**
* The default implementation of a state-change notification to start and stop data-driven reactive actions
*
* @param <T> the type of object which will control these state changes
*/ | // Path: cascade/src/main/java/com/reactivecascade/i/IActionOne.java
// public interface IActionOne<IN> extends IBaseAction<IN> {
// /**
// * Execute the action
// *
// * @param in input
// * @throws Exception to transition to {@link com.reactivecascade.i.IAltFuture.StateError}
// * @throws java.util.concurrent.CancellationException to {@link com.reactivecascade.i.IAltFuture.StateCancelled}
// */
// void call(@NonNull IN in) throws Exception;
// }
//
// Path: cascade/src/main/java/com/reactivecascade/i/IBindingContext.java
// public interface IBindingContext<T> {
// /**
// * Check if closed
// *
// * @return <code>true</code> if {@link #closeBindingContext(Object)} has not been called
// */
// boolean isOpen();
//
// /**
// * Trigger start of all binding context actions
// *
// * @param t the type of object controlling this binding's lifecycle
// */
// void openBindingContext(T t);
//
// /**
// * Trigger end of all binding context actions
// * @param t the type of object controlling this binding's lifecyle
// */
// void closeBindingContext(T t);
//
// /**
// * Add an action to be performed synchronously before the binding context open finishes
// *
// * @param action performed when binding starts
// */
// void onOpen(@NonNull IActionOne<T> action);
//
// /**
// * Add an action to be performed synchronously before the binding context close finishes
// *
// * @param action performed when binding ends
// */
// void onClose(@NonNull IActionOne<T> action);
// }
// Path: cascade/src/main/java/com/reactivecascade/util/BindingContextUtil.java
import android.support.annotation.CallSuper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import com.reactivecascade.i.IActionOne;
import com.reactivecascade.i.IBindingContext;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicReference;
/*
This file is part of Reactive Cascade which is released under The MIT License.
See license.md , https://github.com/futurice/cascade and http://reactivecascade.com for details.
This is open source for the common good. Please contribute improvements by pull request or contact paulirotta@gmail.com
*/
package com.reactivecascade.util;
/**
* Default binding context implementations
*
* TODO WIP - this class is not yet complete and in-use
*/
public class BindingContextUtil {
private static final String TAG = BindingContextUtil.class.getSimpleName();
/**
* The default implementation of a state-change notification to start and stop data-driven reactive actions
*
* @param <T> the type of object which will control these state changes
*/ | public static class DefaultBindingContext<T> implements IBindingContext<T> { |
paulirotta/cascade | cascade/src/main/java/com/reactivecascade/util/BindingContextUtil.java | // Path: cascade/src/main/java/com/reactivecascade/i/IActionOne.java
// public interface IActionOne<IN> extends IBaseAction<IN> {
// /**
// * Execute the action
// *
// * @param in input
// * @throws Exception to transition to {@link com.reactivecascade.i.IAltFuture.StateError}
// * @throws java.util.concurrent.CancellationException to {@link com.reactivecascade.i.IAltFuture.StateCancelled}
// */
// void call(@NonNull IN in) throws Exception;
// }
//
// Path: cascade/src/main/java/com/reactivecascade/i/IBindingContext.java
// public interface IBindingContext<T> {
// /**
// * Check if closed
// *
// * @return <code>true</code> if {@link #closeBindingContext(Object)} has not been called
// */
// boolean isOpen();
//
// /**
// * Trigger start of all binding context actions
// *
// * @param t the type of object controlling this binding's lifecycle
// */
// void openBindingContext(T t);
//
// /**
// * Trigger end of all binding context actions
// * @param t the type of object controlling this binding's lifecyle
// */
// void closeBindingContext(T t);
//
// /**
// * Add an action to be performed synchronously before the binding context open finishes
// *
// * @param action performed when binding starts
// */
// void onOpen(@NonNull IActionOne<T> action);
//
// /**
// * Add an action to be performed synchronously before the binding context close finishes
// *
// * @param action performed when binding ends
// */
// void onClose(@NonNull IActionOne<T> action);
// }
| import android.support.annotation.CallSuper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import com.reactivecascade.i.IActionOne;
import com.reactivecascade.i.IBindingContext;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicReference; | /*
This file is part of Reactive Cascade which is released under The MIT License.
See license.md , https://github.com/futurice/cascade and http://reactivecascade.com for details.
This is open source for the common good. Please contribute improvements by pull request or contact paulirotta@gmail.com
*/
package com.reactivecascade.util;
/**
* Default binding context implementations
*
* TODO WIP - this class is not yet complete and in-use
*/
public class BindingContextUtil {
private static final String TAG = BindingContextUtil.class.getSimpleName();
/**
* The default implementation of a state-change notification to start and stop data-driven reactive actions
*
* @param <T> the type of object which will control these state changes
*/
public static class DefaultBindingContext<T> implements IBindingContext<T> { | // Path: cascade/src/main/java/com/reactivecascade/i/IActionOne.java
// public interface IActionOne<IN> extends IBaseAction<IN> {
// /**
// * Execute the action
// *
// * @param in input
// * @throws Exception to transition to {@link com.reactivecascade.i.IAltFuture.StateError}
// * @throws java.util.concurrent.CancellationException to {@link com.reactivecascade.i.IAltFuture.StateCancelled}
// */
// void call(@NonNull IN in) throws Exception;
// }
//
// Path: cascade/src/main/java/com/reactivecascade/i/IBindingContext.java
// public interface IBindingContext<T> {
// /**
// * Check if closed
// *
// * @return <code>true</code> if {@link #closeBindingContext(Object)} has not been called
// */
// boolean isOpen();
//
// /**
// * Trigger start of all binding context actions
// *
// * @param t the type of object controlling this binding's lifecycle
// */
// void openBindingContext(T t);
//
// /**
// * Trigger end of all binding context actions
// * @param t the type of object controlling this binding's lifecyle
// */
// void closeBindingContext(T t);
//
// /**
// * Add an action to be performed synchronously before the binding context open finishes
// *
// * @param action performed when binding starts
// */
// void onOpen(@NonNull IActionOne<T> action);
//
// /**
// * Add an action to be performed synchronously before the binding context close finishes
// *
// * @param action performed when binding ends
// */
// void onClose(@NonNull IActionOne<T> action);
// }
// Path: cascade/src/main/java/com/reactivecascade/util/BindingContextUtil.java
import android.support.annotation.CallSuper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import com.reactivecascade.i.IActionOne;
import com.reactivecascade.i.IBindingContext;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicReference;
/*
This file is part of Reactive Cascade which is released under The MIT License.
See license.md , https://github.com/futurice/cascade and http://reactivecascade.com for details.
This is open source for the common good. Please contribute improvements by pull request or contact paulirotta@gmail.com
*/
package com.reactivecascade.util;
/**
* Default binding context implementations
*
* TODO WIP - this class is not yet complete and in-use
*/
public class BindingContextUtil {
private static final String TAG = BindingContextUtil.class.getSimpleName();
/**
* The default implementation of a state-change notification to start and stop data-driven reactive actions
*
* @param <T> the type of object which will control these state changes
*/
public static class DefaultBindingContext<T> implements IBindingContext<T> { | private final CopyOnWriteArraySet<IActionOne<T>> onOpenActions = new CopyOnWriteArraySet<>(); |
jtulach/sieve | java/client/src/main/java/org/apidesign/demo/sieve/DataModel.java | // Path: java/algorithm/src/main/java/org/apidesign/demo/sieve/eratosthenes/Primes.java
// public abstract class Primes {
// private final Natural natural;
// private Filter filter;
//
// protected Primes() {
// this.natural = new Natural();
// }
//
// int next() {
// for (;;) {
// int n = natural.next();
// if (filter == null) {
// filter = new Filter(n);
// return n;
// }
// if (filter.acceptAndAdd(n)) {
// return n;
// }
// }
// }
//
// protected abstract void log(String msg);
//
// public final int compute() {
// long start = System.currentTimeMillis();
// int cnt = 0;
// int prntCnt = 97;
// int res;
// for (;;) {
// res = next();
// cnt += 1;
// if (cnt % prntCnt == 0) {
// log("Computed " + cnt + " primes in " + (System.currentTimeMillis() - start) + " ms. Last one is " + res);
// prntCnt *= 2;
// }
// if (cnt >= 100000) {
// break;
// }
// }
// return res;
// }
//
// public static void main(String... args) {
// int cnt = Integer.MAX_VALUE;
// if (args.length == 1) {
// cnt = Integer.parseInt(args[0]);
// }
// while (cnt-- > 0) {
// Primes p = new Primes() {
// @Override
// protected void log(String msg) {
// System.out.println(msg);
// }
// };
// long start = System.currentTimeMillis();
// int value = p.compute();
// long took = System.currentTimeMillis() - start;
// System.out.println("Hundred thousand primes computed in " + took + " ms");
// }
// }
// }
| import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import net.java.html.charts.Chart;
import net.java.html.charts.Color;
import net.java.html.charts.Config;
import net.java.html.charts.Values;
import net.java.html.json.Function;
import net.java.html.json.Model;
import net.java.html.json.ModelOperation;
import net.java.html.json.Property;
import org.apidesign.demo.sieve.eratosthenes.Primes; |
@ModelOperation
void initialize(Data model) {
Chart<Values, Config> chart = Chart.createLine(new Values.Set("a label", Color.valueOf("white"), Color.valueOf("black")));
data = chart.getData();
data.add(new Values("0", 0));
chart.applyTo("chart");
model.setStartOrStop("Start");
model.applyBindings();
}
@Function
void startStop(final Data model) {
if (model.isRunning()) {
model.setStartOrStop("Start");
model.setRunning(false);
} else {
model.setStartOrStop("Stop");
model.runMeasurement(Integer.MAX_VALUE);
}
}
@ModelOperation
void runMeasurement(final Data model, int cnt) {
model.setRunning(true);
final List<Integer> results = new ArrayList<>();
final int[] count = { cnt };
class Schedule extends TimerTask {
@Override
public void run() { | // Path: java/algorithm/src/main/java/org/apidesign/demo/sieve/eratosthenes/Primes.java
// public abstract class Primes {
// private final Natural natural;
// private Filter filter;
//
// protected Primes() {
// this.natural = new Natural();
// }
//
// int next() {
// for (;;) {
// int n = natural.next();
// if (filter == null) {
// filter = new Filter(n);
// return n;
// }
// if (filter.acceptAndAdd(n)) {
// return n;
// }
// }
// }
//
// protected abstract void log(String msg);
//
// public final int compute() {
// long start = System.currentTimeMillis();
// int cnt = 0;
// int prntCnt = 97;
// int res;
// for (;;) {
// res = next();
// cnt += 1;
// if (cnt % prntCnt == 0) {
// log("Computed " + cnt + " primes in " + (System.currentTimeMillis() - start) + " ms. Last one is " + res);
// prntCnt *= 2;
// }
// if (cnt >= 100000) {
// break;
// }
// }
// return res;
// }
//
// public static void main(String... args) {
// int cnt = Integer.MAX_VALUE;
// if (args.length == 1) {
// cnt = Integer.parseInt(args[0]);
// }
// while (cnt-- > 0) {
// Primes p = new Primes() {
// @Override
// protected void log(String msg) {
// System.out.println(msg);
// }
// };
// long start = System.currentTimeMillis();
// int value = p.compute();
// long took = System.currentTimeMillis() - start;
// System.out.println("Hundred thousand primes computed in " + took + " ms");
// }
// }
// }
// Path: java/client/src/main/java/org/apidesign/demo/sieve/DataModel.java
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import net.java.html.charts.Chart;
import net.java.html.charts.Color;
import net.java.html.charts.Config;
import net.java.html.charts.Values;
import net.java.html.json.Function;
import net.java.html.json.Model;
import net.java.html.json.ModelOperation;
import net.java.html.json.Property;
import org.apidesign.demo.sieve.eratosthenes.Primes;
@ModelOperation
void initialize(Data model) {
Chart<Values, Config> chart = Chart.createLine(new Values.Set("a label", Color.valueOf("white"), Color.valueOf("black")));
data = chart.getData();
data.add(new Values("0", 0));
chart.applyTo("chart");
model.setStartOrStop("Start");
model.applyBindings();
}
@Function
void startStop(final Data model) {
if (model.isRunning()) {
model.setStartOrStop("Start");
model.setRunning(false);
} else {
model.setStartOrStop("Stop");
model.runMeasurement(Integer.MAX_VALUE);
}
}
@ModelOperation
void runMeasurement(final Data model, int cnt) {
model.setRunning(true);
final List<Integer> results = new ArrayList<>();
final int[] count = { cnt };
class Schedule extends TimerTask {
@Override
public void run() { | Primes p = new Primes() { |
wangwei86609/osmanthus | osmanthus-core/src/main/java/com/github/wei86609/osmanthus/ds/Interface.java | // Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/ds/arg/InArg.java
// @XStreamAlias("inArgs")
// public class InArg {
//
// @XStreamImplicit
// private List<Arg> args;
//
// public List<Arg> getArgs() {
// return this.args;
// }
//
// public void setArgs(List<Arg> args) {
// this.args = args;
// }
//
// public void addArg(Arg arg) {
// if (this.args == null) {
// this.args = new ArrayList<Arg>();
// }
// this.args.add(arg);
// }
// }
| import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.github.wei86609.osmanthus.ds.arg.InArg; | /*
* Copyright (c) 2017 PaiPai Credit Data Services (Shanghai) Co., Ltd All Rights Reserved.
*/
package com.github.wei86609.osmanthus.ds;
/**
* @author wangwei19
*/
@XStreamAlias("interface")
public class Interface extends DataSource {
private String queryVarName;
private String url;
private String method;
| // Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/ds/arg/InArg.java
// @XStreamAlias("inArgs")
// public class InArg {
//
// @XStreamImplicit
// private List<Arg> args;
//
// public List<Arg> getArgs() {
// return this.args;
// }
//
// public void setArgs(List<Arg> args) {
// this.args = args;
// }
//
// public void addArg(Arg arg) {
// if (this.args == null) {
// this.args = new ArrayList<Arg>();
// }
// this.args.add(arg);
// }
// }
// Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/ds/Interface.java
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.github.wei86609.osmanthus.ds.arg.InArg;
/*
* Copyright (c) 2017 PaiPai Credit Data Services (Shanghai) Co., Ltd All Rights Reserved.
*/
package com.github.wei86609.osmanthus.ds;
/**
* @author wangwei19
*/
@XStreamAlias("interface")
public class Interface extends DataSource {
private String queryVarName;
private String url;
private String method;
| private InArg inArg; |
wangwei86609/osmanthus | osmanthus-core/src/main/java/com/github/wei86609/osmanthus/rule/Rule.java | // Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/ds/DataSource.java
// public class DataSource {
//
// @XStreamAsAttribute
// private String name;
//
// @XStreamAsAttribute
// private String id;
//
// public String getName() {
// return this.name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getId() {
// return this.id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
// }
| import com.github.wei86609.osmanthus.ds.DataSource;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import com.thoughtworks.xstream.annotations.XStreamOmitField;
import java.util.List;
import java.util.Set; |
@XStreamOmitField
private Double ruleScore;
@XStreamOmitField
private Long startTime;
@XStreamOmitField
private Long endTime;
@XStreamOmitField
private Boolean error;
@XStreamOmitField
private String errorMsg;
@XStreamOmitField
private String errorCode;
@XStreamOmitField
private Boolean isHit;
private List<Vocabulary> vocabularies;
private List<Condition> conditions;
private List<Action> actions;
private List<Kpi> kpis;
| // Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/ds/DataSource.java
// public class DataSource {
//
// @XStreamAsAttribute
// private String name;
//
// @XStreamAsAttribute
// private String id;
//
// public String getName() {
// return this.name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getId() {
// return this.id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
// }
// Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/rule/Rule.java
import com.github.wei86609.osmanthus.ds.DataSource;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import com.thoughtworks.xstream.annotations.XStreamOmitField;
import java.util.List;
import java.util.Set;
@XStreamOmitField
private Double ruleScore;
@XStreamOmitField
private Long startTime;
@XStreamOmitField
private Long endTime;
@XStreamOmitField
private Boolean error;
@XStreamOmitField
private String errorMsg;
@XStreamOmitField
private String errorCode;
@XStreamOmitField
private Boolean isHit;
private List<Vocabulary> vocabularies;
private List<Condition> conditions;
private List<Action> actions;
private List<Kpi> kpis;
| private Set<DataSource> dataSources; |
wangwei86609/osmanthus | osmanthus-core/src/main/java/com/github/wei86609/osmanthus/utils/XstreamUtils.java | // Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/ds/Interface.java
// @XStreamAlias("interface")
// public class Interface extends DataSource {
//
// private String queryVarName;
//
// private String url;
//
// private String method;
//
// private InArg inArg;
//
// public InArg getInArg() {
// return this.inArg;
// }
//
// public void setInArg(InArg inArg) {
// this.inArg = inArg;
// }
//
// public String getUrl() {
// return this.url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public String getMethod() {
// return this.method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getQueryVarName() {
// return this.queryVarName;
// }
//
// public void setQueryVarName(String queryVarName) {
// this.queryVarName = queryVarName;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime
// * result
// + ((this.method == null) ? 0 : this.method.hashCode())
// + ((this.queryVarName == null) ? 0 : this.queryVarName
// .hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// Interface other = (Interface) obj;
// if (this.method == null) {
// if (other.method != null) {
// return false;
// }
// } else if (!this.method.equals(other.method)) {
// return false;
// }
// if (this.queryVarName == null) {
// if (other.queryVarName != null) {
// return false;
// }
// } else if (!this.queryVarName.equals(other.queryVarName)) {
// return false;
// }
// return true;
// }
// }
//
// Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/ds/arg/Arg.java
// @XStreamAlias("arg")
// public class Arg {
//
// @XStreamAsAttribute
// private String varId;
//
// @XStreamAsAttribute
// private String varName;
//
// @XStreamAsAttribute
// private String refVarName;
//
// public String getVarName() {
// return this.varName;
// }
//
// public void setVarName(String varName) {
// this.varName = varName;
// }
//
// public String getVarId() {
// return this.varId;
// }
//
// public void setVarId(String varId) {
// this.varId = varId;
// }
//
// public String getRefVarName() {
// return refVarName;
// }
//
// public void setRefVarName(String refVarName) {
// this.refVarName = refVarName;
// }
// }
//
// Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/ds/arg/InArg.java
// @XStreamAlias("inArgs")
// public class InArg {
//
// @XStreamImplicit
// private List<Arg> args;
//
// public List<Arg> getArgs() {
// return this.args;
// }
//
// public void setArgs(List<Arg> args) {
// this.args = args;
// }
//
// public void addArg(Arg arg) {
// if (this.args == null) {
// this.args = new ArrayList<Arg>();
// }
// this.args.add(arg);
// }
// }
| import com.github.wei86609.osmanthus.rule.*;
import com.github.wei86609.osmanthus.ds.Interface;
import com.github.wei86609.osmanthus.ds.arg.Arg;
import com.github.wei86609.osmanthus.ds.arg.InArg;
import com.thoughtworks.xstream.XStream; | package com.github.wei86609.osmanthus.utils;
public abstract class XstreamUtils {
protected static final Class[] SUPPORT_CLASSES = new Class[] {
KnowledgePackage.class, Start.class, End.class, RuleSet.class,
Rule.class, Split.class, Parallel.class, Merge.class,
Vocabulary.class, Action.class, Condition.class, Expression.class, | // Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/ds/Interface.java
// @XStreamAlias("interface")
// public class Interface extends DataSource {
//
// private String queryVarName;
//
// private String url;
//
// private String method;
//
// private InArg inArg;
//
// public InArg getInArg() {
// return this.inArg;
// }
//
// public void setInArg(InArg inArg) {
// this.inArg = inArg;
// }
//
// public String getUrl() {
// return this.url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public String getMethod() {
// return this.method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getQueryVarName() {
// return this.queryVarName;
// }
//
// public void setQueryVarName(String queryVarName) {
// this.queryVarName = queryVarName;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime
// * result
// + ((this.method == null) ? 0 : this.method.hashCode())
// + ((this.queryVarName == null) ? 0 : this.queryVarName
// .hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// Interface other = (Interface) obj;
// if (this.method == null) {
// if (other.method != null) {
// return false;
// }
// } else if (!this.method.equals(other.method)) {
// return false;
// }
// if (this.queryVarName == null) {
// if (other.queryVarName != null) {
// return false;
// }
// } else if (!this.queryVarName.equals(other.queryVarName)) {
// return false;
// }
// return true;
// }
// }
//
// Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/ds/arg/Arg.java
// @XStreamAlias("arg")
// public class Arg {
//
// @XStreamAsAttribute
// private String varId;
//
// @XStreamAsAttribute
// private String varName;
//
// @XStreamAsAttribute
// private String refVarName;
//
// public String getVarName() {
// return this.varName;
// }
//
// public void setVarName(String varName) {
// this.varName = varName;
// }
//
// public String getVarId() {
// return this.varId;
// }
//
// public void setVarId(String varId) {
// this.varId = varId;
// }
//
// public String getRefVarName() {
// return refVarName;
// }
//
// public void setRefVarName(String refVarName) {
// this.refVarName = refVarName;
// }
// }
//
// Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/ds/arg/InArg.java
// @XStreamAlias("inArgs")
// public class InArg {
//
// @XStreamImplicit
// private List<Arg> args;
//
// public List<Arg> getArgs() {
// return this.args;
// }
//
// public void setArgs(List<Arg> args) {
// this.args = args;
// }
//
// public void addArg(Arg arg) {
// if (this.args == null) {
// this.args = new ArrayList<Arg>();
// }
// this.args.add(arg);
// }
// }
// Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/utils/XstreamUtils.java
import com.github.wei86609.osmanthus.rule.*;
import com.github.wei86609.osmanthus.ds.Interface;
import com.github.wei86609.osmanthus.ds.arg.Arg;
import com.github.wei86609.osmanthus.ds.arg.InArg;
import com.thoughtworks.xstream.XStream;
package com.github.wei86609.osmanthus.utils;
public abstract class XstreamUtils {
protected static final Class[] SUPPORT_CLASSES = new Class[] {
KnowledgePackage.class, Start.class, End.class, RuleSet.class,
Rule.class, Split.class, Parallel.class, Merge.class,
Vocabulary.class, Action.class, Condition.class, Expression.class, | Interface.class, Arg.class, InArg.class }; |
wangwei86609/osmanthus | osmanthus-core/src/main/java/com/github/wei86609/osmanthus/utils/XstreamUtils.java | // Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/ds/Interface.java
// @XStreamAlias("interface")
// public class Interface extends DataSource {
//
// private String queryVarName;
//
// private String url;
//
// private String method;
//
// private InArg inArg;
//
// public InArg getInArg() {
// return this.inArg;
// }
//
// public void setInArg(InArg inArg) {
// this.inArg = inArg;
// }
//
// public String getUrl() {
// return this.url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public String getMethod() {
// return this.method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getQueryVarName() {
// return this.queryVarName;
// }
//
// public void setQueryVarName(String queryVarName) {
// this.queryVarName = queryVarName;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime
// * result
// + ((this.method == null) ? 0 : this.method.hashCode())
// + ((this.queryVarName == null) ? 0 : this.queryVarName
// .hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// Interface other = (Interface) obj;
// if (this.method == null) {
// if (other.method != null) {
// return false;
// }
// } else if (!this.method.equals(other.method)) {
// return false;
// }
// if (this.queryVarName == null) {
// if (other.queryVarName != null) {
// return false;
// }
// } else if (!this.queryVarName.equals(other.queryVarName)) {
// return false;
// }
// return true;
// }
// }
//
// Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/ds/arg/Arg.java
// @XStreamAlias("arg")
// public class Arg {
//
// @XStreamAsAttribute
// private String varId;
//
// @XStreamAsAttribute
// private String varName;
//
// @XStreamAsAttribute
// private String refVarName;
//
// public String getVarName() {
// return this.varName;
// }
//
// public void setVarName(String varName) {
// this.varName = varName;
// }
//
// public String getVarId() {
// return this.varId;
// }
//
// public void setVarId(String varId) {
// this.varId = varId;
// }
//
// public String getRefVarName() {
// return refVarName;
// }
//
// public void setRefVarName(String refVarName) {
// this.refVarName = refVarName;
// }
// }
//
// Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/ds/arg/InArg.java
// @XStreamAlias("inArgs")
// public class InArg {
//
// @XStreamImplicit
// private List<Arg> args;
//
// public List<Arg> getArgs() {
// return this.args;
// }
//
// public void setArgs(List<Arg> args) {
// this.args = args;
// }
//
// public void addArg(Arg arg) {
// if (this.args == null) {
// this.args = new ArrayList<Arg>();
// }
// this.args.add(arg);
// }
// }
| import com.github.wei86609.osmanthus.rule.*;
import com.github.wei86609.osmanthus.ds.Interface;
import com.github.wei86609.osmanthus.ds.arg.Arg;
import com.github.wei86609.osmanthus.ds.arg.InArg;
import com.thoughtworks.xstream.XStream; | package com.github.wei86609.osmanthus.utils;
public abstract class XstreamUtils {
protected static final Class[] SUPPORT_CLASSES = new Class[] {
KnowledgePackage.class, Start.class, End.class, RuleSet.class,
Rule.class, Split.class, Parallel.class, Merge.class,
Vocabulary.class, Action.class, Condition.class, Expression.class, | // Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/ds/Interface.java
// @XStreamAlias("interface")
// public class Interface extends DataSource {
//
// private String queryVarName;
//
// private String url;
//
// private String method;
//
// private InArg inArg;
//
// public InArg getInArg() {
// return this.inArg;
// }
//
// public void setInArg(InArg inArg) {
// this.inArg = inArg;
// }
//
// public String getUrl() {
// return this.url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public String getMethod() {
// return this.method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getQueryVarName() {
// return this.queryVarName;
// }
//
// public void setQueryVarName(String queryVarName) {
// this.queryVarName = queryVarName;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime
// * result
// + ((this.method == null) ? 0 : this.method.hashCode())
// + ((this.queryVarName == null) ? 0 : this.queryVarName
// .hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// Interface other = (Interface) obj;
// if (this.method == null) {
// if (other.method != null) {
// return false;
// }
// } else if (!this.method.equals(other.method)) {
// return false;
// }
// if (this.queryVarName == null) {
// if (other.queryVarName != null) {
// return false;
// }
// } else if (!this.queryVarName.equals(other.queryVarName)) {
// return false;
// }
// return true;
// }
// }
//
// Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/ds/arg/Arg.java
// @XStreamAlias("arg")
// public class Arg {
//
// @XStreamAsAttribute
// private String varId;
//
// @XStreamAsAttribute
// private String varName;
//
// @XStreamAsAttribute
// private String refVarName;
//
// public String getVarName() {
// return this.varName;
// }
//
// public void setVarName(String varName) {
// this.varName = varName;
// }
//
// public String getVarId() {
// return this.varId;
// }
//
// public void setVarId(String varId) {
// this.varId = varId;
// }
//
// public String getRefVarName() {
// return refVarName;
// }
//
// public void setRefVarName(String refVarName) {
// this.refVarName = refVarName;
// }
// }
//
// Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/ds/arg/InArg.java
// @XStreamAlias("inArgs")
// public class InArg {
//
// @XStreamImplicit
// private List<Arg> args;
//
// public List<Arg> getArgs() {
// return this.args;
// }
//
// public void setArgs(List<Arg> args) {
// this.args = args;
// }
//
// public void addArg(Arg arg) {
// if (this.args == null) {
// this.args = new ArrayList<Arg>();
// }
// this.args.add(arg);
// }
// }
// Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/utils/XstreamUtils.java
import com.github.wei86609.osmanthus.rule.*;
import com.github.wei86609.osmanthus.ds.Interface;
import com.github.wei86609.osmanthus.ds.arg.Arg;
import com.github.wei86609.osmanthus.ds.arg.InArg;
import com.thoughtworks.xstream.XStream;
package com.github.wei86609.osmanthus.utils;
public abstract class XstreamUtils {
protected static final Class[] SUPPORT_CLASSES = new Class[] {
KnowledgePackage.class, Start.class, End.class, RuleSet.class,
Rule.class, Split.class, Parallel.class, Merge.class,
Vocabulary.class, Action.class, Condition.class, Expression.class, | Interface.class, Arg.class, InArg.class }; |
wangwei86609/osmanthus | osmanthus-core/src/main/java/com/github/wei86609/osmanthus/utils/XstreamUtils.java | // Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/ds/Interface.java
// @XStreamAlias("interface")
// public class Interface extends DataSource {
//
// private String queryVarName;
//
// private String url;
//
// private String method;
//
// private InArg inArg;
//
// public InArg getInArg() {
// return this.inArg;
// }
//
// public void setInArg(InArg inArg) {
// this.inArg = inArg;
// }
//
// public String getUrl() {
// return this.url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public String getMethod() {
// return this.method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getQueryVarName() {
// return this.queryVarName;
// }
//
// public void setQueryVarName(String queryVarName) {
// this.queryVarName = queryVarName;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime
// * result
// + ((this.method == null) ? 0 : this.method.hashCode())
// + ((this.queryVarName == null) ? 0 : this.queryVarName
// .hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// Interface other = (Interface) obj;
// if (this.method == null) {
// if (other.method != null) {
// return false;
// }
// } else if (!this.method.equals(other.method)) {
// return false;
// }
// if (this.queryVarName == null) {
// if (other.queryVarName != null) {
// return false;
// }
// } else if (!this.queryVarName.equals(other.queryVarName)) {
// return false;
// }
// return true;
// }
// }
//
// Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/ds/arg/Arg.java
// @XStreamAlias("arg")
// public class Arg {
//
// @XStreamAsAttribute
// private String varId;
//
// @XStreamAsAttribute
// private String varName;
//
// @XStreamAsAttribute
// private String refVarName;
//
// public String getVarName() {
// return this.varName;
// }
//
// public void setVarName(String varName) {
// this.varName = varName;
// }
//
// public String getVarId() {
// return this.varId;
// }
//
// public void setVarId(String varId) {
// this.varId = varId;
// }
//
// public String getRefVarName() {
// return refVarName;
// }
//
// public void setRefVarName(String refVarName) {
// this.refVarName = refVarName;
// }
// }
//
// Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/ds/arg/InArg.java
// @XStreamAlias("inArgs")
// public class InArg {
//
// @XStreamImplicit
// private List<Arg> args;
//
// public List<Arg> getArgs() {
// return this.args;
// }
//
// public void setArgs(List<Arg> args) {
// this.args = args;
// }
//
// public void addArg(Arg arg) {
// if (this.args == null) {
// this.args = new ArrayList<Arg>();
// }
// this.args.add(arg);
// }
// }
| import com.github.wei86609.osmanthus.rule.*;
import com.github.wei86609.osmanthus.ds.Interface;
import com.github.wei86609.osmanthus.ds.arg.Arg;
import com.github.wei86609.osmanthus.ds.arg.InArg;
import com.thoughtworks.xstream.XStream; | package com.github.wei86609.osmanthus.utils;
public abstract class XstreamUtils {
protected static final Class[] SUPPORT_CLASSES = new Class[] {
KnowledgePackage.class, Start.class, End.class, RuleSet.class,
Rule.class, Split.class, Parallel.class, Merge.class,
Vocabulary.class, Action.class, Condition.class, Expression.class, | // Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/ds/Interface.java
// @XStreamAlias("interface")
// public class Interface extends DataSource {
//
// private String queryVarName;
//
// private String url;
//
// private String method;
//
// private InArg inArg;
//
// public InArg getInArg() {
// return this.inArg;
// }
//
// public void setInArg(InArg inArg) {
// this.inArg = inArg;
// }
//
// public String getUrl() {
// return this.url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public String getMethod() {
// return this.method;
// }
//
// public void setMethod(String method) {
// this.method = method;
// }
//
// public String getQueryVarName() {
// return this.queryVarName;
// }
//
// public void setQueryVarName(String queryVarName) {
// this.queryVarName = queryVarName;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime
// * result
// + ((this.method == null) ? 0 : this.method.hashCode())
// + ((this.queryVarName == null) ? 0 : this.queryVarName
// .hashCode());
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null) {
// return false;
// }
// if (getClass() != obj.getClass()) {
// return false;
// }
// Interface other = (Interface) obj;
// if (this.method == null) {
// if (other.method != null) {
// return false;
// }
// } else if (!this.method.equals(other.method)) {
// return false;
// }
// if (this.queryVarName == null) {
// if (other.queryVarName != null) {
// return false;
// }
// } else if (!this.queryVarName.equals(other.queryVarName)) {
// return false;
// }
// return true;
// }
// }
//
// Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/ds/arg/Arg.java
// @XStreamAlias("arg")
// public class Arg {
//
// @XStreamAsAttribute
// private String varId;
//
// @XStreamAsAttribute
// private String varName;
//
// @XStreamAsAttribute
// private String refVarName;
//
// public String getVarName() {
// return this.varName;
// }
//
// public void setVarName(String varName) {
// this.varName = varName;
// }
//
// public String getVarId() {
// return this.varId;
// }
//
// public void setVarId(String varId) {
// this.varId = varId;
// }
//
// public String getRefVarName() {
// return refVarName;
// }
//
// public void setRefVarName(String refVarName) {
// this.refVarName = refVarName;
// }
// }
//
// Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/ds/arg/InArg.java
// @XStreamAlias("inArgs")
// public class InArg {
//
// @XStreamImplicit
// private List<Arg> args;
//
// public List<Arg> getArgs() {
// return this.args;
// }
//
// public void setArgs(List<Arg> args) {
// this.args = args;
// }
//
// public void addArg(Arg arg) {
// if (this.args == null) {
// this.args = new ArrayList<Arg>();
// }
// this.args.add(arg);
// }
// }
// Path: osmanthus-core/src/main/java/com/github/wei86609/osmanthus/utils/XstreamUtils.java
import com.github.wei86609.osmanthus.rule.*;
import com.github.wei86609.osmanthus.ds.Interface;
import com.github.wei86609.osmanthus.ds.arg.Arg;
import com.github.wei86609.osmanthus.ds.arg.InArg;
import com.thoughtworks.xstream.XStream;
package com.github.wei86609.osmanthus.utils;
public abstract class XstreamUtils {
protected static final Class[] SUPPORT_CLASSES = new Class[] {
KnowledgePackage.class, Start.class, End.class, RuleSet.class,
Rule.class, Split.class, Parallel.class, Merge.class,
Vocabulary.class, Action.class, Condition.class, Expression.class, | Interface.class, Arg.class, InArg.class }; |
Bedework/exchange-ws-client | src/main/java/com/microsoft/exchange/autodiscover/PoxAutodiscoverServiceImpl.java | // Path: src/main/java/com/microsoft/exchange/exception/AutodiscoverException.java
// public class AutodiscoverException extends Exception{
// /**
// *
// */
// private static final long serialVersionUID = -7659779477291199459L;
// public AutodiscoverException(String s) {
// super(s);
// }
// public AutodiscoverException(Exception e) {
// super(e);
// }
// }
//
// Path: src/main/java/com/microsoft/exchange/exception/PoxAutodiscoverException.java
// public class PoxAutodiscoverException extends AutodiscoverException {
//
// /**
// *
// */
// private static final long serialVersionUID = -2218577466910957349L;
//
// public PoxAutodiscoverException(String s) {
// super(s);
// }
// public PoxAutodiscoverException(Exception e) {
// super(e);
// }
//
// }
| import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.w3c.dom.CharacterData;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import com.microsoft.exchange.exception.AutodiscoverException;
import com.microsoft.exchange.exception.PoxAutodiscoverException; | /**
* See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Board of Regents of the University of Wisconsin System
* licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a
* copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.microsoft.exchange.autodiscover;
/**
* An autodiscover implementation that queries all potential POX
* autodiscover endpoints for a given email address
*
* @see <a
* href="http://msdn.microsoft.com/EN-US/library/office/ee332364(v=exchg.140).aspx">Implementing
* an Autodiscover Client in Microsoft Exchange</a>
*
* @author ctcudd
*
*/
public class PoxAutodiscoverServiceImpl extends AbstractExchangeAutodiscoverService{
/**
* client should be configured with PoolingClientConnectionManager and Autodiscovery Redirect Strategy
*/
private DefaultHttpClient httpClient;
protected final Log log = LogFactory.getLog(this.getClass());
private static final String ENDPOINT_SUFFIX = "xml";
@Override
public String getServiceSuffix(){
return ENDPOINT_SUFFIX;
}
private static final String POX_REQUEST_FORMAT = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<Autodiscover xmlns=\"http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006\">" +
"<Request>"+
"<EMailAddress>%s</EMailAddress>"+
"<AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema>"+
"</Request>"+
"</Autodiscover>";
private static final String AS_REQUEST_FORMAT = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<Autodiscover xmlns=\"http://schemas.microsoft.com/exchange/autodiscover/mobilesync/requestschema/2006\">" +
"<Request>"+
"<EMailAddress>%s</EMailAddress>"+
"<AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/mobilesync/responseschema/2006</AcceptableResponseSchema>" +
"</Request>"+
"</Autodiscover>";
@Override | // Path: src/main/java/com/microsoft/exchange/exception/AutodiscoverException.java
// public class AutodiscoverException extends Exception{
// /**
// *
// */
// private static final long serialVersionUID = -7659779477291199459L;
// public AutodiscoverException(String s) {
// super(s);
// }
// public AutodiscoverException(Exception e) {
// super(e);
// }
// }
//
// Path: src/main/java/com/microsoft/exchange/exception/PoxAutodiscoverException.java
// public class PoxAutodiscoverException extends AutodiscoverException {
//
// /**
// *
// */
// private static final long serialVersionUID = -2218577466910957349L;
//
// public PoxAutodiscoverException(String s) {
// super(s);
// }
// public PoxAutodiscoverException(Exception e) {
// super(e);
// }
//
// }
// Path: src/main/java/com/microsoft/exchange/autodiscover/PoxAutodiscoverServiceImpl.java
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.w3c.dom.CharacterData;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import com.microsoft.exchange.exception.AutodiscoverException;
import com.microsoft.exchange.exception.PoxAutodiscoverException;
/**
* See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Board of Regents of the University of Wisconsin System
* licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a
* copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.microsoft.exchange.autodiscover;
/**
* An autodiscover implementation that queries all potential POX
* autodiscover endpoints for a given email address
*
* @see <a
* href="http://msdn.microsoft.com/EN-US/library/office/ee332364(v=exchg.140).aspx">Implementing
* an Autodiscover Client in Microsoft Exchange</a>
*
* @author ctcudd
*
*/
public class PoxAutodiscoverServiceImpl extends AbstractExchangeAutodiscoverService{
/**
* client should be configured with PoolingClientConnectionManager and Autodiscovery Redirect Strategy
*/
private DefaultHttpClient httpClient;
protected final Log log = LogFactory.getLog(this.getClass());
private static final String ENDPOINT_SUFFIX = "xml";
@Override
public String getServiceSuffix(){
return ENDPOINT_SUFFIX;
}
private static final String POX_REQUEST_FORMAT = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<Autodiscover xmlns=\"http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006\">" +
"<Request>"+
"<EMailAddress>%s</EMailAddress>"+
"<AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema>"+
"</Request>"+
"</Autodiscover>";
private static final String AS_REQUEST_FORMAT = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<Autodiscover xmlns=\"http://schemas.microsoft.com/exchange/autodiscover/mobilesync/requestschema/2006\">" +
"<Request>"+
"<EMailAddress>%s</EMailAddress>"+
"<AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/mobilesync/responseschema/2006</AcceptableResponseSchema>" +
"</Request>"+
"</Autodiscover>";
@Override | public String getAutodiscoverEndpoint(String email) throws AutodiscoverException { |
Bedework/exchange-ws-client | src/main/java/com/microsoft/exchange/autodiscover/PoxAutodiscoverServiceImpl.java | // Path: src/main/java/com/microsoft/exchange/exception/AutodiscoverException.java
// public class AutodiscoverException extends Exception{
// /**
// *
// */
// private static final long serialVersionUID = -7659779477291199459L;
// public AutodiscoverException(String s) {
// super(s);
// }
// public AutodiscoverException(Exception e) {
// super(e);
// }
// }
//
// Path: src/main/java/com/microsoft/exchange/exception/PoxAutodiscoverException.java
// public class PoxAutodiscoverException extends AutodiscoverException {
//
// /**
// *
// */
// private static final long serialVersionUID = -2218577466910957349L;
//
// public PoxAutodiscoverException(String s) {
// super(s);
// }
// public PoxAutodiscoverException(Exception e) {
// super(e);
// }
//
// }
| import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.w3c.dom.CharacterData;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import com.microsoft.exchange.exception.AutodiscoverException;
import com.microsoft.exchange.exception.PoxAutodiscoverException; | "<Request>"+
"<EMailAddress>%s</EMailAddress>"+
"<AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/mobilesync/responseschema/2006</AcceptableResponseSchema>" +
"</Request>"+
"</Autodiscover>";
@Override
public String getAutodiscoverEndpoint(String email) throws AutodiscoverException {
String ewsUrl = null;
String responseString = null;
String payload = String.format(POX_REQUEST_FORMAT,email);
for(String potential : getPotentialAutodiscoverEndpoints(email)){
log.info("attempting pox autodiscover for email="+email+" uri="+potential);
HttpPost request = new HttpPost(potential);
StringEntity requestEntity = new StringEntity(payload, getContentType());
request.setEntity(requestEntity);
try {
HttpResponse response = executeInternal(request);
responseString = parseHttpResponseToString(response);
if(StringUtils.isNotBlank(responseString)){
ewsUrl = parseResponseString(responseString);
if(StringUtils.isNotBlank(ewsUrl))
return ewsUrl;
}
} catch (Exception e) {
log.warn("caught exception while attempting POX autodiscover: "+e.getMessage());
}
} | // Path: src/main/java/com/microsoft/exchange/exception/AutodiscoverException.java
// public class AutodiscoverException extends Exception{
// /**
// *
// */
// private static final long serialVersionUID = -7659779477291199459L;
// public AutodiscoverException(String s) {
// super(s);
// }
// public AutodiscoverException(Exception e) {
// super(e);
// }
// }
//
// Path: src/main/java/com/microsoft/exchange/exception/PoxAutodiscoverException.java
// public class PoxAutodiscoverException extends AutodiscoverException {
//
// /**
// *
// */
// private static final long serialVersionUID = -2218577466910957349L;
//
// public PoxAutodiscoverException(String s) {
// super(s);
// }
// public PoxAutodiscoverException(Exception e) {
// super(e);
// }
//
// }
// Path: src/main/java/com/microsoft/exchange/autodiscover/PoxAutodiscoverServiceImpl.java
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.w3c.dom.CharacterData;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import com.microsoft.exchange.exception.AutodiscoverException;
import com.microsoft.exchange.exception.PoxAutodiscoverException;
"<Request>"+
"<EMailAddress>%s</EMailAddress>"+
"<AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/mobilesync/responseschema/2006</AcceptableResponseSchema>" +
"</Request>"+
"</Autodiscover>";
@Override
public String getAutodiscoverEndpoint(String email) throws AutodiscoverException {
String ewsUrl = null;
String responseString = null;
String payload = String.format(POX_REQUEST_FORMAT,email);
for(String potential : getPotentialAutodiscoverEndpoints(email)){
log.info("attempting pox autodiscover for email="+email+" uri="+potential);
HttpPost request = new HttpPost(potential);
StringEntity requestEntity = new StringEntity(payload, getContentType());
request.setEntity(requestEntity);
try {
HttpResponse response = executeInternal(request);
responseString = parseHttpResponseToString(response);
if(StringUtils.isNotBlank(responseString)){
ewsUrl = parseResponseString(responseString);
if(StringUtils.isNotBlank(ewsUrl))
return ewsUrl;
}
} catch (Exception e) {
log.warn("caught exception while attempting POX autodiscover: "+e.getMessage());
}
} | throw new PoxAutodiscoverException("POX autodiscover failed. cannot find ewsurl for email="+email); |
Bedework/exchange-ws-client | src/main/java/com/microsoft/exchange/autodiscover/SoapAutodiscoverServiceImpl.java | // Path: src/main/java/com/microsoft/exchange/exception/AutodiscoverException.java
// public class AutodiscoverException extends Exception{
// /**
// *
// */
// private static final long serialVersionUID = -7659779477291199459L;
// public AutodiscoverException(String s) {
// super(s);
// }
// public AutodiscoverException(Exception e) {
// super(e);
// }
// }
//
// Path: src/main/java/com/microsoft/exchange/exception/ExchangeWebServicesRuntimeException.java
// public class ExchangeWebServicesRuntimeException extends RuntimeException {
//
// /**
// *
// */
// private static final long serialVersionUID = 202143418251140727L;
//
// /**
// *
// */
// public ExchangeWebServicesRuntimeException() {
// }
//
// /**
// * @param message
// */
// public ExchangeWebServicesRuntimeException(String message) {
// super(message);
// }
//
// /**
// * @param cause
// */
// public ExchangeWebServicesRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * @param message
// * @param cause
// */
// public ExchangeWebServicesRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
//
// Path: src/main/java/com/microsoft/exchange/exception/SoapAutodiscoverException.java
// public class SoapAutodiscoverException extends AutodiscoverException{
//
// /**
// *
// */
// private static final long serialVersionUID = 5889558892962802033L;
//
// public SoapAutodiscoverException(String arg){
// super(arg);
// }
//
// public SoapAutodiscoverException(Exception arg){
// super(arg);
// }
// }
| import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import javax.xml.transform.TransformerException;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.oxm.Marshaller;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.client.core.WebServiceMessageCallback;
import org.springframework.ws.client.core.WebServiceOperations;
import org.springframework.ws.soap.SoapMessage;
import org.springframework.ws.soap.client.core.SoapActionCallback;
import org.springframework.xml.transform.StringResult;
import com.microsoft.exchange.exception.AutodiscoverException;
import com.microsoft.exchange.exception.ExchangeWebServicesRuntimeException;
import com.microsoft.exchange.exception.SoapAutodiscoverException; | private final static String ENDPOINT_SUFFIX = "svc";
@Override
public String getServiceSuffix(){
return ENDPOINT_SUFFIX;
}
private final ObjectFactory objectFactory = new ObjectFactory();
@Autowired
@Qualifier("autodiscoverWebServiceTemplate")
private WebServiceOperations webServiceOperations;
public WebServiceOperations getWebServiceOperations() {
return webServiceOperations;
}
public void setWebServiceOperations(WebServiceOperations webServiceOperations) {
this.webServiceOperations = webServiceOperations;
}
private Marshaller marshaller;
public Marshaller getMarshaller() {
return marshaller;
}
public void setMarshaller(Marshaller marshaller) {
this.marshaller = marshaller;
}
| // Path: src/main/java/com/microsoft/exchange/exception/AutodiscoverException.java
// public class AutodiscoverException extends Exception{
// /**
// *
// */
// private static final long serialVersionUID = -7659779477291199459L;
// public AutodiscoverException(String s) {
// super(s);
// }
// public AutodiscoverException(Exception e) {
// super(e);
// }
// }
//
// Path: src/main/java/com/microsoft/exchange/exception/ExchangeWebServicesRuntimeException.java
// public class ExchangeWebServicesRuntimeException extends RuntimeException {
//
// /**
// *
// */
// private static final long serialVersionUID = 202143418251140727L;
//
// /**
// *
// */
// public ExchangeWebServicesRuntimeException() {
// }
//
// /**
// * @param message
// */
// public ExchangeWebServicesRuntimeException(String message) {
// super(message);
// }
//
// /**
// * @param cause
// */
// public ExchangeWebServicesRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * @param message
// * @param cause
// */
// public ExchangeWebServicesRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
//
// Path: src/main/java/com/microsoft/exchange/exception/SoapAutodiscoverException.java
// public class SoapAutodiscoverException extends AutodiscoverException{
//
// /**
// *
// */
// private static final long serialVersionUID = 5889558892962802033L;
//
// public SoapAutodiscoverException(String arg){
// super(arg);
// }
//
// public SoapAutodiscoverException(Exception arg){
// super(arg);
// }
// }
// Path: src/main/java/com/microsoft/exchange/autodiscover/SoapAutodiscoverServiceImpl.java
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import javax.xml.transform.TransformerException;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.oxm.Marshaller;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.client.core.WebServiceMessageCallback;
import org.springframework.ws.client.core.WebServiceOperations;
import org.springframework.ws.soap.SoapMessage;
import org.springframework.ws.soap.client.core.SoapActionCallback;
import org.springframework.xml.transform.StringResult;
import com.microsoft.exchange.exception.AutodiscoverException;
import com.microsoft.exchange.exception.ExchangeWebServicesRuntimeException;
import com.microsoft.exchange.exception.SoapAutodiscoverException;
private final static String ENDPOINT_SUFFIX = "svc";
@Override
public String getServiceSuffix(){
return ENDPOINT_SUFFIX;
}
private final ObjectFactory objectFactory = new ObjectFactory();
@Autowired
@Qualifier("autodiscoverWebServiceTemplate")
private WebServiceOperations webServiceOperations;
public WebServiceOperations getWebServiceOperations() {
return webServiceOperations;
}
public void setWebServiceOperations(WebServiceOperations webServiceOperations) {
this.webServiceOperations = webServiceOperations;
}
private Marshaller marshaller;
public Marshaller getMarshaller() {
return marshaller;
}
public void setMarshaller(Marshaller marshaller) {
this.marshaller = marshaller;
}
| private String parseGetUserSettingsResponse( GetUserSettingsResponseMessage response) throws SoapAutodiscoverException { |
Bedework/exchange-ws-client | src/main/java/com/microsoft/exchange/autodiscover/SoapAutodiscoverServiceImpl.java | // Path: src/main/java/com/microsoft/exchange/exception/AutodiscoverException.java
// public class AutodiscoverException extends Exception{
// /**
// *
// */
// private static final long serialVersionUID = -7659779477291199459L;
// public AutodiscoverException(String s) {
// super(s);
// }
// public AutodiscoverException(Exception e) {
// super(e);
// }
// }
//
// Path: src/main/java/com/microsoft/exchange/exception/ExchangeWebServicesRuntimeException.java
// public class ExchangeWebServicesRuntimeException extends RuntimeException {
//
// /**
// *
// */
// private static final long serialVersionUID = 202143418251140727L;
//
// /**
// *
// */
// public ExchangeWebServicesRuntimeException() {
// }
//
// /**
// * @param message
// */
// public ExchangeWebServicesRuntimeException(String message) {
// super(message);
// }
//
// /**
// * @param cause
// */
// public ExchangeWebServicesRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * @param message
// * @param cause
// */
// public ExchangeWebServicesRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
//
// Path: src/main/java/com/microsoft/exchange/exception/SoapAutodiscoverException.java
// public class SoapAutodiscoverException extends AutodiscoverException{
//
// /**
// *
// */
// private static final long serialVersionUID = 5889558892962802033L;
//
// public SoapAutodiscoverException(String arg){
// super(arg);
// }
//
// public SoapAutodiscoverException(Exception arg){
// super(arg);
// }
// }
| import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import javax.xml.transform.TransformerException;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.oxm.Marshaller;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.client.core.WebServiceMessageCallback;
import org.springframework.ws.client.core.WebServiceOperations;
import org.springframework.ws.soap.SoapMessage;
import org.springframework.ws.soap.client.core.SoapActionCallback;
import org.springframework.xml.transform.StringResult;
import com.microsoft.exchange.exception.AutodiscoverException;
import com.microsoft.exchange.exception.ExchangeWebServicesRuntimeException;
import com.microsoft.exchange.exception.SoapAutodiscoverException; | if (!ErrorCode.NO_ERROR.equals(userResponse.getErrorCode())) {
error = true;
msg.append("Received error message obtaining user mailbox's server. Error "
+ userResponse.getErrorCode().value() + ": " + userResponse.getErrorMessage().getValue());
}
userSettings = userResponse.getUserSettings().getValue();
}
}
if (warning || error) {
throw new SoapAutodiscoverException("Unable to perform soap operation; try again later. Message text: "
+ msg.toString());
}
//return userSettings;
//UserSettings userSettings = sendMessageAndExtractSingleResponse(getUserSettingsSoapMessage, GET_USER_SETTINGS_ACTION);
//Give preference to Internal URL over External URL
String internalUri = null;
String externalUri = null;
for (UserSetting userSetting : userSettings.getUserSettings()) {
String potentialAccountServiceUrl = ((StringSetting) userSetting).getValue().getValue();
if (EXTERNAL_EWS_SERVER.equals(userSetting.getName())) {
externalUri = potentialAccountServiceUrl;
}
if (INTERNAL_EWS_SERVER.equals(userSetting.getName())) {
internalUri = potentialAccountServiceUrl;
}
}
if (internalUri == null && externalUri == null) { | // Path: src/main/java/com/microsoft/exchange/exception/AutodiscoverException.java
// public class AutodiscoverException extends Exception{
// /**
// *
// */
// private static final long serialVersionUID = -7659779477291199459L;
// public AutodiscoverException(String s) {
// super(s);
// }
// public AutodiscoverException(Exception e) {
// super(e);
// }
// }
//
// Path: src/main/java/com/microsoft/exchange/exception/ExchangeWebServicesRuntimeException.java
// public class ExchangeWebServicesRuntimeException extends RuntimeException {
//
// /**
// *
// */
// private static final long serialVersionUID = 202143418251140727L;
//
// /**
// *
// */
// public ExchangeWebServicesRuntimeException() {
// }
//
// /**
// * @param message
// */
// public ExchangeWebServicesRuntimeException(String message) {
// super(message);
// }
//
// /**
// * @param cause
// */
// public ExchangeWebServicesRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * @param message
// * @param cause
// */
// public ExchangeWebServicesRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
//
// Path: src/main/java/com/microsoft/exchange/exception/SoapAutodiscoverException.java
// public class SoapAutodiscoverException extends AutodiscoverException{
//
// /**
// *
// */
// private static final long serialVersionUID = 5889558892962802033L;
//
// public SoapAutodiscoverException(String arg){
// super(arg);
// }
//
// public SoapAutodiscoverException(Exception arg){
// super(arg);
// }
// }
// Path: src/main/java/com/microsoft/exchange/autodiscover/SoapAutodiscoverServiceImpl.java
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import javax.xml.transform.TransformerException;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.oxm.Marshaller;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.client.core.WebServiceMessageCallback;
import org.springframework.ws.client.core.WebServiceOperations;
import org.springframework.ws.soap.SoapMessage;
import org.springframework.ws.soap.client.core.SoapActionCallback;
import org.springframework.xml.transform.StringResult;
import com.microsoft.exchange.exception.AutodiscoverException;
import com.microsoft.exchange.exception.ExchangeWebServicesRuntimeException;
import com.microsoft.exchange.exception.SoapAutodiscoverException;
if (!ErrorCode.NO_ERROR.equals(userResponse.getErrorCode())) {
error = true;
msg.append("Received error message obtaining user mailbox's server. Error "
+ userResponse.getErrorCode().value() + ": " + userResponse.getErrorMessage().getValue());
}
userSettings = userResponse.getUserSettings().getValue();
}
}
if (warning || error) {
throw new SoapAutodiscoverException("Unable to perform soap operation; try again later. Message text: "
+ msg.toString());
}
//return userSettings;
//UserSettings userSettings = sendMessageAndExtractSingleResponse(getUserSettingsSoapMessage, GET_USER_SETTINGS_ACTION);
//Give preference to Internal URL over External URL
String internalUri = null;
String externalUri = null;
for (UserSetting userSetting : userSettings.getUserSettings()) {
String potentialAccountServiceUrl = ((StringSetting) userSetting).getValue().getValue();
if (EXTERNAL_EWS_SERVER.equals(userSetting.getName())) {
externalUri = potentialAccountServiceUrl;
}
if (INTERNAL_EWS_SERVER.equals(userSetting.getName())) {
internalUri = potentialAccountServiceUrl;
}
}
if (internalUri == null && externalUri == null) { | throw new ExchangeWebServicesRuntimeException("Unable to find EWS Server URI in properies " |
Bedework/exchange-ws-client | src/main/java/com/microsoft/exchange/autodiscover/SoapAutodiscoverServiceImpl.java | // Path: src/main/java/com/microsoft/exchange/exception/AutodiscoverException.java
// public class AutodiscoverException extends Exception{
// /**
// *
// */
// private static final long serialVersionUID = -7659779477291199459L;
// public AutodiscoverException(String s) {
// super(s);
// }
// public AutodiscoverException(Exception e) {
// super(e);
// }
// }
//
// Path: src/main/java/com/microsoft/exchange/exception/ExchangeWebServicesRuntimeException.java
// public class ExchangeWebServicesRuntimeException extends RuntimeException {
//
// /**
// *
// */
// private static final long serialVersionUID = 202143418251140727L;
//
// /**
// *
// */
// public ExchangeWebServicesRuntimeException() {
// }
//
// /**
// * @param message
// */
// public ExchangeWebServicesRuntimeException(String message) {
// super(message);
// }
//
// /**
// * @param cause
// */
// public ExchangeWebServicesRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * @param message
// * @param cause
// */
// public ExchangeWebServicesRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
//
// Path: src/main/java/com/microsoft/exchange/exception/SoapAutodiscoverException.java
// public class SoapAutodiscoverException extends AutodiscoverException{
//
// /**
// *
// */
// private static final long serialVersionUID = 5889558892962802033L;
//
// public SoapAutodiscoverException(String arg){
// super(arg);
// }
//
// public SoapAutodiscoverException(Exception arg){
// super(arg);
// }
// }
| import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import javax.xml.transform.TransformerException;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.oxm.Marshaller;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.client.core.WebServiceMessageCallback;
import org.springframework.ws.client.core.WebServiceOperations;
import org.springframework.ws.soap.SoapMessage;
import org.springframework.ws.soap.client.core.SoapActionCallback;
import org.springframework.xml.transform.StringResult;
import com.microsoft.exchange.exception.AutodiscoverException;
import com.microsoft.exchange.exception.ExchangeWebServicesRuntimeException;
import com.microsoft.exchange.exception.SoapAutodiscoverException; | if (log.isDebugEnabled()) {
StringResult message = new StringResult();
try {
marshaller.marshal(soapRequest, message);
log.debug("Attempting to send SOAP request to "+uri+"\nSoap Action: "+soapAction+"\nSoap message body"
+ " (not exact, log org.apache.http.wire to see actual message):\n"+ message);
} catch (IOException ex) {
log.debug("IOException attempting to display soap response", ex);
}
}
// use the request to retrieve data from the Exchange server
try{
response = (GetUserSettingsResponseMessage) webServiceOperations.marshalSendAndReceive(uri, soapRequest, customCallback);
}catch(Exception e){
log.warn("getUserSettings for uri="+uri+" failed: "+e.getMessage());
}
if (log.isDebugEnabled()) {
StringResult messageResponse = new StringResult();
try {
marshaller.marshal(response, messageResponse);
log.debug("Soap response body (not exact, log org.apache.http.wire to see actual message):\n"+messageResponse );
} catch (IOException exception) {
log.debug("IOException attempting to display soap response", exception);
}
}
return response;
}
@Override | // Path: src/main/java/com/microsoft/exchange/exception/AutodiscoverException.java
// public class AutodiscoverException extends Exception{
// /**
// *
// */
// private static final long serialVersionUID = -7659779477291199459L;
// public AutodiscoverException(String s) {
// super(s);
// }
// public AutodiscoverException(Exception e) {
// super(e);
// }
// }
//
// Path: src/main/java/com/microsoft/exchange/exception/ExchangeWebServicesRuntimeException.java
// public class ExchangeWebServicesRuntimeException extends RuntimeException {
//
// /**
// *
// */
// private static final long serialVersionUID = 202143418251140727L;
//
// /**
// *
// */
// public ExchangeWebServicesRuntimeException() {
// }
//
// /**
// * @param message
// */
// public ExchangeWebServicesRuntimeException(String message) {
// super(message);
// }
//
// /**
// * @param cause
// */
// public ExchangeWebServicesRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * @param message
// * @param cause
// */
// public ExchangeWebServicesRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
//
// Path: src/main/java/com/microsoft/exchange/exception/SoapAutodiscoverException.java
// public class SoapAutodiscoverException extends AutodiscoverException{
//
// /**
// *
// */
// private static final long serialVersionUID = 5889558892962802033L;
//
// public SoapAutodiscoverException(String arg){
// super(arg);
// }
//
// public SoapAutodiscoverException(Exception arg){
// super(arg);
// }
// }
// Path: src/main/java/com/microsoft/exchange/autodiscover/SoapAutodiscoverServiceImpl.java
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import javax.xml.transform.TransformerException;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.oxm.Marshaller;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.client.core.WebServiceMessageCallback;
import org.springframework.ws.client.core.WebServiceOperations;
import org.springframework.ws.soap.SoapMessage;
import org.springframework.ws.soap.client.core.SoapActionCallback;
import org.springframework.xml.transform.StringResult;
import com.microsoft.exchange.exception.AutodiscoverException;
import com.microsoft.exchange.exception.ExchangeWebServicesRuntimeException;
import com.microsoft.exchange.exception.SoapAutodiscoverException;
if (log.isDebugEnabled()) {
StringResult message = new StringResult();
try {
marshaller.marshal(soapRequest, message);
log.debug("Attempting to send SOAP request to "+uri+"\nSoap Action: "+soapAction+"\nSoap message body"
+ " (not exact, log org.apache.http.wire to see actual message):\n"+ message);
} catch (IOException ex) {
log.debug("IOException attempting to display soap response", ex);
}
}
// use the request to retrieve data from the Exchange server
try{
response = (GetUserSettingsResponseMessage) webServiceOperations.marshalSendAndReceive(uri, soapRequest, customCallback);
}catch(Exception e){
log.warn("getUserSettings for uri="+uri+" failed: "+e.getMessage());
}
if (log.isDebugEnabled()) {
StringResult messageResponse = new StringResult();
try {
marshaller.marshal(response, messageResponse);
log.debug("Soap response body (not exact, log org.apache.http.wire to see actual message):\n"+messageResponse );
} catch (IOException exception) {
log.debug("IOException attempting to display soap response", exception);
}
}
return response;
}
@Override | public String getAutodiscoverEndpoint(String email) throws AutodiscoverException { |
Bedework/exchange-ws-client | src/main/java/com/microsoft/exchange/impl/http/CustomHttpComponentsMessageSender.java | // Path: src/main/java/com/microsoft/exchange/impl/ExchangeOnlineThrottlingPolicy.java
// public class ExchangeOnlineThrottlingPolicy {
//
// /**
// * Indicates that there are more concurrent requests against the server than are allowed by a user's policy.
// */
// public static final String ERROR_EXCEEDED_CONNECTION_COUNT = "ErrorExceededConnectionCount";
// /**
// * Indicates that a user's throttling policy maximum subscription count has been exceeded.
// */
// public static final String ERROR_EXCEEDED_SUBSCRIPTION_COUNT = "ErrorExceededSubscriptionCount";
// /**
// * Indicates that a search operation call has exceeded the total number of items that can be returned.
// */
// public static final String ERROR_EXCEEDED_FIND_COUNT_LIMIT = "ErrorExceededFindCountLimit";
// /**
// * Occurs when the server is busy.
// */
// public static final String ERROR_SERVER_BUSY = "ErrorServerBusy";
// /**
// * The maximum number of entries returned for FindItem requests.
// */
// public static final int FIND_ITEM_MAX_ENTRIES_RETURNED = 1000;
// /**
// * The maximum number of concurrent connections for a service account using impersonation.
// */
// public static final int MAX_CONCURRENT_CONNECTIONS_IMPERSONATION = 10;
// }
| import org.apache.http.impl.auth.DigestScheme;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.pool.ConnPoolControl;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.springframework.ws.transport.http.HttpComponentsMessageSender;
import com.microsoft.exchange.impl.ExchangeOnlineThrottlingPolicy;
import java.net.URI;
import org.apache.http.auth.AuthScheme;
import org.apache.http.auth.AuthScope;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.impl.auth.BasicScheme; | public void setPreemptiveAuthScope(AuthScope preemptiveAuthScope) {
this.preemptiveAuthScope = preemptiveAuthScope;
}
/**
* @return the credentialsProviderFactory
*/
public CredentialsProviderFactory getCredentialsProviderFactory() {
return credentialsProviderFactory;
}
/**
* @param credentialsProviderFactory the credentialsProviderFactory to set
*/
public void setCredentialsProviderFactory(
CredentialsProviderFactory credentialsProviderFactory) {
this.credentialsProviderFactory = credentialsProviderFactory;
}
/* (non-Javadoc)
* @see org.springframework.ws.transport.http.HttpComponentsMessageSender#afterPropertiesSet()
*/
@Override
public void afterPropertiesSet() throws Exception {
super.afterPropertiesSet();
if(isPreemptiveAuthEnabled()) {
this.preemptiveAuthScheme = identifyScheme(getPreemptiveAuthScope().getScheme());
}
boolean overrideSuccess = false;
if(defaultMaxPerRouteOverride != null) {
overrideSuccess = this.overrideDefaultMaxPerRoute(defaultMaxPerRouteOverride);
}
| // Path: src/main/java/com/microsoft/exchange/impl/ExchangeOnlineThrottlingPolicy.java
// public class ExchangeOnlineThrottlingPolicy {
//
// /**
// * Indicates that there are more concurrent requests against the server than are allowed by a user's policy.
// */
// public static final String ERROR_EXCEEDED_CONNECTION_COUNT = "ErrorExceededConnectionCount";
// /**
// * Indicates that a user's throttling policy maximum subscription count has been exceeded.
// */
// public static final String ERROR_EXCEEDED_SUBSCRIPTION_COUNT = "ErrorExceededSubscriptionCount";
// /**
// * Indicates that a search operation call has exceeded the total number of items that can be returned.
// */
// public static final String ERROR_EXCEEDED_FIND_COUNT_LIMIT = "ErrorExceededFindCountLimit";
// /**
// * Occurs when the server is busy.
// */
// public static final String ERROR_SERVER_BUSY = "ErrorServerBusy";
// /**
// * The maximum number of entries returned for FindItem requests.
// */
// public static final int FIND_ITEM_MAX_ENTRIES_RETURNED = 1000;
// /**
// * The maximum number of concurrent connections for a service account using impersonation.
// */
// public static final int MAX_CONCURRENT_CONNECTIONS_IMPERSONATION = 10;
// }
// Path: src/main/java/com/microsoft/exchange/impl/http/CustomHttpComponentsMessageSender.java
import org.apache.http.impl.auth.DigestScheme;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.pool.ConnPoolControl;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.springframework.ws.transport.http.HttpComponentsMessageSender;
import com.microsoft.exchange.impl.ExchangeOnlineThrottlingPolicy;
import java.net.URI;
import org.apache.http.auth.AuthScheme;
import org.apache.http.auth.AuthScope;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.impl.auth.BasicScheme;
public void setPreemptiveAuthScope(AuthScope preemptiveAuthScope) {
this.preemptiveAuthScope = preemptiveAuthScope;
}
/**
* @return the credentialsProviderFactory
*/
public CredentialsProviderFactory getCredentialsProviderFactory() {
return credentialsProviderFactory;
}
/**
* @param credentialsProviderFactory the credentialsProviderFactory to set
*/
public void setCredentialsProviderFactory(
CredentialsProviderFactory credentialsProviderFactory) {
this.credentialsProviderFactory = credentialsProviderFactory;
}
/* (non-Javadoc)
* @see org.springframework.ws.transport.http.HttpComponentsMessageSender#afterPropertiesSet()
*/
@Override
public void afterPropertiesSet() throws Exception {
super.afterPropertiesSet();
if(isPreemptiveAuthEnabled()) {
this.preemptiveAuthScheme = identifyScheme(getPreemptiveAuthScope().getScheme());
}
boolean overrideSuccess = false;
if(defaultMaxPerRouteOverride != null) {
overrideSuccess = this.overrideDefaultMaxPerRoute(defaultMaxPerRouteOverride);
}
| if(overrideSuccess && defaultMaxPerRouteOverride > ExchangeOnlineThrottlingPolicy.MAX_CONCURRENT_CONNECTIONS_IMPERSONATION) { |
Bedework/exchange-ws-client | src/main/java/com/microsoft/exchange/autodiscover/AutodiscoverRedirectStrategy.java | // Path: src/main/java/com/microsoft/exchange/exception/ExchangeWebServicesRuntimeException.java
// public class ExchangeWebServicesRuntimeException extends RuntimeException {
//
// /**
// *
// */
// private static final long serialVersionUID = 202143418251140727L;
//
// /**
// *
// */
// public ExchangeWebServicesRuntimeException() {
// }
//
// /**
// * @param message
// */
// public ExchangeWebServicesRuntimeException(String message) {
// super(message);
// }
//
// /**
// * @param cause
// */
// public ExchangeWebServicesRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * @param message
// * @param cause
// */
// public ExchangeWebServicesRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
| import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.ProtocolException;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.LaxRedirectStrategy;
import org.apache.http.protocol.HttpContext;
import com.microsoft.exchange.exception.ExchangeWebServicesRuntimeException; | * Overrides behavior to follow redirects for POST messages, AND to have the redirect be a POST. Behavior of
* <code>DefaultRedirectStrategy</code> is to use a GET for the redirect (though against spec this is the
* de-facto standard, see http://www.mail-archive.com/httpclient-users@hc.apache.org/msg06327.html and
* http://www.alanflavell.org.uk/www/post-redirect.html).
*
* For our application, we want to follow the redirect for a 302 as long as it is to a safe location and
* have the redirect be a POST.
*
* This code is modified from http-components' http-client 4.2.5. Since we only use POST the code for the
* other HTTP methods has been removed to simplify this method.
*
* @param request Http request
* @param response Http response
* @param context Http context
* @return Request to issue to the redirected location
* @throws ProtocolException protocol exception
*/
@Override
public HttpUriRequest getRedirect(
final HttpRequest request,
final HttpResponse response,
final HttpContext context) throws ProtocolException {
URI uri = getLocationURI(request, response, context);
log.info("Following redirect to "+ uri.toString());
String method = request.getRequestLine().getMethod();
int status = response.getStatusLine().getStatusCode();
// Insure location is safe
if (matchesPatternSet(uri, unsafeUriPatterns)) {
log.warn("Not following to URI {} - matches a configured unsafe URI pattern "+ uri.toString()); | // Path: src/main/java/com/microsoft/exchange/exception/ExchangeWebServicesRuntimeException.java
// public class ExchangeWebServicesRuntimeException extends RuntimeException {
//
// /**
// *
// */
// private static final long serialVersionUID = 202143418251140727L;
//
// /**
// *
// */
// public ExchangeWebServicesRuntimeException() {
// }
//
// /**
// * @param message
// */
// public ExchangeWebServicesRuntimeException(String message) {
// super(message);
// }
//
// /**
// * @param cause
// */
// public ExchangeWebServicesRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * @param message
// * @param cause
// */
// public ExchangeWebServicesRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
// Path: src/main/java/com/microsoft/exchange/autodiscover/AutodiscoverRedirectStrategy.java
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.ProtocolException;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.LaxRedirectStrategy;
import org.apache.http.protocol.HttpContext;
import com.microsoft.exchange.exception.ExchangeWebServicesRuntimeException;
* Overrides behavior to follow redirects for POST messages, AND to have the redirect be a POST. Behavior of
* <code>DefaultRedirectStrategy</code> is to use a GET for the redirect (though against spec this is the
* de-facto standard, see http://www.mail-archive.com/httpclient-users@hc.apache.org/msg06327.html and
* http://www.alanflavell.org.uk/www/post-redirect.html).
*
* For our application, we want to follow the redirect for a 302 as long as it is to a safe location and
* have the redirect be a POST.
*
* This code is modified from http-components' http-client 4.2.5. Since we only use POST the code for the
* other HTTP methods has been removed to simplify this method.
*
* @param request Http request
* @param response Http response
* @param context Http context
* @return Request to issue to the redirected location
* @throws ProtocolException protocol exception
*/
@Override
public HttpUriRequest getRedirect(
final HttpRequest request,
final HttpResponse response,
final HttpContext context) throws ProtocolException {
URI uri = getLocationURI(request, response, context);
log.info("Following redirect to "+ uri.toString());
String method = request.getRequestLine().getMethod();
int status = response.getStatusLine().getStatusCode();
// Insure location is safe
if (matchesPatternSet(uri, unsafeUriPatterns)) {
log.warn("Not following to URI {} - matches a configured unsafe URI pattern "+ uri.toString()); | throw new ExchangeWebServicesRuntimeException("Autodiscover redirected to unsafe URI " + uri.toString()); |
Bedework/exchange-ws-client | src/main/java/com/microsoft/exchange/impl/RequestServerVersionClientInterceptor.java | // Path: src/main/java/com/microsoft/exchange/exception/ExchangeWebServicesRuntimeException.java
// public class ExchangeWebServicesRuntimeException extends RuntimeException {
//
// /**
// *
// */
// private static final long serialVersionUID = 202143418251140727L;
//
// /**
// *
// */
// public ExchangeWebServicesRuntimeException() {
// }
//
// /**
// * @param message
// */
// public ExchangeWebServicesRuntimeException(String message) {
// super(message);
// }
//
// /**
// * @param cause
// */
// public ExchangeWebServicesRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * @param message
// * @param cause
// */
// public ExchangeWebServicesRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
| import org.springframework.ws.client.WebServiceClientException;
import org.springframework.ws.client.support.interceptor.ClientInterceptor;
import org.springframework.ws.context.MessageContext;
import org.springframework.ws.soap.SoapEnvelope;
import org.springframework.ws.soap.SoapHeader;
import org.springframework.ws.soap.SoapMessage;
import com.microsoft.exchange.exception.ExchangeWebServicesRuntimeException;
import com.microsoft.exchange.impl.http.CredentialsProviderFactory;
import com.microsoft.exchange.types.ExchangeVersionType;
import com.microsoft.exchange.types.RequestServerVersion;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.WebServiceMessage; | /**
* See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Board of Regents of the University of Wisconsin System
* licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a
* copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
*
*/
package com.microsoft.exchange.impl;
/**
* {@link ClientInterceptor} to add a {@link RequestServerVersion}
* with the configured {@link ExchangeVersionType} to the SOAP Header.
*
* Note that while Microsoft documents the {@link RequestServerVersion} element in the header
* as OPTIONAL, you will need to require this interceptor if you are using the {@link CredentialsProviderFactory}
* integration strategy (as opposed to impersonation).
*
* @author Nicholas Blair
*/
public class RequestServerVersionClientInterceptor implements ClientInterceptor {
protected final Log log = LogFactory.getLog(this.getClass());
private JAXBContext jaxbContext;
/**
* @return the jaxbContext
*/
public JAXBContext getJaxbContext() {
return jaxbContext;
}
/**
* @param jaxbContext the jaxbContext to set
*/
@Autowired
public void setJaxbContext(JAXBContext jaxbContext) {
this.jaxbContext = jaxbContext;
}
/* (non-Javadoc)
* @see org.springframework.ws.client.support.interceptor.ClientInterceptor#handleRequest(org.springframework.ws.context.MessageContext)
*/
@Override
public boolean handleRequest(MessageContext messageContext)
throws WebServiceClientException {
WebServiceMessage request = messageContext.getRequest();
if(request instanceof SoapMessage) {
SoapMessage soapMessage = (SoapMessage) request;
SoapEnvelope envelope = soapMessage.getEnvelope();
SoapHeader header = envelope.getHeader();
RequestServerVersion rsv = new RequestServerVersion();
try {
Marshaller m = jaxbContext.createMarshaller();
m.marshal(rsv, header.getResult());
} catch (JAXBException e) {
log.error("JAXBException raised while attempting to add RequestServerVersion to soap header " + rsv, e); | // Path: src/main/java/com/microsoft/exchange/exception/ExchangeWebServicesRuntimeException.java
// public class ExchangeWebServicesRuntimeException extends RuntimeException {
//
// /**
// *
// */
// private static final long serialVersionUID = 202143418251140727L;
//
// /**
// *
// */
// public ExchangeWebServicesRuntimeException() {
// }
//
// /**
// * @param message
// */
// public ExchangeWebServicesRuntimeException(String message) {
// super(message);
// }
//
// /**
// * @param cause
// */
// public ExchangeWebServicesRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * @param message
// * @param cause
// */
// public ExchangeWebServicesRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
// Path: src/main/java/com/microsoft/exchange/impl/RequestServerVersionClientInterceptor.java
import org.springframework.ws.client.WebServiceClientException;
import org.springframework.ws.client.support.interceptor.ClientInterceptor;
import org.springframework.ws.context.MessageContext;
import org.springframework.ws.soap.SoapEnvelope;
import org.springframework.ws.soap.SoapHeader;
import org.springframework.ws.soap.SoapMessage;
import com.microsoft.exchange.exception.ExchangeWebServicesRuntimeException;
import com.microsoft.exchange.impl.http.CredentialsProviderFactory;
import com.microsoft.exchange.types.ExchangeVersionType;
import com.microsoft.exchange.types.RequestServerVersion;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.WebServiceMessage;
/**
* See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Board of Regents of the University of Wisconsin System
* licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a
* copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
*
*/
package com.microsoft.exchange.impl;
/**
* {@link ClientInterceptor} to add a {@link RequestServerVersion}
* with the configured {@link ExchangeVersionType} to the SOAP Header.
*
* Note that while Microsoft documents the {@link RequestServerVersion} element in the header
* as OPTIONAL, you will need to require this interceptor if you are using the {@link CredentialsProviderFactory}
* integration strategy (as opposed to impersonation).
*
* @author Nicholas Blair
*/
public class RequestServerVersionClientInterceptor implements ClientInterceptor {
protected final Log log = LogFactory.getLog(this.getClass());
private JAXBContext jaxbContext;
/**
* @return the jaxbContext
*/
public JAXBContext getJaxbContext() {
return jaxbContext;
}
/**
* @param jaxbContext the jaxbContext to set
*/
@Autowired
public void setJaxbContext(JAXBContext jaxbContext) {
this.jaxbContext = jaxbContext;
}
/* (non-Javadoc)
* @see org.springframework.ws.client.support.interceptor.ClientInterceptor#handleRequest(org.springframework.ws.context.MessageContext)
*/
@Override
public boolean handleRequest(MessageContext messageContext)
throws WebServiceClientException {
WebServiceMessage request = messageContext.getRequest();
if(request instanceof SoapMessage) {
SoapMessage soapMessage = (SoapMessage) request;
SoapEnvelope envelope = soapMessage.getEnvelope();
SoapHeader header = envelope.getHeader();
RequestServerVersion rsv = new RequestServerVersion();
try {
Marshaller m = jaxbContext.createMarshaller();
m.marshal(rsv, header.getResult());
} catch (JAXBException e) {
log.error("JAXBException raised while attempting to add RequestServerVersion to soap header " + rsv, e); | throw new ExchangeWebServicesRuntimeException("JAXBException raised while attempting to add RequestServerVersion to soap header " + rsv, e); |
Bedework/exchange-ws-client | src/main/java/com/microsoft/exchange/impl/RequestServerTimeZoneInterceptor.java | // Path: src/main/java/com/microsoft/exchange/exception/ExchangeWebServicesRuntimeException.java
// public class ExchangeWebServicesRuntimeException extends RuntimeException {
//
// /**
// *
// */
// private static final long serialVersionUID = 202143418251140727L;
//
// /**
// *
// */
// public ExchangeWebServicesRuntimeException() {
// }
//
// /**
// * @param message
// */
// public ExchangeWebServicesRuntimeException(String message) {
// super(message);
// }
//
// /**
// * @param cause
// */
// public ExchangeWebServicesRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * @param message
// * @param cause
// */
// public ExchangeWebServicesRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
| import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.client.WebServiceClientException;
import org.springframework.ws.client.support.interceptor.ClientInterceptor;
import org.springframework.ws.context.MessageContext;
import org.springframework.ws.soap.SoapEnvelope;
import org.springframework.ws.soap.SoapHeader;
import org.springframework.ws.soap.SoapMessage;
import com.ibm.icu.util.TimeZone;
import com.microsoft.exchange.exception.ExchangeWebServicesRuntimeException;
import com.microsoft.exchange.types.TimeZoneContext;
import com.microsoft.exchange.types.TimeZoneDefinitionType; | /**
* See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Board of Regents of the University of Wisconsin System
* licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a
* copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.microsoft.exchange.impl;
/**
*
* The TimeZoneContext element is used in the Simple Object Access Protocol
* (SOAP) header to specify the time zone definition that is to be used as the
* default when assigning the time zone for the DateTime properties of objects
* that are created, updated, and retrieved by using Exchange Web Services
* (EWS).
*
* @see <a href="http://msdn.microsoft.com/en-us/library/dd899417(EXCHG.140).aspx>Working with Time Zones in Exchange 2010 Exchange Web Services</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/office/dd899417(v=exchg.150).aspx">TimeZoneContext</a>
* @see <a href="http://support.microsoft.com/kb/973627">Microsoft Time Zone Index Values</a>'
*
* Other important links for consideration:
* <a href="http://icu-project.org/apiref/icu4j/com/ibm/icu/util/TimeZone.html">ICU4J</a> has a set of mappings for windows timezones.
* They get the info from unicode.org, I assume I can trust their mappings: http://cldr.unicode.org/development/development-process/design-proposals/extended-windows-olson-zid-mapping
* http://www.unicode.org/cldr/charts/latest/supplemental/zone_tzid.html
* @author ctcudd
*
*/
public class RequestServerTimeZoneInterceptor implements ClientInterceptor, InitializingBean {
protected final Log log = LogFactory.getLog(this.getClass());
private JAXBContext jaxbContext;
/**
* @return the jaxbContext
*/
public JAXBContext getJaxbContext() {
return jaxbContext;
}
/**
* @param jaxbContext
* the jaxbContext to set
*/
@Autowired
public void setJaxbContext(JAXBContext jaxbContext) {
this.jaxbContext = jaxbContext;
}
//try to set this with a valid windows time zone id which matches the jvm timezone
private String windowsTimeZoneID;
public String getWindowsTimeZoneID(){
return this.windowsTimeZoneID;
}
//as long as we set the time zone context to match the jvm time zone, things should be ok. UTC should match regardless of environment(s)
public static final String FALLBACK_TIMEZONE_ID="UTC";
@Override
public boolean handleRequest(MessageContext messageContext)
throws WebServiceClientException {
WebServiceMessage request = messageContext.getRequest();
if(!isTimeZoneValid()){ | // Path: src/main/java/com/microsoft/exchange/exception/ExchangeWebServicesRuntimeException.java
// public class ExchangeWebServicesRuntimeException extends RuntimeException {
//
// /**
// *
// */
// private static final long serialVersionUID = 202143418251140727L;
//
// /**
// *
// */
// public ExchangeWebServicesRuntimeException() {
// }
//
// /**
// * @param message
// */
// public ExchangeWebServicesRuntimeException(String message) {
// super(message);
// }
//
// /**
// * @param cause
// */
// public ExchangeWebServicesRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * @param message
// * @param cause
// */
// public ExchangeWebServicesRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// }
// Path: src/main/java/com/microsoft/exchange/impl/RequestServerTimeZoneInterceptor.java
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.client.WebServiceClientException;
import org.springframework.ws.client.support.interceptor.ClientInterceptor;
import org.springframework.ws.context.MessageContext;
import org.springframework.ws.soap.SoapEnvelope;
import org.springframework.ws.soap.SoapHeader;
import org.springframework.ws.soap.SoapMessage;
import com.ibm.icu.util.TimeZone;
import com.microsoft.exchange.exception.ExchangeWebServicesRuntimeException;
import com.microsoft.exchange.types.TimeZoneContext;
import com.microsoft.exchange.types.TimeZoneDefinitionType;
/**
* See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Board of Regents of the University of Wisconsin System
* licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a
* copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.microsoft.exchange.impl;
/**
*
* The TimeZoneContext element is used in the Simple Object Access Protocol
* (SOAP) header to specify the time zone definition that is to be used as the
* default when assigning the time zone for the DateTime properties of objects
* that are created, updated, and retrieved by using Exchange Web Services
* (EWS).
*
* @see <a href="http://msdn.microsoft.com/en-us/library/dd899417(EXCHG.140).aspx>Working with Time Zones in Exchange 2010 Exchange Web Services</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/office/dd899417(v=exchg.150).aspx">TimeZoneContext</a>
* @see <a href="http://support.microsoft.com/kb/973627">Microsoft Time Zone Index Values</a>'
*
* Other important links for consideration:
* <a href="http://icu-project.org/apiref/icu4j/com/ibm/icu/util/TimeZone.html">ICU4J</a> has a set of mappings for windows timezones.
* They get the info from unicode.org, I assume I can trust their mappings: http://cldr.unicode.org/development/development-process/design-proposals/extended-windows-olson-zid-mapping
* http://www.unicode.org/cldr/charts/latest/supplemental/zone_tzid.html
* @author ctcudd
*
*/
public class RequestServerTimeZoneInterceptor implements ClientInterceptor, InitializingBean {
protected final Log log = LogFactory.getLog(this.getClass());
private JAXBContext jaxbContext;
/**
* @return the jaxbContext
*/
public JAXBContext getJaxbContext() {
return jaxbContext;
}
/**
* @param jaxbContext
* the jaxbContext to set
*/
@Autowired
public void setJaxbContext(JAXBContext jaxbContext) {
this.jaxbContext = jaxbContext;
}
//try to set this with a valid windows time zone id which matches the jvm timezone
private String windowsTimeZoneID;
public String getWindowsTimeZoneID(){
return this.windowsTimeZoneID;
}
//as long as we set the time zone context to match the jvm time zone, things should be ok. UTC should match regardless of environment(s)
public static final String FALLBACK_TIMEZONE_ID="UTC";
@Override
public boolean handleRequest(MessageContext messageContext)
throws WebServiceClientException {
WebServiceMessage request = messageContext.getRequest();
if(!isTimeZoneValid()){ | throw new ExchangeWebServicesRuntimeException("RequestServerTimeZoneInterceptor - the windowsTimeZoneID specified ("+this.windowsTimeZoneID+") does not match this systems default time zone ("+TimeZone.getDefault().getID()+")"); |
Bedework/exchange-ws-client | src/main/java/com/microsoft/exchange/autodiscover/CompositeAutodiscoverServiceImpl.java | // Path: src/main/java/com/microsoft/exchange/exception/AutodiscoverException.java
// public class AutodiscoverException extends Exception{
// /**
// *
// */
// private static final long serialVersionUID = -7659779477291199459L;
// public AutodiscoverException(String s) {
// super(s);
// }
// public AutodiscoverException(Exception e) {
// super(e);
// }
// }
| import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.googlecode.ehcache.annotations.Cacheable;
import com.microsoft.exchange.exception.AutodiscoverException; | /**
* See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Board of Regents of the University of Wisconsin System
* licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a
* copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.microsoft.exchange.autodiscover;
/**
* An autodiscover implementation that queries all potential SOAP and POX
* autodiscover endpoints for a given email address
*
* @see <a href="http://msdn.microsoft.com/EN-US/library/office/ee332364(v=exchg.140).aspx">Implementing an Autodiscover Client in Microsoft Exchange</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/office/dn528374(v=exchg.150).aspx">When to use autodiscover</a>
*
* @author ctcudd
*
*/
public class CompositeAutodiscoverServiceImpl implements ExchangeAutodiscoverService {
protected final Log log = LogFactory.getLog(this.getClass());
@Autowired
private Collection<ExchangeAutodiscoverService> autodiscoverServices;
@Override
@Cacheable(cacheName="autodiscoverCache") | // Path: src/main/java/com/microsoft/exchange/exception/AutodiscoverException.java
// public class AutodiscoverException extends Exception{
// /**
// *
// */
// private static final long serialVersionUID = -7659779477291199459L;
// public AutodiscoverException(String s) {
// super(s);
// }
// public AutodiscoverException(Exception e) {
// super(e);
// }
// }
// Path: src/main/java/com/microsoft/exchange/autodiscover/CompositeAutodiscoverServiceImpl.java
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.googlecode.ehcache.annotations.Cacheable;
import com.microsoft.exchange.exception.AutodiscoverException;
/**
* See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Board of Regents of the University of Wisconsin System
* licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a
* copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.microsoft.exchange.autodiscover;
/**
* An autodiscover implementation that queries all potential SOAP and POX
* autodiscover endpoints for a given email address
*
* @see <a href="http://msdn.microsoft.com/EN-US/library/office/ee332364(v=exchg.140).aspx">Implementing an Autodiscover Client in Microsoft Exchange</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/office/dn528374(v=exchg.150).aspx">When to use autodiscover</a>
*
* @author ctcudd
*
*/
public class CompositeAutodiscoverServiceImpl implements ExchangeAutodiscoverService {
protected final Log log = LogFactory.getLog(this.getClass());
@Autowired
private Collection<ExchangeAutodiscoverService> autodiscoverServices;
@Override
@Cacheable(cacheName="autodiscoverCache") | public String getAutodiscoverEndpoint(String email) throws AutodiscoverException { |
Bedework/exchange-ws-client | src/main/java/com/microsoft/exchange/autodiscover/AutodiscoverDestinationProvider.java | // Path: src/main/java/com/microsoft/exchange/exception/AutodiscoverException.java
// public class AutodiscoverException extends Exception{
// /**
// *
// */
// private static final long serialVersionUID = -7659779477291199459L;
// public AutodiscoverException(String s) {
// super(s);
// }
// public AutodiscoverException(Exception e) {
// super(e);
// }
// }
| import com.microsoft.exchange.exception.AutodiscoverException;
import com.microsoft.exchange.impl.ImpersonationConnectingSIDSource;
import com.microsoft.exchange.types.ConnectingSIDType;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.ws.client.support.destination.DestinationProvider; | */
@Autowired
public void setConnectingSIDSource(ImpersonationConnectingSIDSource connectingSIDSource) {
this.connectingSIDSource = connectingSIDSource;
}
public ExchangeAutodiscoverService getCompositeAutodiscoverService() {
return compositeAutodiscoverService;
}
@Autowired
public void setCompositeAutodiscoverService(ExchangeAutodiscoverService compositeAutodiscoverService) {
this.compositeAutodiscoverService = compositeAutodiscoverService;
}
/* (non-Javadoc)
* @see org.springframework.ws.client.support.destination.DestinationProvider#getDestination()
*/
@Override
public URI getDestination() {
URI autodiscoverURI = null;
String autodiscoverEndpoint = getDefaultUri();
ConnectingSIDType connectingSID = connectingSIDSource.getConnectingSID(null, null);
if(null != connectingSID){
String upn = connectingSID.getPrincipalName();
try {
autodiscoverEndpoint = compositeAutodiscoverService.getAutodiscoverEndpoint(upn); | // Path: src/main/java/com/microsoft/exchange/exception/AutodiscoverException.java
// public class AutodiscoverException extends Exception{
// /**
// *
// */
// private static final long serialVersionUID = -7659779477291199459L;
// public AutodiscoverException(String s) {
// super(s);
// }
// public AutodiscoverException(Exception e) {
// super(e);
// }
// }
// Path: src/main/java/com/microsoft/exchange/autodiscover/AutodiscoverDestinationProvider.java
import com.microsoft.exchange.exception.AutodiscoverException;
import com.microsoft.exchange.impl.ImpersonationConnectingSIDSource;
import com.microsoft.exchange.types.ConnectingSIDType;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.ws.client.support.destination.DestinationProvider;
*/
@Autowired
public void setConnectingSIDSource(ImpersonationConnectingSIDSource connectingSIDSource) {
this.connectingSIDSource = connectingSIDSource;
}
public ExchangeAutodiscoverService getCompositeAutodiscoverService() {
return compositeAutodiscoverService;
}
@Autowired
public void setCompositeAutodiscoverService(ExchangeAutodiscoverService compositeAutodiscoverService) {
this.compositeAutodiscoverService = compositeAutodiscoverService;
}
/* (non-Javadoc)
* @see org.springframework.ws.client.support.destination.DestinationProvider#getDestination()
*/
@Override
public URI getDestination() {
URI autodiscoverURI = null;
String autodiscoverEndpoint = getDefaultUri();
ConnectingSIDType connectingSID = connectingSIDSource.getConnectingSID(null, null);
if(null != connectingSID){
String upn = connectingSID.getPrincipalName();
try {
autodiscoverEndpoint = compositeAutodiscoverService.getAutodiscoverEndpoint(upn); | } catch (AutodiscoverException e) { |
Bedework/exchange-ws-client | src/main/java/com/microsoft/exchange/autodiscover/AbstractExchangeAutodiscoverService.java | // Path: src/main/java/com/microsoft/exchange/exception/AutodiscoverException.java
// public class AutodiscoverException extends Exception{
// /**
// *
// */
// private static final long serialVersionUID = -7659779477291199459L;
// public AutodiscoverException(String s) {
// super(s);
// }
// public AutodiscoverException(Exception e) {
// super(e);
// }
// }
| import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.validator.routines.EmailValidator;
import org.apache.http.entity.ContentType;
import com.microsoft.exchange.exception.AutodiscoverException; | /**
* See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Board of Regents of the University of Wisconsin System
* licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a
* copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.microsoft.exchange.autodiscover;
public abstract class AbstractExchangeAutodiscoverService implements ExchangeAutodiscoverService {
protected Log log = LogFactory.getLog(this.getClass());
/**
* Don't use this. all you should need is an email address to discover an EWS ENDPOINT
*/
@Deprecated
protected static final String AUTODISCOVER_URL = "https://autodiscover-s.outlook.com/autodiscover/autodiscover.xml";
private static final String TEXT_XML = "text/xml";
private static final String UTF_8 = "UTF-8";
private static final ContentType CONTENT_TYPE = ContentType.create(TEXT_XML, UTF_8);
private static final List<String> SCHEMES;
private static final List<String> AUTODISCOVER_ENDPOINT_PATTERNS;
static{
List<String> autoDiscoverEndpoints = new ArrayList<String>();
autoDiscoverEndpoints.add("{scheme}://{domain}/autodiscover/autodiscover.{serviceSuffix}");
autoDiscoverEndpoints.add("{scheme}://autodiscover.{domain}/autodiscover/autodiscover.{serviceSuffix}");
//fallback pattern
//autoDiscoverEndpoints.add("https://autodiscover-s.outlook.com/autodiscover/autodiscover.{serviceSuffix}");
AUTODISCOVER_ENDPOINT_PATTERNS = Collections.unmodifiableList(autoDiscoverEndpoints);
//prefer https, see: http://msdn.microsoft.com/en-us/library/office/jj900169(v=exchg.150).aspx
List<String> schemes = new ArrayList<String>();
schemes.add("https");
schemes.add("http");
SCHEMES = Collections.unmodifiableList(schemes);
}
protected ContentType getContentType(){
return CONTENT_TYPE;
}
/**
*
* @return the url suffix for the autodiscover service.
*
* POX = .xml
* SOAP = .svc
*/
abstract protected String getServiceSuffix();
@Override
public List<String> getPotentialAutodiscoverEndpoints(String email) {
String domain = null;
List<String> potentialEndpoints = new ArrayList<String>();
try{
domain = extractDomainFromEmail(email); | // Path: src/main/java/com/microsoft/exchange/exception/AutodiscoverException.java
// public class AutodiscoverException extends Exception{
// /**
// *
// */
// private static final long serialVersionUID = -7659779477291199459L;
// public AutodiscoverException(String s) {
// super(s);
// }
// public AutodiscoverException(Exception e) {
// super(e);
// }
// }
// Path: src/main/java/com/microsoft/exchange/autodiscover/AbstractExchangeAutodiscoverService.java
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.validator.routines.EmailValidator;
import org.apache.http.entity.ContentType;
import com.microsoft.exchange.exception.AutodiscoverException;
/**
* See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Board of Regents of the University of Wisconsin System
* licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a
* copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.microsoft.exchange.autodiscover;
public abstract class AbstractExchangeAutodiscoverService implements ExchangeAutodiscoverService {
protected Log log = LogFactory.getLog(this.getClass());
/**
* Don't use this. all you should need is an email address to discover an EWS ENDPOINT
*/
@Deprecated
protected static final String AUTODISCOVER_URL = "https://autodiscover-s.outlook.com/autodiscover/autodiscover.xml";
private static final String TEXT_XML = "text/xml";
private static final String UTF_8 = "UTF-8";
private static final ContentType CONTENT_TYPE = ContentType.create(TEXT_XML, UTF_8);
private static final List<String> SCHEMES;
private static final List<String> AUTODISCOVER_ENDPOINT_PATTERNS;
static{
List<String> autoDiscoverEndpoints = new ArrayList<String>();
autoDiscoverEndpoints.add("{scheme}://{domain}/autodiscover/autodiscover.{serviceSuffix}");
autoDiscoverEndpoints.add("{scheme}://autodiscover.{domain}/autodiscover/autodiscover.{serviceSuffix}");
//fallback pattern
//autoDiscoverEndpoints.add("https://autodiscover-s.outlook.com/autodiscover/autodiscover.{serviceSuffix}");
AUTODISCOVER_ENDPOINT_PATTERNS = Collections.unmodifiableList(autoDiscoverEndpoints);
//prefer https, see: http://msdn.microsoft.com/en-us/library/office/jj900169(v=exchg.150).aspx
List<String> schemes = new ArrayList<String>();
schemes.add("https");
schemes.add("http");
SCHEMES = Collections.unmodifiableList(schemes);
}
protected ContentType getContentType(){
return CONTENT_TYPE;
}
/**
*
* @return the url suffix for the autodiscover service.
*
* POX = .xml
* SOAP = .svc
*/
abstract protected String getServiceSuffix();
@Override
public List<String> getPotentialAutodiscoverEndpoints(String email) {
String domain = null;
List<String> potentialEndpoints = new ArrayList<String>();
try{
domain = extractDomainFromEmail(email); | }catch(AutodiscoverException e){ |
Bedework/exchange-ws-client | src/test/java/com/microsoft/exchange/integration/NtlmCredentialsIntegrationTest.java | // Path: src/main/java/com/microsoft/exchange/impl/http/ThreadLocalCredentialsProviderFactory.java
// public class ThreadLocalCredentialsProviderFactory implements CredentialsProviderFactory {
//
// private static final ThreadLocal<Credentials> threadLocal = new ThreadLocal<Credentials>();
//
// /*
// * (non-Javadoc)
// * @see com.microsoft.exchange.impl.http.CredentialsProviderFactory#getCredentialsProvider(java.net.URI)
// */
// @Override
// public CredentialsProvider getCredentialsProvider(URI uri) {
// return new CredentialsProvider() {
// @Override
// public void setCredentials(AuthScope authscope,
// Credentials credentials) {
// ThreadLocalCredentialsProviderFactory.set(credentials);
// }
// @Override
// public Credentials getCredentials(AuthScope authscope) {
// return ThreadLocalCredentialsProviderFactory.get();
// }
// @Override
// public void clear() {
// ThreadLocalCredentialsProviderFactory.clear();
// }
// };
// }
//
// /**
// *
// * @return the current {@link Credentials} stored in the {@link ThreadLocal}.
// */
// public static Credentials get() {
// return threadLocal.get();
// }
//
// /**
// * Set a {@link Credentials} instance in the {@link ThreadLocal}
// * @param credentials
// */
// public static void set(Credentials credentials) {
// threadLocal.set(credentials);
// }
//
// /**
// * Clear the {@link ThreadLocal}.
// * @see {@link ThreadLocal#remove()}
// */
// public static void clear() {
// threadLocal.remove();
// }
// }
| import com.microsoft.exchange.messages.FindFolderResponse;
import static org.junit.Assert.*;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.NTCredentials;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.microsoft.exchange.impl.http.ThreadLocalCredentialsProviderFactory;
import com.microsoft.exchange.messages.FindFolder; | /**
* See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Board of Regents of the University of Wisconsin System
* licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a
* copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.microsoft.exchange.integration;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:/com/microsoft/exchange/exchangeContext-usingNtlmCredentials.xml")
public class NtlmCredentialsIntegrationTest extends AbstractIntegrationTest {
@Value("${username}")
private String userName;
@Value("${password}")
private String password;
@Value("${domain}")
private String domain;
@Test
public void isAutowired() {
assertNotNull(ewsClient);
}
@Override
public void initializeCredentials() {
Credentials credentials = new NTCredentials(userName, password, "", domain); | // Path: src/main/java/com/microsoft/exchange/impl/http/ThreadLocalCredentialsProviderFactory.java
// public class ThreadLocalCredentialsProviderFactory implements CredentialsProviderFactory {
//
// private static final ThreadLocal<Credentials> threadLocal = new ThreadLocal<Credentials>();
//
// /*
// * (non-Javadoc)
// * @see com.microsoft.exchange.impl.http.CredentialsProviderFactory#getCredentialsProvider(java.net.URI)
// */
// @Override
// public CredentialsProvider getCredentialsProvider(URI uri) {
// return new CredentialsProvider() {
// @Override
// public void setCredentials(AuthScope authscope,
// Credentials credentials) {
// ThreadLocalCredentialsProviderFactory.set(credentials);
// }
// @Override
// public Credentials getCredentials(AuthScope authscope) {
// return ThreadLocalCredentialsProviderFactory.get();
// }
// @Override
// public void clear() {
// ThreadLocalCredentialsProviderFactory.clear();
// }
// };
// }
//
// /**
// *
// * @return the current {@link Credentials} stored in the {@link ThreadLocal}.
// */
// public static Credentials get() {
// return threadLocal.get();
// }
//
// /**
// * Set a {@link Credentials} instance in the {@link ThreadLocal}
// * @param credentials
// */
// public static void set(Credentials credentials) {
// threadLocal.set(credentials);
// }
//
// /**
// * Clear the {@link ThreadLocal}.
// * @see {@link ThreadLocal#remove()}
// */
// public static void clear() {
// threadLocal.remove();
// }
// }
// Path: src/test/java/com/microsoft/exchange/integration/NtlmCredentialsIntegrationTest.java
import com.microsoft.exchange.messages.FindFolderResponse;
import static org.junit.Assert.*;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.NTCredentials;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.microsoft.exchange.impl.http.ThreadLocalCredentialsProviderFactory;
import com.microsoft.exchange.messages.FindFolder;
/**
* See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Board of Regents of the University of Wisconsin System
* licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a
* copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.microsoft.exchange.integration;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:/com/microsoft/exchange/exchangeContext-usingNtlmCredentials.xml")
public class NtlmCredentialsIntegrationTest extends AbstractIntegrationTest {
@Value("${username}")
private String userName;
@Value("${password}")
private String password;
@Value("${domain}")
private String domain;
@Test
public void isAutowired() {
assertNotNull(ewsClient);
}
@Override
public void initializeCredentials() {
Credentials credentials = new NTCredentials(userName, password, "", domain); | ThreadLocalCredentialsProviderFactory.set(credentials); |
jvanhie/discogsscrobbler | app/src/main/java/com/github/jvanhie/discogsscrobbler/DrawerActivity.java | // Path: app/src/main/java/com/github/jvanhie/discogsscrobbler/adapters/NavDrawerListAdapter.java
// public class NavDrawerListAdapter extends BaseAdapter {
//
// private Context mContext;
// private ArrayList<NavDrawerItem> navDrawerItems;
//
// public NavDrawerListAdapter(Context context){
// this.mContext = context;
// this.navDrawerItems = new ArrayList<NavDrawerItem>();
// }
//
// public void addItem(String title, int icon) {
// navDrawerItems.add(new NavDrawerItem(title,icon));
// }
//
// @Override
// public int getCount() {
// return navDrawerItems.size();
// }
//
// @Override
// public Object getItem(int position) {
// return navDrawerItems.get(position);
// }
//
// @Override
// public long getItemId(int position) {
// return position;
// }
//
// @SuppressLint("InflateParams")
// @Override
// public View getView(int position, View convertView, ViewGroup parent) {
// if (convertView == null) {
// if(mContext == null) return null;
// LayoutInflater mInflater = (LayoutInflater)
// mContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
// convertView = mInflater.inflate(R.layout.drawer_list_item, null);
// }
//
// ImageView imgIcon = (ImageView) convertView.findViewById(R.id.icon);
// TextView txtTitle = (TextView) convertView.findViewById(R.id.title);
//
// imgIcon.setImageResource(navDrawerItems.get(position).icon);
// txtTitle.setText(navDrawerItems.get(position).title);
//
// return convertView;
// }
//
// private class NavDrawerItem {
// public String title;
// public int icon;
//
// public NavDrawerItem(){}
//
// public NavDrawerItem(String title, int icon){
// this.title = title;
// this.icon = icon;
// }
//
// }
//
// }
| import com.github.jvanhie.discogsscrobbler.adapters.NavDrawerListAdapter;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView; | /*
* Copyright (c) 2014 Jono Vanhie-Van Gerwen
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.jvanhie.discogsscrobbler;
/**
* Created by Jono on 01/04/2014.
*/
public abstract class DrawerActivity extends ActionBarActivity {
private CharSequence mDrawerTitle;
private CharSequence mTitle;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
public void setDrawer(int layout, int list, String title, String drawerTitle, boolean showDrawerIcon) {
mTitle = title;
mDrawerTitle = drawerTitle;
mDrawerLayout = (DrawerLayout) findViewById(layout);
//populate the navigation drawer
mDrawerList = (ListView) findViewById(list);
// set a custom shadow that overlays the main content when the drawer opens
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// load slide menu items
String[] navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);
// nav drawer icons from resources
TypedArray navMenuIcons = getResources().obtainTypedArray(R.array.nav_drawer_icons); | // Path: app/src/main/java/com/github/jvanhie/discogsscrobbler/adapters/NavDrawerListAdapter.java
// public class NavDrawerListAdapter extends BaseAdapter {
//
// private Context mContext;
// private ArrayList<NavDrawerItem> navDrawerItems;
//
// public NavDrawerListAdapter(Context context){
// this.mContext = context;
// this.navDrawerItems = new ArrayList<NavDrawerItem>();
// }
//
// public void addItem(String title, int icon) {
// navDrawerItems.add(new NavDrawerItem(title,icon));
// }
//
// @Override
// public int getCount() {
// return navDrawerItems.size();
// }
//
// @Override
// public Object getItem(int position) {
// return navDrawerItems.get(position);
// }
//
// @Override
// public long getItemId(int position) {
// return position;
// }
//
// @SuppressLint("InflateParams")
// @Override
// public View getView(int position, View convertView, ViewGroup parent) {
// if (convertView == null) {
// if(mContext == null) return null;
// LayoutInflater mInflater = (LayoutInflater)
// mContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
// convertView = mInflater.inflate(R.layout.drawer_list_item, null);
// }
//
// ImageView imgIcon = (ImageView) convertView.findViewById(R.id.icon);
// TextView txtTitle = (TextView) convertView.findViewById(R.id.title);
//
// imgIcon.setImageResource(navDrawerItems.get(position).icon);
// txtTitle.setText(navDrawerItems.get(position).title);
//
// return convertView;
// }
//
// private class NavDrawerItem {
// public String title;
// public int icon;
//
// public NavDrawerItem(){}
//
// public NavDrawerItem(String title, int icon){
// this.title = title;
// this.icon = icon;
// }
//
// }
//
// }
// Path: app/src/main/java/com/github/jvanhie/discogsscrobbler/DrawerActivity.java
import com.github.jvanhie.discogsscrobbler.adapters.NavDrawerListAdapter;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
/*
* Copyright (c) 2014 Jono Vanhie-Van Gerwen
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.jvanhie.discogsscrobbler;
/**
* Created by Jono on 01/04/2014.
*/
public abstract class DrawerActivity extends ActionBarActivity {
private CharSequence mDrawerTitle;
private CharSequence mTitle;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
public void setDrawer(int layout, int list, String title, String drawerTitle, boolean showDrawerIcon) {
mTitle = title;
mDrawerTitle = drawerTitle;
mDrawerLayout = (DrawerLayout) findViewById(layout);
//populate the navigation drawer
mDrawerList = (ListView) findViewById(list);
// set a custom shadow that overlays the main content when the drawer opens
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// load slide menu items
String[] navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);
// nav drawer icons from resources
TypedArray navMenuIcons = getResources().obtainTypedArray(R.array.nav_drawer_icons); | NavDrawerListAdapter adapter = new NavDrawerListAdapter(this); |
jvanhie/discogsscrobbler | app/src/main/java/com/github/jvanhie/discogsscrobbler/models/Folder.java | // Path: app/src/main/java/com/github/jvanhie/discogsscrobbler/queries/DiscogsFolders.java
// public class DiscogsFolders {
// public List<Folder> folders;
//
// public class Folder {
// public long id;
// public int count;
// public String name;
// }
// }
| import com.activeandroid.Model;
import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table;
import com.github.jvanhie.discogsscrobbler.queries.DiscogsFolders; | /*
* Copyright (c) 2014 Jono Vanhie-Van Gerwen
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.jvanhie.discogsscrobbler.models;
/**
* Created by Jono on 08/05/2014.
*/
@Table(name = "folders")
public class Folder extends Model {
@Column(name = "folderid", unique = true, onUniqueConflict = Column.ConflictAction.REPLACE)
public long folderid;
@Column(name = "count")
public int count;
@Column(name = "name")
public String name;
public Folder() {
super();
}
| // Path: app/src/main/java/com/github/jvanhie/discogsscrobbler/queries/DiscogsFolders.java
// public class DiscogsFolders {
// public List<Folder> folders;
//
// public class Folder {
// public long id;
// public int count;
// public String name;
// }
// }
// Path: app/src/main/java/com/github/jvanhie/discogsscrobbler/models/Folder.java
import com.activeandroid.Model;
import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table;
import com.github.jvanhie.discogsscrobbler.queries.DiscogsFolders;
/*
* Copyright (c) 2014 Jono Vanhie-Van Gerwen
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.jvanhie.discogsscrobbler.models;
/**
* Created by Jono on 08/05/2014.
*/
@Table(name = "folders")
public class Folder extends Model {
@Column(name = "folderid", unique = true, onUniqueConflict = Column.ConflictAction.REPLACE)
public long folderid;
@Column(name = "count")
public int count;
@Column(name = "name")
public String name;
public Folder() {
super();
}
| public Folder(DiscogsFolders.Folder f) { |
jvanhie/discogsscrobbler | app/src/main/java/com/github/jvanhie/discogsscrobbler/models/Image.java | // Path: app/src/main/java/com/github/jvanhie/discogsscrobbler/queries/DiscogsRelease.java
// public class DiscogsRelease {
// public long id;
// public String title;
// public int year;
// public String resource_url;
// public int master_id;
// public String master_url;
// public String country;
// public String released_formatted;
// public String notes;
// public String thumb;
//
// public String[] styles;
// public String[] genres;
// public List<Artist> artists;
// public List<Label> labels;
// public List<Format> formats;
// public List<Image> images;
// public List<Track> tracklist;
//
// public class Artist {
// public String join="";
// public String name;
// }
//
// public class Label {
// public String name;
// }
//
// public class Format {
// public String qty;
// public String[] descriptions;
// public String text;
// public String name;
// }
//
// public class Image {
// public String type;
// public int width;
// public int height;
// public String uri;
// public String uri150;
// }
//
// public class Track {
// public String duration;
// public String position;
// public String title;
// public String type_;
// public List<Artist> artists;
// }
//
// }
| import com.activeandroid.Model;
import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table;
import com.github.jvanhie.discogsscrobbler.queries.DiscogsRelease; | /*
* Copyright (c) 2014 Jono Vanhie-Van Gerwen
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.jvanhie.discogsscrobbler.models;
/**
* Created by Jono on 22/03/2014.
*/
@Table(name = "images")
public class Image extends Model{
@Column(name = "release", onDelete = Column.ForeignKeyAction.CASCADE)
public Release release;
@Column(name = "idx")
public int idx;
@Column(name = "type")
public String type;
@Column(name = "width")
public int width;
@Column(name = "height")
public int height;
@Column(name = "uri")
public String uri;
@Column(name = "uri150")
public String uri150;
public Image() {
super();
}
| // Path: app/src/main/java/com/github/jvanhie/discogsscrobbler/queries/DiscogsRelease.java
// public class DiscogsRelease {
// public long id;
// public String title;
// public int year;
// public String resource_url;
// public int master_id;
// public String master_url;
// public String country;
// public String released_formatted;
// public String notes;
// public String thumb;
//
// public String[] styles;
// public String[] genres;
// public List<Artist> artists;
// public List<Label> labels;
// public List<Format> formats;
// public List<Image> images;
// public List<Track> tracklist;
//
// public class Artist {
// public String join="";
// public String name;
// }
//
// public class Label {
// public String name;
// }
//
// public class Format {
// public String qty;
// public String[] descriptions;
// public String text;
// public String name;
// }
//
// public class Image {
// public String type;
// public int width;
// public int height;
// public String uri;
// public String uri150;
// }
//
// public class Track {
// public String duration;
// public String position;
// public String title;
// public String type_;
// public List<Artist> artists;
// }
//
// }
// Path: app/src/main/java/com/github/jvanhie/discogsscrobbler/models/Image.java
import com.activeandroid.Model;
import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table;
import com.github.jvanhie.discogsscrobbler.queries.DiscogsRelease;
/*
* Copyright (c) 2014 Jono Vanhie-Van Gerwen
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.jvanhie.discogsscrobbler.models;
/**
* Created by Jono on 22/03/2014.
*/
@Table(name = "images")
public class Image extends Model{
@Column(name = "release", onDelete = Column.ForeignKeyAction.CASCADE)
public Release release;
@Column(name = "idx")
public int idx;
@Column(name = "type")
public String type;
@Column(name = "width")
public int width;
@Column(name = "height")
public int height;
@Column(name = "uri")
public String uri;
@Column(name = "uri150")
public String uri150;
public Image() {
super();
}
| public Image(DiscogsRelease.Image image, Release release) { |
jvanhie/discogsscrobbler | app/src/main/java/com/github/jvanhie/discogsscrobbler/util/Lastfm.java | // Path: app/src/main/java/com/github/jvanhie/discogsscrobbler/models/Track.java
// @Table(name = "tracks")
// public class Track extends Model implements Parcelable{
//
// @Column(name = "release", onDelete = Column.ForeignKeyAction.CASCADE)
// public Release release;
//
// @Column(name = "idx")
// public int idx;
//
// @Column(name = "position")
// public String position;
//
// @Column(name = "type")
// public String type;
//
// @Column(name = "artist")
// public String artist;
//
// @Column(name = "album")
// public String album;
//
// @Column(name = "title")
// public String title;
//
// @Column(name = "duration")
// public String duration;
//
// public Track() {
// super();
// }
//
// public Track(Parcel in) {
// readFromParcel(in);
// }
//
// public Track(DiscogsRelease.Track track, Release release) {
// duration = track.duration;
// position = track.position;
// title = track.title;
// type = track.type_;
// artist = Discogs.formatArtist(track.artists);
// //if the track info does not have an artist set, fetch it from the release
// if(artist.equals("")) artist = release.artist;
// album = release.title;
// this.release = release;
// }
//
// /*parcelable implementation*/
// @Override
// public int describeContents() {
// return 0;
// }
//
// @Override
// public void writeToParcel(Parcel parcel, int i) {
// parcel.writeInt(idx);
// parcel.writeString(position);
// parcel.writeString(type);
// parcel.writeString(artist);
// parcel.writeString(album);
// parcel.writeString(title);
// parcel.writeString(duration);
// }
//
// private void readFromParcel(Parcel in) {
// idx = in.readInt();
// position = in.readString();
// type = in.readString();
// artist = in.readString();
// album = in.readString();
// title = in.readString();
// duration = in.readString();
// }
//
// public static final Parcelable.Creator CREATOR = new Creator() {
// @Override
// public Track createFromParcel(Parcel parcel) {
// return new Track(parcel);
// }
//
// @Override
// public Track[] newArray(int i) {
// return new Track[i];
// }
// };
//
// /*static formatting functions*/
// public static int formatDurationToSeconds(String duration) {
// int defaultDuration = 0;
// if(duration != null && !duration.equals("") && duration.contains(":")) {
// try {
// String[] tokens = duration.split(":");
// int minutes = Integer.parseInt(tokens[0]);
// int seconds = Integer.parseInt(tokens[1]);
// return (60 * minutes + seconds);
// } catch (NumberFormatException e) {
// }
// }
// return defaultDuration;
// }
//
// public static String formatDurationToString(int duration) {
// String format = null;
// if(duration > 0) {
// //discogs uses a fixed string representation of duration: mm:ss
// int minutes = (int) Math.floor((double)duration/60.0);
// int seconds = duration%60;
// String secondsPre = seconds <10? "0" : "";
// format = minutes+":"+secondsPre+seconds;
// }
// return format;
// }
// }
| import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.github.jvanhie.discogsscrobbler.R;
import com.github.jvanhie.discogsscrobbler.models.Track;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import de.umass.lastfm.Authenticator;
import de.umass.lastfm.CallException;
import de.umass.lastfm.Caller;
import de.umass.lastfm.Session;
import de.umass.lastfm.scrobble.ScrobbleData;
import de.umass.lastfm.scrobble.ScrobbleResult; | mContext = context;
Resources res = context.getResources();
API_KEY = res.getString(R.string.lastfm_api_key);
API_SECRET = res.getString(R.string.lastfm_api_secret);
mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
mAccessKey = mPrefs.getString("lastfm_access_key", null);
mUserName = mPrefs.getString("lastfm_user_name", null);
//if username and key not null -> recreate the lastfm session
if(mAccessKey != null) {
mSession = Session.createSession(API_KEY, API_SECRET, mAccessKey);
}
String ua = res.getString(R.string.user_agent);
mLastfm = Caller.getInstance();
mLastfm.setUserAgent(ua);
mLastfm.setCache(null);
mLastfm.setDebugMode(true);
}
public boolean isLoggedIn() {
return (mSession != null);
}
public String getUserName() {
return mUserName;
}
| // Path: app/src/main/java/com/github/jvanhie/discogsscrobbler/models/Track.java
// @Table(name = "tracks")
// public class Track extends Model implements Parcelable{
//
// @Column(name = "release", onDelete = Column.ForeignKeyAction.CASCADE)
// public Release release;
//
// @Column(name = "idx")
// public int idx;
//
// @Column(name = "position")
// public String position;
//
// @Column(name = "type")
// public String type;
//
// @Column(name = "artist")
// public String artist;
//
// @Column(name = "album")
// public String album;
//
// @Column(name = "title")
// public String title;
//
// @Column(name = "duration")
// public String duration;
//
// public Track() {
// super();
// }
//
// public Track(Parcel in) {
// readFromParcel(in);
// }
//
// public Track(DiscogsRelease.Track track, Release release) {
// duration = track.duration;
// position = track.position;
// title = track.title;
// type = track.type_;
// artist = Discogs.formatArtist(track.artists);
// //if the track info does not have an artist set, fetch it from the release
// if(artist.equals("")) artist = release.artist;
// album = release.title;
// this.release = release;
// }
//
// /*parcelable implementation*/
// @Override
// public int describeContents() {
// return 0;
// }
//
// @Override
// public void writeToParcel(Parcel parcel, int i) {
// parcel.writeInt(idx);
// parcel.writeString(position);
// parcel.writeString(type);
// parcel.writeString(artist);
// parcel.writeString(album);
// parcel.writeString(title);
// parcel.writeString(duration);
// }
//
// private void readFromParcel(Parcel in) {
// idx = in.readInt();
// position = in.readString();
// type = in.readString();
// artist = in.readString();
// album = in.readString();
// title = in.readString();
// duration = in.readString();
// }
//
// public static final Parcelable.Creator CREATOR = new Creator() {
// @Override
// public Track createFromParcel(Parcel parcel) {
// return new Track(parcel);
// }
//
// @Override
// public Track[] newArray(int i) {
// return new Track[i];
// }
// };
//
// /*static formatting functions*/
// public static int formatDurationToSeconds(String duration) {
// int defaultDuration = 0;
// if(duration != null && !duration.equals("") && duration.contains(":")) {
// try {
// String[] tokens = duration.split(":");
// int minutes = Integer.parseInt(tokens[0]);
// int seconds = Integer.parseInt(tokens[1]);
// return (60 * minutes + seconds);
// } catch (NumberFormatException e) {
// }
// }
// return defaultDuration;
// }
//
// public static String formatDurationToString(int duration) {
// String format = null;
// if(duration > 0) {
// //discogs uses a fixed string representation of duration: mm:ss
// int minutes = (int) Math.floor((double)duration/60.0);
// int seconds = duration%60;
// String secondsPre = seconds <10? "0" : "";
// format = minutes+":"+secondsPre+seconds;
// }
// return format;
// }
// }
// Path: app/src/main/java/com/github/jvanhie/discogsscrobbler/util/Lastfm.java
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.github.jvanhie.discogsscrobbler.R;
import com.github.jvanhie.discogsscrobbler.models.Track;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import de.umass.lastfm.Authenticator;
import de.umass.lastfm.CallException;
import de.umass.lastfm.Caller;
import de.umass.lastfm.Session;
import de.umass.lastfm.scrobble.ScrobbleData;
import de.umass.lastfm.scrobble.ScrobbleResult;
mContext = context;
Resources res = context.getResources();
API_KEY = res.getString(R.string.lastfm_api_key);
API_SECRET = res.getString(R.string.lastfm_api_secret);
mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
mAccessKey = mPrefs.getString("lastfm_access_key", null);
mUserName = mPrefs.getString("lastfm_user_name", null);
//if username and key not null -> recreate the lastfm session
if(mAccessKey != null) {
mSession = Session.createSession(API_KEY, API_SECRET, mAccessKey);
}
String ua = res.getString(R.string.user_agent);
mLastfm = Caller.getInstance();
mLastfm.setUserAgent(ua);
mLastfm.setCache(null);
mLastfm.setDebugMode(true);
}
public boolean isLoggedIn() {
return (mSession != null);
}
public String getUserName() {
return mUserName;
}
| public void updateNowPlaying(final Track track, final LastfmWaiter waiter) { |
mikelewis0/easyccg | src/uk/ac/ed/easyccg/syntax/Combinator.java | // Path: src/uk/ac/ed/easyccg/syntax/Category.java
// public enum Slash {
// FWD, BWD, EITHER;
// public String toString()
// {
// String result = "";
//
// switch (this)
// {
// case FWD: result = "/"; break;
// case BWD: result = "\\"; break;
// case EITHER: result = "|"; break;
//
// }
//
// return result;
// }
//
// public static Slash fromString(String text) {
// if (text != null) {
// for (Slash slash : values()) {
// if (text.equalsIgnoreCase(slash.toString()))
// {
// return slash;
// }
// }
// }
// throw new IllegalArgumentException("Invalid slash: " + text);
// }
//
// public boolean matches(Slash other)
// {
// return this == EITHER || this == other;
// }
// }
| import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import uk.ac.ed.easyccg.syntax.Category.Slash; | package uk.ac.ed.easyccg.syntax;
public abstract class Combinator
{
public enum RuleType {
FA, BA, FC, BX, GFC, GBX, CONJ, RP, LP, NOISE, UNARY, LEXICON
}
private Combinator(RuleType ruleType)
{
this.ruleType = ruleType;
}
static class RuleProduction {
public RuleProduction(RuleType ruleType, Category result, final boolean headIsLeft)
{
this.ruleType = ruleType;
this.category = result;
this.headIsLeft = headIsLeft;
}
public final RuleType ruleType;
public final Category category;
public final boolean headIsLeft;
}
public abstract boolean headIsLeft(Category left, Category right);
public final static Collection<Combinator> STANDARD_COMBINATORS = new ArrayList<Combinator>(Arrays.asList(
new ForwardApplication(),
new BackwardApplication(), | // Path: src/uk/ac/ed/easyccg/syntax/Category.java
// public enum Slash {
// FWD, BWD, EITHER;
// public String toString()
// {
// String result = "";
//
// switch (this)
// {
// case FWD: result = "/"; break;
// case BWD: result = "\\"; break;
// case EITHER: result = "|"; break;
//
// }
//
// return result;
// }
//
// public static Slash fromString(String text) {
// if (text != null) {
// for (Slash slash : values()) {
// if (text.equalsIgnoreCase(slash.toString()))
// {
// return slash;
// }
// }
// }
// throw new IllegalArgumentException("Invalid slash: " + text);
// }
//
// public boolean matches(Slash other)
// {
// return this == EITHER || this == other;
// }
// }
// Path: src/uk/ac/ed/easyccg/syntax/Combinator.java
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import uk.ac.ed.easyccg.syntax.Category.Slash;
package uk.ac.ed.easyccg.syntax;
public abstract class Combinator
{
public enum RuleType {
FA, BA, FC, BX, GFC, GBX, CONJ, RP, LP, NOISE, UNARY, LEXICON
}
private Combinator(RuleType ruleType)
{
this.ruleType = ruleType;
}
static class RuleProduction {
public RuleProduction(RuleType ruleType, Category result, final boolean headIsLeft)
{
this.ruleType = ruleType;
this.category = result;
this.headIsLeft = headIsLeft;
}
public final RuleType ruleType;
public final Category category;
public final boolean headIsLeft;
}
public abstract boolean headIsLeft(Category left, Category right);
public final static Collection<Combinator> STANDARD_COMBINATORS = new ArrayList<Combinator>(Arrays.asList(
new ForwardApplication(),
new BackwardApplication(), | new ForwardComposition(Slash.FWD, Slash.FWD, Slash.FWD), |
mikelewis0/easyccg | src/uk/ac/ed/easyccg/syntax/TagDict.java | // Path: src/uk/ac/ed/easyccg/syntax/InputReader.java
// public static class InputToParser {
// private final List<InputWord> words;
// private boolean isAlreadyTagged;
// InputToParser(List<InputWord> words, List<Category> goldCategories, List<List<SyntaxTreeNodeLeaf>> inputSupertags, boolean isAlreadyTagged)
// {
// this.words = words;
// this.goldCategories = goldCategories;
// this.inputSupertags = inputSupertags;
// this.isAlreadyTagged = isAlreadyTagged;
// }
// private final List<Category> goldCategories;
// private final List<List<SyntaxTreeNodeLeaf>> inputSupertags;
// public int length()
// {
// return words.size();
// }
//
// /**
// * If true, the Parser should not supertag the data itself, and use getInputSupertags() instead.
// */
// public boolean isAlreadyTagged()
// {
// return isAlreadyTagged;
// }
// public List<List<SyntaxTreeNodeLeaf>> getInputSupertags()
// {
// return inputSupertags;
// }
//
// public List<SyntaxTreeNodeLeaf> getInputSupertags1best()
// {
// List<SyntaxTreeNodeLeaf> result = new ArrayList<SyntaxTreeNodeLeaf>();
// for (List<SyntaxTreeNodeLeaf> tagsForWord : inputSupertags) {
// result.add(tagsForWord.get(0));
// }
// return result;
// }
// public boolean haveGoldCategories()
// {
// return getGoldCategories() != null;
// }
//
// public List<Category> getGoldCategories()
// {
// return goldCategories;
// }
//
// public List<InputWord> getInputWords() {
// return words;
//
// }
//
// public String getWordsAsString()
// {
// StringBuilder result = new StringBuilder();
// for (InputWord word : words) {
// result.append(word.word + " ");
// }
//
// return result.toString().trim();
// }
//
// public static InputToParser fromTokens(List<String> tokens) {
// List<InputWord> inputWords = new ArrayList<InputWord>(tokens.size());
// for (String word : tokens) {
// inputWords.add(new InputWord(word, null, null));
// }
// return new InputToParser(inputWords, null, null, false);
// }
//
// }
| import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import uk.ac.ed.easyccg.syntax.InputReader.InputToParser;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multiset;
import com.google.common.collect.Multiset.Entry; | * Loads a tag dictionary from the model folder
*/
public static Map<String, Collection<Category>> readDict(File modelFolder) throws IOException {
Map<String, Collection<Category>> result = new HashMap<String, Collection<Category>>();
File file = new File(modelFolder, fileName);
if (!file.exists()) return null;
for (String line : Util.readFile(file)) {
String[] fields = line.split("\t");
List<Category> cats = new ArrayList<Category>();
for (int i=1; i<fields.length; i++) {
cats.add(Category.valueOf(fields[i]));
}
result.put(fields[0], ImmutableSet.copyOf(cats));
}
return ImmutableMap.copyOf(result);
}
private final static Comparator<Entry<Category>> comparator = new Comparator<Entry<Category>>()
{
@Override
public int compare(Entry<Category> arg0, Entry<Category> arg1)
{
return arg1.getCount() - arg0.getCount();
}
};
/**
* Finds the set of categories used for each word in a corpus
*/ | // Path: src/uk/ac/ed/easyccg/syntax/InputReader.java
// public static class InputToParser {
// private final List<InputWord> words;
// private boolean isAlreadyTagged;
// InputToParser(List<InputWord> words, List<Category> goldCategories, List<List<SyntaxTreeNodeLeaf>> inputSupertags, boolean isAlreadyTagged)
// {
// this.words = words;
// this.goldCategories = goldCategories;
// this.inputSupertags = inputSupertags;
// this.isAlreadyTagged = isAlreadyTagged;
// }
// private final List<Category> goldCategories;
// private final List<List<SyntaxTreeNodeLeaf>> inputSupertags;
// public int length()
// {
// return words.size();
// }
//
// /**
// * If true, the Parser should not supertag the data itself, and use getInputSupertags() instead.
// */
// public boolean isAlreadyTagged()
// {
// return isAlreadyTagged;
// }
// public List<List<SyntaxTreeNodeLeaf>> getInputSupertags()
// {
// return inputSupertags;
// }
//
// public List<SyntaxTreeNodeLeaf> getInputSupertags1best()
// {
// List<SyntaxTreeNodeLeaf> result = new ArrayList<SyntaxTreeNodeLeaf>();
// for (List<SyntaxTreeNodeLeaf> tagsForWord : inputSupertags) {
// result.add(tagsForWord.get(0));
// }
// return result;
// }
// public boolean haveGoldCategories()
// {
// return getGoldCategories() != null;
// }
//
// public List<Category> getGoldCategories()
// {
// return goldCategories;
// }
//
// public List<InputWord> getInputWords() {
// return words;
//
// }
//
// public String getWordsAsString()
// {
// StringBuilder result = new StringBuilder();
// for (InputWord word : words) {
// result.append(word.word + " ");
// }
//
// return result.toString().trim();
// }
//
// public static InputToParser fromTokens(List<String> tokens) {
// List<InputWord> inputWords = new ArrayList<InputWord>(tokens.size());
// for (String word : tokens) {
// inputWords.add(new InputWord(word, null, null));
// }
// return new InputToParser(inputWords, null, null, false);
// }
//
// }
// Path: src/uk/ac/ed/easyccg/syntax/TagDict.java
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import uk.ac.ed.easyccg.syntax.InputReader.InputToParser;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multiset;
import com.google.common.collect.Multiset.Entry;
* Loads a tag dictionary from the model folder
*/
public static Map<String, Collection<Category>> readDict(File modelFolder) throws IOException {
Map<String, Collection<Category>> result = new HashMap<String, Collection<Category>>();
File file = new File(modelFolder, fileName);
if (!file.exists()) return null;
for (String line : Util.readFile(file)) {
String[] fields = line.split("\t");
List<Category> cats = new ArrayList<Category>();
for (int i=1; i<fields.length; i++) {
cats.add(Category.valueOf(fields[i]));
}
result.put(fields[0], ImmutableSet.copyOf(cats));
}
return ImmutableMap.copyOf(result);
}
private final static Comparator<Entry<Category>> comparator = new Comparator<Entry<Category>>()
{
@Override
public int compare(Entry<Category> arg0, Entry<Category> arg1)
{
return arg1.getCount() - arg0.getCount();
}
};
/**
* Finds the set of categories used for each word in a corpus
*/ | public static Map<String, Collection<Category>> makeDict(Iterable<InputToParser> input) { |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.