Java Code Examples for org.easymock.EasyMock#reportMatcher()

The following examples show how to use org.easymock.EasyMock#reportMatcher() . 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: LogUtilsTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testLogParamsSubstitutionWithThrowable() throws Exception {
    Logger log = LogUtils.getL7dLogger(LogUtilsTest.class, null,
                                       "testLogParamsSubstitutionWithThrowable");
    Handler handler = EasyMock.createNiceMock(Handler.class);
    Exception ex = new Exception();
    LogRecord record = new LogRecord(Level.SEVERE, "subbed in 4 & 3");
    record.setThrown(ex);
    EasyMock.reportMatcher(new LogRecordMatcher(record));
    handler.publish(record);
    EasyMock.replay(handler);
    synchronized (log) {
        log.addHandler(handler);
        LogUtils.log(log, Level.SEVERE, "SUB2_MSG", ex, new Object[] {3, 4});
        EasyMock.verify(handler);
        log.removeHandler(handler);
    }
}
 
Example 3
Source File: LogUtilsTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testLogParamSubstitutionWithThrowable() throws Exception {
    Logger log = LogUtils.getL7dLogger(LogUtilsTest.class, null, "testLogParamSubstitutionWithThrowable");
    Handler handler = EasyMock.createNiceMock(Handler.class);
    Exception ex = new Exception();
    LogRecord record = new LogRecord(Level.SEVERE, "subbed in 1 only");
    record.setThrown(ex);
    EasyMock.reportMatcher(new LogRecordMatcher(record));
    handler.publish(record);
    EasyMock.replay(handler);
    synchronized (log) {
        log.addHandler(handler);
        LogUtils.log(log, Level.SEVERE, "SUB1_MSG", ex, 1);
        EasyMock.verify(handler);
        log.removeHandler(handler);
    }
}
 
Example 4
Source File: LogUtilsTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testLogNoParamsWithThrowable() {
    Logger log = LogUtils.getL7dLogger(LogUtilsTest.class, null, "testLogNoParamsWithThrowable");
    Handler handler = EasyMock.createNiceMock(Handler.class);
    Exception ex = new Exception("x");
    LogRecord record = new LogRecord(Level.SEVERE, "subbed in {0} only");
    record.setThrown(ex);
    EasyMock.reportMatcher(new LogRecordMatcher(record));
    handler.publish(record);
    EasyMock.replay(handler);
    synchronized (log) {
        log.addHandler(handler);
        // handler called *after* localization of message
        LogUtils.log(log, Level.SEVERE, "SUB1_MSG", ex);
        EasyMock.verify(handler);
        log.removeHandler(handler);
    }
}
 
Example 5
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 6
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 7
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 8
Source File: LogUtilsTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testHandleL7dMessage() throws Exception {
    Logger log = LogUtils.getL7dLogger(LogUtilsTest.class, null, "testHandleL7dMessage");
    Handler handler = EasyMock.createNiceMock(Handler.class);
    log.addHandler(handler);
    // handler called *before* localization of message
    LogRecord record = new LogRecord(Level.WARNING, "FOOBAR_MSG");
    record.setResourceBundle(log.getResourceBundle());
    EasyMock.reportMatcher(new LogRecordMatcher(record));
    handler.publish(record);
    EasyMock.replay(handler);
    log.log(Level.WARNING, "FOOBAR_MSG");
    EasyMock.verify(handler);
    log.removeHandler(handler);
}
 
Example 9
Source File: LogUtilsTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testLogNoParamsOrThrowable() {
    Logger log = LogUtils.getL7dLogger(LogUtilsTest.class, null, "testLogNoParamsOrThrowable");
    Handler handler = EasyMock.createNiceMock(Handler.class);
    log.addHandler(handler);
    // handler called *after* localization of message
    LogRecord record = new LogRecord(Level.SEVERE, "subbed in {0} only");
    EasyMock.reportMatcher(new LogRecordMatcher(record));
    handler.publish(record);
    EasyMock.replay(handler);
    LogUtils.log(log, Level.SEVERE, "SUB1_MSG");
    EasyMock.verify(handler);
    log.removeHandler(handler);
}
 
Example 10
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 11
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 12
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 13
Source File: StateManagerImplTest.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
PubsubEvent matchStateChange(String task, ScheduleStatus from, ScheduleStatus to) {
  EasyMock.reportMatcher(new StateChangeMatcher(task, from, to));
  return null;
}
 
Example 14
Source File: StateManagerImplTest.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
PubsubEvent matchTasksDeleted(String id, String... ids) {
  EasyMock.reportMatcher(new DeletedTasksMatcher(id, ids));
  return null;
}
 
Example 15
Source File: LogManagerTest.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
private static byte[] entryEq(LogEntry expected) {
  EasyMock.reportMatcher(new LogEntryMatcher(expected));
  return new byte[] {};
}
 
Example 16
Source File: AnswerCallback.java    From mongodb-async-driver with Apache License 2.0 2 votes vote down vote up
/**
 * Helper for matching callbacks and triggering them at method invocation
 * time.
 *
 * @param <T>
 *            The type for the callback.
 *
 * @return <code>null</code>
 */
public static <T> ReplyCallback callback() {
    EasyMock.reportMatcher(new AnswerCallback<T>());
    return null;
}
 
Example 17
Source File: LogOpMatcher.java    From attic-aurora with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a matcher that supports value matching between a serialized {@link LogEntry} byte array
 * and a log entry object.
 *
 * @param entry Entry to match against.
 * @return {@code null}, return value included for easymock-style embedding.
 */
private static byte[] sameEntry(LogEntry entry) {
  EasyMock.reportMatcher(new LogOpMatcher(entry));
  return new byte[] {};
}
 
Example 18
Source File: AnswerCallback.java    From mongodb-async-driver with Apache License 2.0 2 votes vote down vote up
/**
 * Helper for matching callbacks and triggering them at method invocation
 * time.
 *
 * @param <T>
 *            The type for the callback.
 * @param reply
 *            The reply to give the callback when matching.
 * @return <code>null</code>
 */
public static <T> Callback<T> callback(final T reply) {
    EasyMock.reportMatcher(new AnswerCallback<T>(reply));
    return null;
}
 
Example 19
Source File: AnswerCallback.java    From mongodb-async-driver with Apache License 2.0 2 votes vote down vote up
/**
 * Helper for matching callbacks and triggering them at method invocation
 * time.
 *
 * @param <T>
 *            The type for the callback.
 * @param error
 *            The error to provide the callback.
 *
 * @return <code>null</code>
 */
public static <T> ReplyCallback callback(final Throwable error) {
    EasyMock.reportMatcher(new AnswerCallback<T>(error));
    return null;
}
 
Example 20
Source File: TestIntentServiceHelper.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Matcher method to set the expected intent to match against
 * (ignoring the intent ID for the intent).
 *
 * @param intent the expected Intent
 * @return the submitted Intent
 */
public static Intent eqExceptId(Intent intent) {
    EasyMock.reportMatcher(new IdAgnosticIntentMatcher(intent));
    return intent;
}