org.easymock.IArgumentMatcher Java Examples

The following examples show how to use org.easymock.IArgumentMatcher. 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: KafkaTopicClientImplTest.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 6 votes vote down vote up
private static Collection<NewTopic> singleNewTopic(final NewTopic expected) {
  class NewTopicsMatcher implements IArgumentMatcher {
    @SuppressWarnings("unchecked")
    @Override
    public boolean matches(final Object argument) {
      final Collection<NewTopic> newTopics = (Collection<NewTopic>) argument;
      if (newTopics.size() != 1) {
        return false;
      }

      final NewTopic actual = newTopics.iterator().next();
      return Objects.equals(actual.name(), expected.name())
             && Objects.equals(actual.replicationFactor(), expected.replicationFactor())
             && Objects.equals(actual.numPartitions(), expected.numPartitions())
             && Objects.equals(actual.configs(), expected.configs());
    }

    @Override
    public void appendTo(final StringBuffer buffer) {
      buffer.append("{NewTopic").append(expected).append("}");
    }
  }

  EasyMock.reportMatcher(new NewTopicsMatcher());
  return null;
}
 
Example #2
Source File: FileTrackExporterTest.java    From mytracks with Apache License 2.0 6 votes vote down vote up
/**
 * Waypoint equals.
 * 
 * @param waypoint the waypoint
 */
private Waypoint waypointEq(final Waypoint waypoint) {
  EasyMock.reportMatcher(new IArgumentMatcher() {
      @Override
    public boolean matches(Object object) {
      if (object == null || waypoint == null) {
        return waypoint == object;
      }
      Waypoint waypoint2 = (Waypoint) object;

      return waypoint.getId() == waypoint2.getId();
    }

      @Override
    public void appendTo(StringBuffer buffer) {
      buffer.append("waypointEq(");
      buffer.append(waypoint);
      buffer.append(")");
    }
  });
  return null;
}
 
Example #3
Source File: FileTrackExporterTest.java    From mytracks with Apache License 2.0 6 votes vote down vote up
/**
 * Track equals.
 * 
 * @param track1 the track
 */
private Track trackEq(final Track track1) {
  EasyMock.reportMatcher(new IArgumentMatcher() {
      @Override
    public boolean matches(Object object) {
      if (object == null || track1 == null) {
        return track1 == object;
      }
      Track track2 = (Track) object;

      return track1.getName().equals(track2.getName());
    }

      @Override
    public void appendTo(StringBuffer buffer) {
      buffer.append("trackEq(");
      buffer.append(track1);
      buffer.append(")");
    }
  });
  return null;
}
 
Example #4
Source File: KafkaTopicClientImplTest.java    From ksql-fork-with-deep-learning-function with Apache License 2.0 5 votes vote down vote up
private static Map<ConfigResource, Config> withResourceConfig(final ConfigResource resource,
                                                              final ConfigEntry... entries) {
  final Set<ConfigEntry> expected = Arrays.stream(entries)
      .collect(Collectors.toSet());

  class ConfigMatcher implements IArgumentMatcher {
    @SuppressWarnings("unchecked")
    @Override
    public boolean matches(final Object argument) {
      final Map<ConfigResource, Config> request = (Map<ConfigResource, Config>)argument;
      if (request.size() != 1) {
        return false;
      }

      final Config config = request.get(resource);
      if (config == null) {
        return false;
      }

      final Set<ConfigEntry> actual = new HashSet<>(config.entries());
      return actual.equals(expected);
    }

    @Override
    public void appendTo(final StringBuffer buffer) {
      buffer.append(resource).append("->")
          .append("Config{").append(expected).append("}");
    }
  }
  EasyMock.reportMatcher(new ConfigMatcher());
  return null;
}
 
Example #5
Source File: FileTrackExporterTest.java    From mytracks with Apache License 2.0 5 votes vote down vote up
/**
 * Location equals.
 *  
 * @param location the location
 */
private Location locationEq(final Location location) {
  EasyMock.reportMatcher(new IArgumentMatcher() {
      @Override
    public boolean matches(Object object) {
      if (object == null || location == null) {
        return location == object;
      }
      Location location2 = (Location) object;

      return location.hasAccuracy() == location2.hasAccuracy()
          && (!location.hasAccuracy() || location.getAccuracy() == location2.getAccuracy())
          && location.hasAltitude() == location2.hasAltitude()
          && (!location.hasAltitude() || location.getAltitude() == location2.getAltitude())
          && location.hasBearing() == location2.hasBearing()
          && (!location.hasBearing() || location.getBearing() == location2.getBearing())
          && location.hasSpeed() == location2.hasSpeed()
          && (!location.hasSpeed() || location.getSpeed() == location2.getSpeed())
          && location.getLatitude() == location2.getLatitude()
          && location.getLongitude() == location2.getLongitude()
          && location.getTime() == location2.getTime();
    }

      @Override
    public void appendTo(StringBuffer buffer) {
      buffer.append("locationEq(");
      buffer.append(location);
      buffer.append(")");
    }
  });
  return null;
}
 
Example #6
Source File: ServerInstanceContextTest.java    From chassis with Apache License 2.0 5 votes vote down vote up
private static com.amazonaws.regions.Region eqRegion(final com.amazonaws.regions.Region region) {
    EasyMock.reportMatcher(new IArgumentMatcher() {
        @Override
        public boolean matches(Object o) {
            com.amazonaws.regions.Region givenRegion = (com.amazonaws.regions.Region) o;
            return givenRegion.getName().equals(region.getName());
        }

        @Override
        public void appendTo(StringBuffer stringBuffer) {
            stringBuffer.append("eqReqion for ").append(region.getName());
        }
    });
    return region;
}
 
Example #7
Source File: ArgumentMatchersUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
public static String minCharCount(int value){
    EasyMock.reportMatcher(new IArgumentMatcher() {
        @Override
        public boolean matches(Object argument) {
            return argument instanceof String 
              && ((String) argument).length() >= value;
        }
 
        @Override
        public void appendTo(StringBuffer buffer) {
            buffer.append("charCount(\"" + value + "\")");
        }
    });    
    return null;
}
 
Example #8
Source File: LocationsMatcher.java    From mytracks with Apache License 2.0 4 votes vote down vote up
public static Location[] eqLoc(Location[] expected) {
  IArgumentMatcher matcher = new LocationsMatcher(expected);
  AndroidMock.reportMatcher(matcher);
  return null;
}