Java Code Examples for com.google.common.collect.FluentIterable#size()

The following examples show how to use com.google.common.collect.FluentIterable#size() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SubsystemTestCase.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: SubsystemTestCase.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: SubsystemTestCase.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
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());
     }
}
 
Example 4
Source File: SubsystemTestCase.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
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());
     }
}
 
Example 5
Source File: TestInfoRepository.java    From android-test with Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example 6
Source File: StepInvoker.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
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();
	}