You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by al...@apache.org on 2017/11/27 19:49:17 UTC
[camel] branch master updated: CAMEL-11869: Upgrade mockito-core to
version 2.11.0 for camel-spring-ldap
This is an automated email from the ASF dual-hosted git repository.
aldettinger pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 1f147c6 CAMEL-11869: Upgrade mockito-core to version 2.11.0 for camel-spring-ldap
1f147c6 is described below
commit 1f147c68ed4d15f72112f823891a94453e8c7a06
Author: aldettinger <al...@gmail.com>
AuthorDate: Mon Nov 27 20:48:07 2017 +0100
CAMEL-11869: Upgrade mockito-core to version 2.11.0 for camel-spring-ldap
---
components/camel-spring-ldap/pom.xml | 1 +
.../springldap/SpringLdapComponentTest.java | 73 +++++++++++-----------
.../springldap/SpringLdapProducerTest.java | 51 ++++++++-------
3 files changed, 65 insertions(+), 60 deletions(-)
diff --git a/components/camel-spring-ldap/pom.xml b/components/camel-spring-ldap/pom.xml
index b4955f2..1ea986f 100644
--- a/components/camel-spring-ldap/pom.xml
+++ b/components/camel-spring-ldap/pom.xml
@@ -93,6 +93,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
+ <version>${mockito2-version}</version>
<scope>test</scope>
</dependency>
diff --git a/components/camel-spring-ldap/src/test/java/org/apache/camel/component/springldap/SpringLdapComponentTest.java b/components/camel-spring-ldap/src/test/java/org/apache/camel/component/springldap/SpringLdapComponentTest.java
index c8b9334..1878f0a 100644
--- a/components/camel-spring-ldap/src/test/java/org/apache/camel/component/springldap/SpringLdapComponentTest.java
+++ b/components/camel-spring-ldap/src/test/java/org/apache/camel/component/springldap/SpringLdapComponentTest.java
@@ -29,22 +29,45 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
-import org.mockito.Mockito;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Captor;
+import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.ldap.core.AttributesMapper;
import org.springframework.ldap.core.LdapTemplate;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+@RunWith(MockitoJUnitRunner.class)
public class SpringLdapComponentTest extends CamelSpringTestSupport {
private LdapTemplate ldapTemplate;
private ProducerTemplate producer;
private Map<String, Object> body;
+ @Captor
+ private ArgumentCaptor<String> dnCaptor;
+
+ @Captor
+ private ArgumentCaptor<Attributes> attributesCaptor;
+
+ @Captor
+ private ArgumentCaptor<Object> objectToBindCaptor;
+
+ @Captor
+ private ArgumentCaptor<String> filterCaptor;
+
+ @Captor
+ private ArgumentCaptor<Integer> scopeCaptor;
+
+ @Captor
+ private ArgumentCaptor<AttributesMapper<String>> mapperCaptor;
+
@Test
public void testUnbind() throws Exception {
String dnToUnbind = "some dn to unbind";
@@ -54,8 +77,7 @@ public class SpringLdapComponentTest extends CamelSpringTestSupport {
+ SpringLdapTestConfiguration.LDAP_MOCK_NAME
+ "?operation=unbind", body);
- ArgumentCaptor<String> dnCaptor = ArgumentCaptor.forClass(String.class);
- Mockito.verify(ldapTemplate).unbind(dnCaptor.capture());
+ verify(ldapTemplate).unbind(dnCaptor.capture());
assertEquals(dnToUnbind, dnCaptor.getValue());
}
@@ -73,14 +95,7 @@ public class SpringLdapComponentTest extends CamelSpringTestSupport {
+ SpringLdapTestConfiguration.LDAP_MOCK_NAME
+ "?operation=bind", body);
- ArgumentCaptor<String> dnCaptor = ArgumentCaptor.forClass(String.class);
- ArgumentCaptor<Attributes> attributesCaptor = ArgumentCaptor
- .forClass(Attributes.class);
- ArgumentCaptor<Object> objectToBindCaptor = ArgumentCaptor
- .forClass(Object.class);
-
- Mockito.verify(ldapTemplate).bind(dnCaptor.capture(),
- objectToBindCaptor.capture(), attributesCaptor.capture());
+ verify(ldapTemplate).bind(dnCaptor.capture(), objectToBindCaptor.capture(), attributesCaptor.capture());
assertEquals(dnToBind, dnCaptor.getValue());
assertNull(objectToBindCaptor.getValue());
assertEquals(attributes, attributesCaptor.getValue());
@@ -95,34 +110,17 @@ public class SpringLdapComponentTest extends CamelSpringTestSupport {
body.put(SpringLdapProducer.FILTER, filter);
- ArgumentCaptor<String> dnCaptor = ArgumentCaptor.forClass(String.class);
- ArgumentCaptor<String> filterCaptor = ArgumentCaptor
- .forClass(String.class);
- ArgumentCaptor<Integer> scopeCaptor = ArgumentCaptor
- .forClass(Integer.class);
- ArgumentCaptor<AttributesMapper> mapperCaptor = ArgumentCaptor
- .forClass(AttributesMapper.class);
-
- List<String> searchResult = Collections
- .singletonList("some search result");
- when(
- ldapTemplate.search(any(String.class), any(String.class),
- any(Integer.class), any(AttributesMapper.class)))
- .thenReturn(searchResult);
-
- MockEndpoint resultEndpoint = (MockEndpoint) context
- .getEndpoint("mock:result");
- resultEndpoint.expectedBodiesReceived(Collections
- .singletonList(searchResult));
+ List<String> searchResult = Collections.singletonList("some search result");
+ when(ldapTemplate.search(any(String.class), any(String.class), any(Integer.class), ArgumentMatchers.<AttributesMapper<String>> any())).thenReturn(searchResult);
+
+ MockEndpoint resultEndpoint = (MockEndpoint)context.getEndpoint("mock:result");
+ resultEndpoint.expectedBodiesReceived(Collections.singletonList(searchResult));
producer.sendBody("direct:start", body);
- Mockito.verify(ldapTemplate).search(dnCaptor.capture(),
- filterCaptor.capture(), scopeCaptor.capture(),
- mapperCaptor.capture());
+ verify(ldapTemplate).search(dnCaptor.capture(), filterCaptor.capture(), scopeCaptor.capture(), mapperCaptor.capture());
assertEquals(dnToSearch, dnCaptor.getValue());
- assertEquals((Integer) SearchControls.ONELEVEL_SCOPE,
- scopeCaptor.getValue());
+ assertEquals((Integer)SearchControls.ONELEVEL_SCOPE, scopeCaptor.getValue());
assertEquals(filter, filterCaptor.getValue());
resultEndpoint.assertIsSatisfied();
@@ -151,8 +149,7 @@ public class SpringLdapComponentTest extends CamelSpringTestSupport {
}
private void initializeTest(String dn) {
- ldapTemplate = context.getRegistry().lookupByNameAndType(
- SpringLdapTestConfiguration.LDAP_MOCK_NAME, LdapTemplate.class);
+ ldapTemplate = context.getRegistry().lookupByNameAndType(SpringLdapTestConfiguration.LDAP_MOCK_NAME, LdapTemplate.class);
producer = context.createProducerTemplate();
diff --git a/components/camel-spring-ldap/src/test/java/org/apache/camel/component/springldap/SpringLdapProducerTest.java b/components/camel-spring-ldap/src/test/java/org/apache/camel/component/springldap/SpringLdapProducerTest.java
index 031c7f9..194e97c 100644
--- a/components/camel-spring-ldap/src/test/java/org/apache/camel/component/springldap/SpringLdapProducerTest.java
+++ b/components/camel-spring-ldap/src/test/java/org/apache/camel/component/springldap/SpringLdapProducerTest.java
@@ -33,30 +33,37 @@ import org.apache.camel.impl.DefaultMessage;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.Matchers;
-import org.mockito.Mockito;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.ldap.core.AttributesMapper;
import org.springframework.ldap.core.LdapOperations;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.query.LdapQuery;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Matchers.isNull;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.isNull;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+@RunWith(MockitoJUnitRunner.class)
public class SpringLdapProducerTest extends CamelTestSupport {
- private SpringLdapEndpoint ldapEndpoint = Mockito.mock(SpringLdapEndpoint.class);
- private LdapTemplate ldapTemplate = Mockito.mock(LdapTemplate.class);
+ @Mock
+ private SpringLdapEndpoint ldapEndpoint;
- private SpringLdapProducer ldapProducer = new SpringLdapProducer(ldapEndpoint);
+ @Mock
+ private LdapTemplate ldapTemplate;
+
+ private SpringLdapProducer ldapProducer;
@Before
public void setUp() throws Exception {
super.setUp();
when(ldapEndpoint.getLdapTemplate()).thenReturn(ldapTemplate);
+ ldapProducer = new SpringLdapProducer(ldapEndpoint);
}
@Test(expected = UnsupportedOperationException.class)
@@ -80,7 +87,7 @@ public class SpringLdapProducerTest extends CamelTestSupport {
Exchange exchange = new DefaultExchange(context);
Message in = new DefaultMessage(context);
- Map<String, Object> body = new HashMap<String, Object>();
+ Map<String, Object> body = new HashMap<>();
processBody(exchange, in, body);
}
@@ -90,8 +97,8 @@ public class SpringLdapProducerTest extends CamelTestSupport {
Exchange exchange = new DefaultExchange(context);
Message in = new DefaultMessage(context);
- Map<String, Object> body = new HashMap<String, Object>();
- body.put(SpringLdapProducer.FUNCTION, Mockito.mock(BiFunction.class));
+ Map<String, Object> body = new HashMap<>();
+ body.put(SpringLdapProducer.FUNCTION, mock(BiFunction.class));
when(ldapEndpoint.getOperation()).thenReturn(LdapOperation.FUNCTION_DRIVEN);
@@ -109,7 +116,7 @@ public class SpringLdapProducerTest extends CamelTestSupport {
Exchange exchange = new DefaultExchange(context);
Message in = new DefaultMessage(context);
- Map<String, Object> body = new HashMap<String, Object>();
+ Map<String, Object> body = new HashMap<>();
body.put(SpringLdapProducer.DN, "");
processBody(exchange, in, body);
@@ -120,7 +127,7 @@ public class SpringLdapProducerTest extends CamelTestSupport {
Exchange exchange = new DefaultExchange(context);
Message in = new DefaultMessage(context);
- Map<String, Object> body = new HashMap<String, Object>();
+ Map<String, Object> body = new HashMap<>();
body.put(SpringLdapProducer.DN, null);
processBody(exchange, in, body);
@@ -131,7 +138,7 @@ public class SpringLdapProducerTest extends CamelTestSupport {
Exchange exchange = new DefaultExchange(context);
Message in = new DefaultMessage(context);
- Map<String, Object> body = new HashMap<String, Object>();
+ Map<String, Object> body = new HashMap<>();
body.put(SpringLdapProducer.DN, " ");
processBody(exchange, in, body);
@@ -146,7 +153,7 @@ public class SpringLdapProducerTest extends CamelTestSupport {
Exchange exchange = new DefaultExchange(context);
Message in = new DefaultMessage(context);
- Map<String, Object> body = new HashMap<String, Object>();
+ Map<String, Object> body = new HashMap<>();
body.put(SpringLdapProducer.DN, dn);
body.put(SpringLdapProducer.FILTER, filter);
@@ -154,7 +161,7 @@ public class SpringLdapProducerTest extends CamelTestSupport {
when(ldapEndpoint.scopeValue()).thenReturn(scope);
processBody(exchange, in, body);
- verify(ldapTemplate).search(eq(dn), eq(filter), eq(scope), any(AttributesMapper.class));
+ verify(ldapTemplate).search(eq(dn), eq(filter), eq(scope), ArgumentMatchers.<AttributesMapper<String>>any());
}
@Test
@@ -165,7 +172,7 @@ public class SpringLdapProducerTest extends CamelTestSupport {
Exchange exchange = new DefaultExchange(context);
Message in = new DefaultMessage(context);
- Map<String, Object> body = new HashMap<String, Object>();
+ Map<String, Object> body = new HashMap<>();
body.put(SpringLdapProducer.DN, dn);
body.put(SpringLdapProducer.ATTRIBUTES, attributes);
@@ -182,7 +189,7 @@ public class SpringLdapProducerTest extends CamelTestSupport {
Exchange exchange = new DefaultExchange(context);
Message in = new DefaultMessage(context);
- Map<String, Object> body = new HashMap<String, Object>();
+ Map<String, Object> body = new HashMap<>();
body.put(SpringLdapProducer.DN, dn);
when(ldapEndpoint.getOperation()).thenReturn(LdapOperation.UNBIND);
@@ -200,7 +207,7 @@ public class SpringLdapProducerTest extends CamelTestSupport {
Exchange exchange = new DefaultExchange(context);
Message in = new DefaultMessage(context);
- Map<String, Object> body = new HashMap<String, Object>();
+ Map<String, Object> body = new HashMap<>();
body.put(SpringLdapProducer.DN, dn);
body.put(SpringLdapProducer.FILTER, filter);
body.put(SpringLdapProducer.PASSWORD, password);
@@ -208,7 +215,7 @@ public class SpringLdapProducerTest extends CamelTestSupport {
when(ldapEndpoint.getOperation()).thenReturn(LdapOperation.AUTHENTICATE);
processBody(exchange, in, body);
- verify(ldapTemplate).authenticate(Matchers.any(LdapQuery.class), eq(password));
+ verify(ldapTemplate).authenticate(ArgumentMatchers.any(LdapQuery.class), eq(password));
}
@Test
@@ -219,7 +226,7 @@ public class SpringLdapProducerTest extends CamelTestSupport {
Exchange exchange = new DefaultExchange(context);
Message in = new DefaultMessage(context);
- Map<String, Object> body = new HashMap<String, Object>();
+ Map<String, Object> body = new HashMap<>();
body.put(SpringLdapProducer.DN, dn);
body.put(SpringLdapProducer.MODIFICATION_ITEMS, modificationItems);
@@ -236,7 +243,7 @@ public class SpringLdapProducerTest extends CamelTestSupport {
Exchange exchange = new DefaultExchange(context);
Message in = new DefaultMessage(context);
- Map<String, Object> body = new HashMap<String, Object>();
+ Map<String, Object> body = new HashMap<>();
body.put(SpringLdapProducer.DN, dn);
body.put(SpringLdapProducer.REQUEST, dn);
body.put(SpringLdapProducer.FUNCTION, (BiFunction<LdapOperations, String, Void>)(l, q) -> {
--
To stop receiving notification emails like this one, please contact
['"commits@camel.apache.org" <co...@camel.apache.org>'].