From 98441b9a149987a7498ca5c499fb51dfb804dbec Mon Sep 17 00:00:00 2001 From: John Blum Date: Mon, 5 May 2014 11:46:52 -0700 Subject: [PATCH] Modified the testLookupQueryService method to use pure mock objects to test the lookup behavior and conditional statements. Added an assertion to the testLookupLocalQueryService test case to verify that the RegionService.getQueryService() method is 'never' called. --- .../data/gemfire/GemfireTemplateTest.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/springframework/data/gemfire/GemfireTemplateTest.java b/src/test/java/org/springframework/data/gemfire/GemfireTemplateTest.java index b1d01612..b89d9a7b 100644 --- a/src/test/java/org/springframework/data/gemfire/GemfireTemplateTest.java +++ b/src/test/java/org/springframework/data/gemfire/GemfireTemplateTest.java @@ -24,6 +24,7 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -183,17 +184,34 @@ public class GemfireTemplateTest { } @Test + @SuppressWarnings("unchecked") public void testLookupQueryService() { - assertSame(simple.getRegionService().getQueryService().getClass(), - template.lookupQueryService(simple).getClass()); + ClientCache mockClientCache = mock(ClientCache.class, "testLookupQueryService.ClientCache"); + QueryService mockQueryService = mock(QueryService.class, "testLookupQueryService.QueryService"); + Region mockRegion = mock(Region.class, "testLookupQueryService.Region"); + + when(mockRegion.getRegionService()).thenReturn(mockClientCache); + when(mockClientCache.getQueryService()).thenReturn(mockQueryService); + + GemfireTemplate localTemplate = new GemfireTemplate(mockRegion) { + @Override boolean isLocalWithNoServerProxy(final Region region) { + return false; + } + }; + + assertSame(mockQueryService, localTemplate.lookupQueryService(mockRegion)); + + verify(mockRegion, times(2)).getRegionService(); + verify(mockClientCache, times(1)).getQueryService(); + verify(mockClientCache, never()).getLocalQueryService(); } @Test @SuppressWarnings("unchecked") public void testLookupLocalQueryService() { ClientCache mockClientCache = mock(ClientCache.class, "testLookupLocalQueryService.ClientCache"); - Region mockRegion = mock(Region.class, "testLookupLocalQueryService.Region"); QueryService mockQueryService = mock(QueryService.class, "testLookupLocalQueryService.QueryService"); + Region mockRegion = mock(Region.class, "testLookupLocalQueryService.Region"); RegionAttributes mockRegionAttributes = mock(RegionAttributes.class, "testLookupLocalQueryService.RegionAttributes"); when(mockClientCache.getLocalQueryService()).thenReturn(mockQueryService); @@ -209,6 +227,7 @@ public class GemfireTemplateTest { assertSame(mockQueryService, localTemplate.lookupQueryService(mockRegion)); + verify(mockClientCache, never()).getQueryService(); verify(mockClientCache, times(1)).getLocalQueryService(); verify(mockRegion, times(2)).getRegionService(); verify(mockRegionAttributes, times(1)).getScope();