### Question:
Utilities { public static boolean aggregateOptimizationsSupported(RequestContext requestContext) { boolean isStatsAccessor = implementsInterface(requestContext.getAccessor(), StatsAccessor.class); return (isStatsAccessor && !requestContext.hasFilter() && (requestContext.getAggType() != null) && requestContext.getAggType().isOptimizationSupported() && requestContext.getNumAttrsProjected() == 0); }  static byte[] parseBase64(String encoded, String paramName); static boolean isValidDirectoryName(String name); static boolean isValidRestrictedDirectoryName(String name); static Object createAnyInstance(Class<?> confClass,
                                           String className, RequestContext metaData); static Object createAnyInstance(String className); static void byteArrayToOctalString(byte[] bytes, StringBuilder sb); static String maskNonPrintables(String input); static FragmentMetadata parseFragmentMetadata(RequestContext context); static boolean aggregateOptimizationsSupported(RequestContext requestContext); static boolean implementsInterface(String className, Class<?> iface); static boolean isFragmenterCacheEnabled(); static String absoluteDataPath(String dataSource); static boolean isSecurityEnabled(Configuration configuration); static String rightTrimWhiteSpace(String s); static String getHost(String uri); static final Pattern SCHEME_PATTERN; static final Pattern NON_HOSTNAME_CHARACTERS; }### Answer:
@Test public void useAggBridge() { RequestContext metaData = mock(RequestContext.class); when(metaData.getAccessor()).thenReturn(StatsAccessorImpl.class.getName()); when(metaData.getAggType()).thenReturn(EnumAggregationType.COUNT); when(metaData.getAccessor()).thenReturn("org.greenplum.pxf.api.utilities.UtilitiesTest$StatsAccessorImpl"); assertTrue(Utilities.aggregateOptimizationsSupported(metaData)); when(metaData.getAccessor()).thenReturn(UtilitiesTest.class.getName()); when(metaData.getAggType()).thenReturn(EnumAggregationType.COUNT); assertFalse(Utilities.aggregateOptimizationsSupported(metaData)); when(metaData.getAccessor()).thenReturn(StatsAccessorImpl.class.getName()); when(metaData.getAggType()).thenReturn(EnumAggregationType.COUNT); when(metaData.hasFilter()).thenReturn(true); assertFalse(Utilities.aggregateOptimizationsSupported(metaData)); }
@Test public void useStats() { RequestContext mockCtxSupporting = mock(RequestContext.class); when(mockCtxSupporting.getAggType()).thenReturn(EnumAggregationType.COUNT); when(mockCtxSupporting.getAccessor()).thenReturn("org.greenplum.pxf.api.utilities.UtilitiesTest$StatsAccessorImpl"); assertTrue(Utilities.aggregateOptimizationsSupported(mockCtxSupporting)); RequestContext mockCtxNonSupporting = mock(RequestContext.class); when(mockCtxNonSupporting.getAggType()).thenReturn(EnumAggregationType.COUNT); when(mockCtxNonSupporting.getAccessor()).thenReturn("org.greenplum.pxf.api.utilities.UtilitiesTest$NonStatsAccessorImpl"); assertFalse(Utilities.aggregateOptimizationsSupported(mockCtxNonSupporting)); RequestContext mockCtxFilter = mock(RequestContext.class); when(mockCtxFilter.getAggType()).thenReturn(EnumAggregationType.COUNT); when(mockCtxFilter.getAccessor()).thenReturn("org.greenplum.pxf.api.utilities.UtilitiesTest$StatsAccessorImpl"); when(mockCtxFilter.hasFilter()).thenReturn(true); assertFalse(Utilities.aggregateOptimizationsSupported(mockCtxFilter)); RequestContext mockCtxProjection = mock(RequestContext.class); when(mockCtxProjection.getAggType()).thenReturn(EnumAggregationType.COUNT); when(mockCtxProjection.getAccessor()).thenReturn("org.greenplum.pxf.api.utilities.UtilitiesTest$StatsAccessorImpl"); when(mockCtxProjection.hasFilter()).thenReturn(false); when(mockCtxProjection.getNumAttrsProjected()).thenReturn(1); assertFalse(Utilities.aggregateOptimizationsSupported(mockCtxProjection)); }