Updated Branches: refs/heads/master 3210a8d16 -> 67aa3b3a9
CAMEL-6826: Use Mock Objects Instead of Live HazelcastInstances to Speed Up Testing Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/67aa3b3a Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/67aa3b3a Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/67aa3b3a Branch: refs/heads/master Commit: 67aa3b3a9ebcd4044664ae64845f18821fc1d9a0 Parents: 3210a8d Author: James W. Carman <jcar...@apache.org> Authored: Tue Oct 8 13:44:59 2013 -0400 Committer: James W. Carman <jcar...@apache.org> Committed: Tue Oct 8 16:35:32 2013 -0400 ---------------------------------------------------------------------- components/camel-hazelcast/pom.xml | 5 + .../HazelcastAtomicnumberProducerTest.java | 47 +++++--- .../hazelcast/HazelcastCamelTestSupport.java | 57 ++++++++++ .../hazelcast/HazelcastListProducerTest.java | 82 +++++--------- .../hazelcast/HazelcastMapProducerTest.java | 69 ++++++------ .../HazelcastMultimapProducerTest.java | 54 ++++------ .../hazelcast/HazelcastQueueProducerTest.java | 107 +++++++------------ 7 files changed, 214 insertions(+), 207 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/67aa3b3a/components/camel-hazelcast/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-hazelcast/pom.xml b/components/camel-hazelcast/pom.xml index 0b8a878..fb4cbf3 100644 --- a/components/camel-hazelcast/pom.xml +++ b/components/camel-hazelcast/pom.xml @@ -63,6 +63,11 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-test-spring</artifactId> <scope>test</scope> http://git-wip-us.apache.org/repos/asf/camel/blob/67aa3b3a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastAtomicnumberProducerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastAtomicnumberProducerTest.java b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastAtomicnumberProducerTest.java index 158a112..84eb211 100644 --- a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastAtomicnumberProducerTest.java +++ b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastAtomicnumberProducerTest.java @@ -16,51 +16,68 @@ */ package org.apache.camel.component.hazelcast; +import com.hazelcast.core.HazelcastInstance; +import com.hazelcast.core.IAtomicLong; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.After; import org.junit.Test; +import org.mockito.Mock; +import static org.mockito.Mockito.*; -public class HazelcastAtomicnumberProducerTest extends CamelTestSupport { +public class HazelcastAtomicnumberProducerTest extends HazelcastCamelTestSupport { + + @Mock + private IAtomicLong atomicNumber; + + @Override + protected void trainHazelcastInstance(HazelcastInstance hazelcastInstance) { + when(hazelcastInstance.getAtomicLong("foo")).thenReturn(atomicNumber); + } + + @Override + protected void verifyHazelcastInstance(HazelcastInstance hazelcastInstance) { + verify(hazelcastInstance, atLeastOnce()).getAtomicLong("foo"); + } + + @After + public void verifyAtomicNumberMock() { + verifyNoMoreInteractions(atomicNumber); + } @Test public void testSet() { template.sendBody("direct:set", 4711); - - long body = template.requestBody("direct:get", null, Long.class); - assertEquals(4711, body); + verify(atomicNumber).set(4711); } @Test public void testGet() { - template.sendBody("direct:set", 1234); - + when(atomicNumber.get()).thenReturn(1234L); long body = template.requestBody("direct:get", null, Long.class); + verify(atomicNumber).get(); assertEquals(1234, body); } @Test public void testIncrement() { - template.sendBody("direct:set", 10); - + when(atomicNumber.incrementAndGet()).thenReturn(11L); long body = template.requestBody("direct:increment", null, Long.class); + verify(atomicNumber).incrementAndGet(); assertEquals(11, body); } @Test public void testDecrement() { - template.sendBody("direct:set", 10); - + when(atomicNumber.decrementAndGet()).thenReturn(9L); long body = template.requestBody("direct:decrement", null, Long.class); + verify(atomicNumber).decrementAndGet(); assertEquals(9, body); } @Test public void testDestroy() throws InterruptedException { - template.sendBody("direct:set", 10); template.sendBody("direct:destroy", null); - long body = template.requestBody("direct:get", null, Long.class); - // the body is destory - assertEquals(0, body); + verify(atomicNumber).destroy(); } @Override http://git-wip-us.apache.org/repos/asf/camel/blob/67aa3b3a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastCamelTestSupport.java ---------------------------------------------------------------------- diff --git a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastCamelTestSupport.java b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastCamelTestSupport.java new file mode 100644 index 0000000..fa56f5d --- /dev/null +++ b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastCamelTestSupport.java @@ -0,0 +1,57 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.hazelcast; + +import com.hazelcast.core.HazelcastInstance; +import org.apache.camel.CamelContext; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.After; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import static org.mockito.Mockito.*; +public class HazelcastCamelTestSupport extends CamelTestSupport { + + @Mock + private HazelcastInstance hazelcastInstance; + + @Override + protected CamelContext createCamelContext() throws Exception { + MockitoAnnotations.initMocks(this); + CamelContext context = super.createCamelContext(); + HazelcastComponent hazelcastComponent = new HazelcastComponent(context); + hazelcastComponent.setHazelcastInstance(hazelcastInstance); + context.addComponent("hazelcast", hazelcastComponent); + trainHazelcastInstance(hazelcastInstance); + return context; + } + + protected void trainHazelcastInstance(HazelcastInstance hazelcastInstance) { + + } + + protected void verifyHazelcastInstance(HazelcastInstance hazelcastInstance) { + + } + + @After + public final void verifyHazelcastInstanceMock() { + verifyHazelcastInstance(hazelcastInstance); + verifyNoMoreInteractions(hazelcastInstance); + } + + +} http://git-wip-us.apache.org/repos/asf/camel/blob/67aa3b3a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastListProducerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastListProducerTest.java b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastListProducerTest.java index 3d88b87..f367c11 100644 --- a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastListProducerTest.java +++ b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastListProducerTest.java @@ -16,101 +16,77 @@ */ package org.apache.camel.component.hazelcast; +import java.util.ArrayList; import java.util.List; import com.hazelcast.core.HazelcastInstance; +import com.hazelcast.core.IList; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.After; +import org.junit.Before; import org.junit.Test; +import org.mockito.Mock; -public class HazelcastListProducerTest extends CamelTestSupport { +import static org.mockito.Mockito.*; - private List<String> list; +public class HazelcastListProducerTest extends HazelcastCamelTestSupport { + + @Mock + private IList<String> list; + + @Override + protected void trainHazelcastInstance(HazelcastInstance hazelcastInstance) { + when(hazelcastInstance.<String>getList("bar")).thenReturn(list); + } @Override - protected void doPostSetup() throws Exception { - HazelcastComponent component = context().getComponent("hazelcast", HazelcastComponent.class); - HazelcastInstance hazelcastInstance = component.getHazelcastInstance(); - list = hazelcastInstance.getList("bar"); - list.clear(); + protected void verifyHazelcastInstance(HazelcastInstance hazelcastInstance) { + verify(hazelcastInstance, atLeastOnce()).getList("bar"); + } + + @After + public final void verifyListMock() { + verifyNoMoreInteractions(list); } @Test public void addValue() throws InterruptedException { template.sendBody("direct:add", "bar"); - assertTrue(list.contains("bar")); + verify(list).add("bar"); } @Test public void removeValue() throws InterruptedException { - list.add("foo1"); - list.add("foo2"); - list.add("foo3"); - - assertEquals(3, list.size()); - - // specify the value to remove template.sendBody("direct:removevalue", "foo2"); - - assertEquals(2, list.size()); - assertTrue(list.contains("foo1") && list.contains("foo3")); + verify(list).remove("foo2"); } @Test public void getValueWithIdx() { - list.add("foo1"); - list.add("foo2"); - - assertEquals(2, list.size()); - + when(list.get(1)).thenReturn("foo2"); template.sendBodyAndHeader("direct:get", "test", HazelcastConstants.OBJECT_POS, 1); - + verify(list).get(1); assertEquals("foo2", consumer.receiveBody("seda:out", 5000, String.class)); - } @Test public void setValueWithIdx() { - list.add("foo1"); - list.add("foo2"); - - assertEquals(2, list.size()); - template.sendBodyAndHeader("direct:set", "test", HazelcastConstants.OBJECT_POS, 1); - - assertEquals(2, list.size()); - assertEquals("test", list.get(1)); - + verify(list).set(1, "test"); } @Test public void removeValueWithIdx() { - list.add("foo1"); - list.add("foo2"); - - assertEquals(2, list.size()); - - // do not specify the value to delete, but the index template.sendBodyAndHeader("direct:removevalue", null, HazelcastConstants.OBJECT_POS, 1); - - assertEquals(1, list.size()); - assertEquals("foo1", list.get(0)); + verify(list).remove(1); } @Test public void removeValueWithoutIdx() { - list.add("foo1"); - list.add("foo2"); - - assertEquals(2, list.size()); - - // do not specify the index to delete, but the value template.sendBody("direct:removevalue", "foo1"); - - assertEquals(1, list.size()); - assertEquals("foo2", list.get(0)); + verify(list).remove("foo1"); } @Override http://git-wip-us.apache.org/repos/asf/camel/blob/67aa3b3a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMapProducerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMapProducerTest.java b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMapProducerTest.java index 8c5ccfe..669a38d 100644 --- a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMapProducerTest.java +++ b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMapProducerTest.java @@ -17,87 +17,82 @@ package org.apache.camel.component.hazelcast; import java.io.Serializable; +import java.util.Arrays; import java.util.Collection; import com.hazelcast.core.HazelcastInstance; import com.hazelcast.core.IMap; +import com.hazelcast.query.SqlPredicate; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.hazelcast.testutil.Dummy; -import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.After; import org.junit.Test; +import org.mockito.Mock; -public class HazelcastMapProducerTest extends CamelTestSupport implements Serializable { +import static org.mockito.Mockito.*; - private static final long serialVersionUID = 1L; +public class HazelcastMapProducerTest extends HazelcastCamelTestSupport implements Serializable { + + @Mock private IMap<Object, Object> map; @Override - protected void doPostSetup() throws Exception { - HazelcastComponent component = context().getComponent("hazelcast", HazelcastComponent.class); - HazelcastInstance hazelcastInstance = component.getHazelcastInstance(); - map = hazelcastInstance.getMap("foo"); - map.clear(); + protected void trainHazelcastInstance(HazelcastInstance hazelcastInstance) { + when(hazelcastInstance.getMap("foo")).thenReturn(map); + } + + @Override + protected void verifyHazelcastInstance(HazelcastInstance hazelcastInstance) { + verify(hazelcastInstance, atLeastOnce()).getMap("foo"); + } + + @After + public void verifyMapMock() { + verifyNoMoreInteractions(map); } @Test public void testPut() throws InterruptedException { template.sendBodyAndHeader("direct:put", "my-foo", HazelcastConstants.OBJECT_ID, "4711"); - - assertTrue(map.containsKey("4711")); - assertEquals("my-foo", map.get("4711")); + verify(map).put("4711", "my-foo"); } @Test public void testUpdate() { - template.sendBodyAndHeader("direct:put", "my-foo", HazelcastConstants.OBJECT_ID, "4711"); - - assertTrue(map.containsKey("4711")); - assertEquals("my-foo", map.get("4711")); - template.sendBodyAndHeader("direct:update", "my-fooo", HazelcastConstants.OBJECT_ID, "4711"); - assertEquals("my-fooo", map.get("4711")); + verify(map).lock("4711"); + verify(map).replace("4711", "my-fooo"); + verify(map).unlock("4711"); } @Test public void testGet() { - map.put("4711", "my-foo"); - + when(map.get("4711")).thenReturn("my-foo"); template.sendBodyAndHeader("direct:get", null, HazelcastConstants.OBJECT_ID, "4711"); String body = consumer.receiveBody("seda:out", 5000, String.class); - + verify(map).get("4711"); assertEquals("my-foo", body); } @Test public void testDelete() { - map.put(4711, "my-foo"); - assertEquals(1, map.size()); - template.sendBodyAndHeader("direct:delete", null, HazelcastConstants.OBJECT_ID, 4711); - assertEquals(0, map.size()); + verify(map).remove(4711); } @Test public void testQuery() { - map.put("1", new Dummy("alpha", 1000)); - map.put("2", new Dummy("beta", 2000)); - map.put("3", new Dummy("gamma", 3000)); + String sql = "bar > 1000"; - String q1 = "bar > 1000"; - String q2 = "foo LIKE alp%"; + when(map.values(any(SqlPredicate.class))).thenReturn(Arrays.<Object>asList(new Dummy("beta", 2000), new Dummy("gamma", 3000))); + template.sendBodyAndHeader("direct:query", null, HazelcastConstants.QUERY, sql); + verify(map).values(any(SqlPredicate.class)); - template.sendBodyAndHeader("direct:query", null, HazelcastConstants.QUERY, q1); Collection<?> b1 = consumer.receiveBody("seda:out", 5000, Collection.class); assertNotNull(b1); assertEquals(2, b1.size()); - - template.sendBodyAndHeader("direct:query", null, HazelcastConstants.QUERY, q2); - Collection<?> b2 = consumer.receiveBody("seda:out", 5000, Collection.class); - - assertNotNull(b2); - assertEquals(1, b2.size()); } @Override @@ -121,6 +116,4 @@ public class HazelcastMapProducerTest extends CamelTestSupport implements Serial } }; } - - } http://git-wip-us.apache.org/repos/asf/camel/blob/67aa3b3a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMultimapProducerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMultimapProducerTest.java b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMultimapProducerTest.java index 8a4a742..3467c4b 100644 --- a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMultimapProducerTest.java +++ b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMultimapProducerTest.java @@ -16,6 +16,7 @@ */ package org.apache.camel.component.hazelcast; +import java.util.Arrays; import java.util.Collection; import com.hazelcast.core.Hazelcast; @@ -23,69 +24,56 @@ import com.hazelcast.core.HazelcastInstance; import com.hazelcast.core.MultiMap; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.AfterClass; +import org.junit.After; import org.junit.Test; +import org.mockito.Mock; +import static org.mockito.Mockito.*; -public class HazelcastMultimapProducerTest extends CamelTestSupport { +public class HazelcastMultimapProducerTest extends HazelcastCamelTestSupport { + @Mock private MultiMap<Object, Object> map; @Override - protected void doPostSetup() throws Exception { - HazelcastComponent component = context().getComponent("hazelcast", HazelcastComponent.class); - HazelcastInstance hazelcastInstance = component.getHazelcastInstance(); - this.map = hazelcastInstance.getMultiMap("bar"); - this.map.clear(); + protected void trainHazelcastInstance(HazelcastInstance hazelcastInstance) { + when(hazelcastInstance.getMultiMap("bar")).thenReturn(map); } - @AfterClass - public static void tearDownClass() { - Hazelcast.shutdownAll(); + @Override + protected void verifyHazelcastInstance(HazelcastInstance hazelcastInstance) { + verify(hazelcastInstance, atLeastOnce()).getMultiMap("bar"); + } + + @After + public void verifyMapMock() { + verifyNoMoreInteractions(map); } @Test public void testPut() throws InterruptedException { template.sendBodyAndHeader("direct:put", "my-foo", HazelcastConstants.OBJECT_ID, "4711"); - template.sendBodyAndHeader("direct:put", "my-bar", HazelcastConstants.OBJECT_ID, "4711"); - - assertTrue(map.containsKey("4711")); - Collection<Object> values = map.get("4711"); - - assertTrue(values.contains("my-foo")); - assertTrue(values.contains("my-bar")); + verify(map).put("4711", "my-foo"); } @Test public void testRemoveValue() { - map.put("4711", "my-foo"); - map.put("4711", "my-bar"); - - assertEquals(2, map.get("4711").size()); - template.sendBodyAndHeader("direct:removevalue", "my-foo", HazelcastConstants.OBJECT_ID, "4711"); - - assertEquals(1, map.get("4711").size()); - assertTrue(map.get("4711").contains("my-bar")); + verify(map).remove("4711", "my-foo"); } @Test public void testGet() { - map.put("4711", "my-foo"); - + when(map.get("4711")).thenReturn(Arrays.<Object>asList("my-foo")); template.sendBodyAndHeader("direct:get", null, HazelcastConstants.OBJECT_ID, "4711"); + verify(map).get("4711"); Collection<?> body = consumer.receiveBody("seda:out", 5000, Collection.class); - assertTrue(body.contains("my-foo")); } @Test public void testDelete() { - map.put(4711, "my-foo"); - assertEquals(1, map.size()); - template.sendBodyAndHeader("direct:delete", null, HazelcastConstants.OBJECT_ID, 4711); - assertEquals(0, map.size()); + verify(map).remove(4711); } @Override http://git-wip-us.apache.org/repos/asf/camel/blob/67aa3b3a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastQueueProducerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastQueueProducerTest.java b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastQueueProducerTest.java index 087729d..8877281 100644 --- a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastQueueProducerTest.java +++ b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastQueueProducerTest.java @@ -16,114 +16,85 @@ */ package org.apache.camel.component.hazelcast; -import java.util.concurrent.BlockingQueue; - -import com.hazelcast.core.Hazelcast; - import com.hazelcast.core.HazelcastInstance; +import com.hazelcast.core.IQueue; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.AfterClass; +import org.junit.After; import org.junit.Test; +import org.mockito.Mock; -public class HazelcastQueueProducerTest extends CamelTestSupport { +import static org.mockito.Mockito.*; - private BlockingQueue<String> queue; +public class HazelcastQueueProducerTest extends HazelcastCamelTestSupport { + + @Mock + private IQueue<String> queue; @Override - protected void doPostSetup() throws Exception { - HazelcastComponent component = context().getComponent("hazelcast", HazelcastComponent.class); - HazelcastInstance hazelcastInstance = component.getHazelcastInstance(); - queue = hazelcastInstance.getQueue("bar"); - queue.clear(); + protected void trainHazelcastInstance(HazelcastInstance hazelcastInstance) { + when(hazelcastInstance.<String>getQueue("bar")).thenReturn(queue); } - @AfterClass - public static void tearDownClass() { - Hazelcast.shutdownAll(); + @Override + protected void verifyHazelcastInstance(HazelcastInstance hazelcastInstance) { + verify(hazelcastInstance, atLeastOnce()).getQueue("bar"); + } + + @After + public void verifyQueueMock() { + verifyNoMoreInteractions(queue); } @Test public void put() throws InterruptedException { template.sendBody("direct:put", "foo"); - - assertTrue(queue.contains("foo")); - - queue.clear(); + verify(queue).put("foo"); } @Test - public void noOperation() throws InterruptedException { + public void noOperation() { template.sendBody("direct:no-operation", "bar"); - - assertTrue(queue.contains("bar")); - - queue.clear(); + verify(queue).add("bar"); } @Test - public void add() throws InterruptedException { + public void add() { template.sendBody("direct:add", "bar"); - - assertTrue(queue.contains("bar")); - - queue.clear(); + verify(queue).add("bar"); } @Test - public void offer() throws InterruptedException { + public void offer() { template.sendBody("direct:offer", "foobar"); - assertTrue(queue.contains("foobar")); - - queue.clear(); + verify(queue).offer("foobar"); } @Test - public void removeValue() throws InterruptedException { - queue.put("foo1"); - queue.put("foo2"); - queue.put("foo3"); - - assertEquals(3, queue.size()); - - // specify the value to remove + public void removeSpecifiedValue() throws InterruptedException { template.sendBody("direct:removevalue", "foo2"); - assertEquals(2, queue.size()); - assertTrue(queue.contains("foo1") && queue.contains("foo3")); + verify(queue).remove("foo2"); + } - // do not specify the value to delete (null) + @Test + public void removeValue() { template.sendBody("direct:removevalue", null); - assertEquals(1, queue.size()); - - assertTrue(queue.contains("foo3")); - - queue.clear(); + verify(queue).remove(); } @Test public void poll() throws InterruptedException { - queue.put("foo"); - assertEquals(1, queue.size()); - - template.sendBody("direct:poll", null); - - assertFalse(queue.contains("foo")); - assertEquals(0, queue.size()); - - queue.clear(); + when(queue.poll()).thenReturn("foo"); + String answer = template.requestBody("direct:poll", null, String.class); + verify(queue).poll(); + assertEquals("foo", answer); } @Test public void peek() throws InterruptedException { - queue.put("foo"); - assertEquals(1, queue.size()); - - template.sendBody("direct:peek", null); - - assertEquals(1, queue.size()); - assertTrue(queue.contains("foo")); - - queue.clear(); + when(queue.peek()).thenReturn("foo"); + String answer = template.requestBody("direct:peek", null, String.class); + verify(queue).peek(); + assertEquals("foo", answer); } @Override