Search in sources :

Example 1 with IArgumentMatcher

use of org.easymock.IArgumentMatcher in project easymock by easymock.

the class LastControl method reportNot.

public static void reportNot() {
    List<IArgumentMatcher> stack = threadToArgumentMatcherStack.get();
    assertState(stack != null, NO_MATCHERS_FOUND);
    stack.add(new Not(popLastArgumentMatchers(1).get(0)));
}
Also used : Not(org.easymock.internal.matchers.Not) IArgumentMatcher(org.easymock.IArgumentMatcher)

Example 2 with IArgumentMatcher

use of org.easymock.IArgumentMatcher in project felix by apache.

the class ConfigInstallerTest method testSetConfiguration.

public void testSetConfiguration() throws Exception {
    EasyMock.expect(mockBundleContext.getProperty(DirectoryWatcher.CONFIG_ENCODING)).andReturn(null);
    EasyMock.expect(mockBundleContext.getProperty(DirectoryWatcher.LOG_DEFAULT)).andReturn(null);
    EasyMock.expect(mockBundleContext.getProperty(DirectoryWatcher.LOG_LEVEL)).andReturn(null);
    EasyMock.expect(mockConfiguration.getProperties()).andReturn(new Hashtable<String, Object>());
    EasyMock.reportMatcher(new IArgumentMatcher() {

        public boolean matches(Object argument) {
            return ((Dictionary) argument).get("testkey").equals("testvalue");
        }

        public void appendTo(StringBuffer buffer) {
            buffer.append("<Dictionary check: testkey present?>");
        }
    });
    mockConfiguration.update(new Hashtable<String, Object>());
    EasyMock.expect(mockConfigurationAdmin.listConfigurations((String) EasyMock.anyObject())).andReturn(null);
    EasyMock.expect(mockConfigurationAdmin.getConfiguration("firstcfg", "?")).andReturn(mockConfiguration);
    EasyMock.replay(mockConfiguration, mockConfigurationAdmin, mockBundleContext);
    ConfigInstaller ci = new ConfigInstaller(mockBundleContext, mockConfigurationAdmin, new FileInstall());
    assertTrue(ci.setConfig(new File("src/test/resources/watched/firstcfg.cfg")));
    EasyMock.verify(mockConfiguration, mockConfigurationAdmin, mockBundleContext);
}
Also used : Dictionary(java.util.Dictionary) IArgumentMatcher(org.easymock.IArgumentMatcher) File(java.io.File)

Example 3 with IArgumentMatcher

use of org.easymock.IArgumentMatcher in project ksql by confluentinc.

the class KafkaTopicClientImplTest method withResourceConfig.

/*
   * Config has broken hashCode & equals method:
   * https://issues.apache.org/jira/browse/KAFKA-6727
   */
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;
}
Also used : ConfigEntry(org.apache.kafka.clients.admin.ConfigEntry) TopicConfig(org.apache.kafka.common.config.TopicConfig) Config(org.apache.kafka.clients.admin.Config) IArgumentMatcher(org.easymock.IArgumentMatcher) EasyMock.anyObject(org.easymock.EasyMock.anyObject) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) ConfigResource(org.apache.kafka.common.config.ConfigResource) HashSet(java.util.HashSet)

Example 4 with IArgumentMatcher

use of org.easymock.IArgumentMatcher in project ksql by confluentinc.

the class KafkaTopicClientImplTest method singleNewTopic.

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;
}
Also used : IArgumentMatcher(org.easymock.IArgumentMatcher) Collection(java.util.Collection) EasyMock.anyObject(org.easymock.EasyMock.anyObject) NewTopic(org.apache.kafka.clients.admin.NewTopic)

Example 5 with IArgumentMatcher

use of org.easymock.IArgumentMatcher in project easymock by easymock.

the class LastControl method reportOr.

public static void reportOr(int count) {
    List<IArgumentMatcher> stack = threadToArgumentMatcherStack.get();
    assertState(stack != null, NO_MATCHERS_FOUND);
    stack.add(new Or(popLastArgumentMatchers(count)));
}
Also used : Or(org.easymock.internal.matchers.Or) IArgumentMatcher(org.easymock.IArgumentMatcher)

Aggregations

IArgumentMatcher (org.easymock.IArgumentMatcher)6 EasyMock.anyObject (org.easymock.EasyMock.anyObject)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 File (java.io.File)1 Collection (java.util.Collection)1 Dictionary (java.util.Dictionary)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Config (org.apache.kafka.clients.admin.Config)1 ConfigEntry (org.apache.kafka.clients.admin.ConfigEntry)1 NewTopic (org.apache.kafka.clients.admin.NewTopic)1 ConfigResource (org.apache.kafka.common.config.ConfigResource)1 TopicConfig (org.apache.kafka.common.config.TopicConfig)1 And (org.easymock.internal.matchers.And)1 Not (org.easymock.internal.matchers.Not)1 Or (org.easymock.internal.matchers.Or)1