下面列出了com.google.common.collect.FluentIterable#size ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private boolean containsMessageWithAttrs(Capture<MessageBody> capturedMsg, final String msgType, final Map<String,Object>attrs) {
FluentIterable<MessageBody> matched = FluentIterable.from(capturedMsg.getValues()).filter(new Predicate<MessageBody>() {
public boolean apply(MessageBody message) {
if(!message.getMessageType().equals(msgType)){
return false;
}
for(Map.Entry<String,Object>attr:attrs.entrySet()){
if(attr.getValue() == NULL_VALUE) {
if( message.getAttributes().get(attr.getKey()) != null ) {
System.out.println(String.format("[%s] does not match [expected, actual]=[ %s, %s]",attr.getKey(), null, message.getAttributes().get(attr.getKey())));
return false;
}else {
continue;
}
}else if(!attr.getValue().equals(message.getAttributes().get(attr.getKey()))){
System.out.println(String.format("[%s] does not match [expected, actual]=[ %s, %s]",attr.getKey(), attr.getValue(), message.getAttributes().get(attr.getKey())));
return false;
}
}
return true;
}
});
boolean isMatched = (matched != null && matched.size() > 0);
return isMatched;
}
private boolean containsMessageWithAttrs(Capture<MessageBody> capturedMsg, final String msgType, final Map<String,Object>attrs) {
FluentIterable<MessageBody> matched = FluentIterable.from(capturedMsg.getValues()).filter(new Predicate<MessageBody>() {
public boolean apply(MessageBody message) {
if(!message.getMessageType().equals(msgType)){
return false;
}
for(Map.Entry<String,Object>attr:attrs.entrySet()){
if(attr.getValue() == NULL_VALUE) {
if( message.getAttributes().get(attr.getKey()) != null ) {
System.out.println(String.format("[%s] does not match [expected, actual]=[ %s, %s]",attr.getKey(), null, message.getAttributes().get(attr.getKey())));
return false;
}else {
continue;
}
}else if(!attr.getValue().equals(message.getAttributes().get(attr.getKey()))){
System.out.println(String.format("[%s] does not match [expected, actual]=[ %s, %s]",attr.getKey(), attr.getValue(), message.getAttributes().get(attr.getKey())));
return false;
}
}
return true;
}
});
boolean isMatched = (matched != null && matched.size() > 0);
return isMatched;
}
protected void assertContainsBroadcastEventWithAttrs(final String event, final Map<String,Object>attrs, Integer fireCount){
FluentIterable<MessageBody> matched = FluentIterable.from(broadcasts.getValues()).filter(new Predicate<MessageBody>() {
public boolean apply(MessageBody message) {
if(!message.getMessageType().equals(event)){
return false;
}
for(Map.Entry<String,Object>attr:attrs.entrySet()){
if(attr.getValue() == NULL_VALUE) {
if( message.getAttributes().get(attr.getKey()) != null ) {
System.out.println(String.format("[%s] does not match [expected, actual]=[ %s, %s]",attr.getKey(), null, message.getAttributes().get(attr.getKey())));
return false;
}else {
continue;
}
}else if(!attr.getValue().equals(message.getAttributes().get(attr.getKey()))){
System.out.println(String.format("[%s] does not match [expected, actual]=[ %s, %s]",attr.getKey(), attr.getValue(), message.getAttributes().get(attr.getKey())));
return false;
}
}
return true;
}
});
if(matched == null || matched.size() > 1){
for(MessageBody mb:broadcasts.getValues()){
System.out.println(String.format("the following messages were broadcast message %s",mb));
}
}
boolean isMatched = (matched != null && matched.size() > 0);
assertTrue(String.format("could not locate event %s with attributes %s",event,attrs),isMatched);
if(fireCount != null && fireCount.intValue() > 0 && matched != null) {
assertTrue(String.format("fire count does not match [expected, actual] =[%s, %s]",fireCount.intValue(),matched.size()), fireCount.intValue() == matched.size());
}
}
protected void assertContainsBroadcastEventWithAttrs(final String event, final Map<String,Object>attrs, Integer fireCount){
FluentIterable<MessageBody> matched = FluentIterable.from(broadcasts.getValues()).filter(new Predicate<MessageBody>() {
public boolean apply(MessageBody message) {
if(!message.getMessageType().equals(event)){
return false;
}
for(Map.Entry<String,Object>attr:attrs.entrySet()){
if(attr.getValue() == NULL_VALUE) {
if( message.getAttributes().get(attr.getKey()) != null ) {
System.out.println(String.format("[%s] does not match [expected, actual]=[ %s, %s]",attr.getKey(), null, message.getAttributes().get(attr.getKey())));
return false;
}else {
continue;
}
}else if(!attr.getValue().equals(message.getAttributes().get(attr.getKey()))){
System.out.println(String.format("[%s] does not match [expected, actual]=[ %s, %s]",attr.getKey(), attr.getValue(), message.getAttributes().get(attr.getKey())));
return false;
}
}
return true;
}
});
if(matched == null || matched.size() > 1){
for(MessageBody mb:broadcasts.getValues()){
System.out.println(String.format("the following messages were broadcast message %s",mb));
}
}
boolean isMatched = (matched != null && matched.size() > 0);
assertTrue(String.format("could not locate event %s with attributes %s",event,attrs),isMatched);
if(fireCount != null && fireCount.intValue() > 0 && matched != null) {
assertTrue(String.format("fire count does not match [expected, actual] =[%s, %s]",fireCount.intValue(),matched.size()), fireCount.intValue() == matched.size());
}
}
private List<InputStream> getDexDumpFilesFromApk(String apkPath) {
List<InputStream> dexDumpFiles = Lists.newArrayList();
try {
logger.info("Scanning: " + apkPath);
ZipFile apk = new ZipFile(new File(apkPath));
FluentIterable<ZipEntry> dexEntries = listDexFilesFrom(apk);
checkState(
dexEntries.size() > 0,
"%s: Apk is expected to have at least one dex file! APKs without dex files can be built"
+ " but cannot be installed. Often this is an interaction between the"
+ " binary_under_test attribute containing all classes that are also in the srcs"
+ " and deps attributes of the android_test target itself.",
apkPath);
// As of Apr 2015, dexdump tool extracts info only from the first dex file (classes.dex) of
// an apk. If the apk contains only one dex, running dexdump on the apk is good enough.
// Otherwise, we run dexdump on each of the dex files.
if (dexEntries.size() == 1) {
dexDumpFiles.add(runDexDump(apkPath));
} else {
for (String dex : getDexesFrom(apk, dexEntries)) {
dexDumpFiles.add(runDexDump(dex));
}
}
return dexDumpFiles;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public Method findMethod(List<Method> interceptorMethods, Class<? extends Annotation> step, Class<?> interceptorClass) {
FluentIterable<Method> possibleMethods = FluentIterable.from(interceptorMethods).filter(hasStepAnnotation(step));
if (possibleMethods.size() > 1 && possibleMethods.allMatch(not(notSameClass(interceptorClass)))) {
throw new IllegalStateException(String.format("%s - You should not have more than one @%s annotated method",
interceptorClass.getCanonicalName(), step.getSimpleName()));
}
return possibleMethods.first().orNull();
}