/** * Create a new capture instance that will keep only the last captured value * * @param <T> type of the class to be captured * @return the new capture object */ public static <T> Capture<T> newInstance() { return new Capture<>(); }
/** * Creates a control, order checking is disabled by default. * * @return the control. */ public static IMocksControl createControl() { return createControl(MockType.DEFAULT); }
/** * Create a new capture instance that will keep only the last captured value. * * @param <T> type of the class to be captured * @return the new capture object */ public static <T> Capture<T> newCapture() { return Capture.newInstance(); }
private Task createMockTask(String type) { Task mock = EasyMock.createMock(Task.class); EasyMock.expect(mock.getType()).andReturn(type).anyTimes(); EasyMock.replay(mock); return mock; }
private ImmutableWorkerInfo createMockWorker(int currCapacityUsed, boolean canRunTask, boolean isValidVersion) { ImmutableWorkerInfo worker = EasyMock.createMock(ImmutableWorkerInfo.class); EasyMock.expect(worker.canRunTask(EasyMock.anyObject(Task.class))).andReturn(canRunTask).anyTimes(); EasyMock.expect(worker.getCurrCapacityUsed()).andReturn(currCapacityUsed).anyTimes(); EasyMock.expect(worker.isValidVersion(EasyMock.anyString())).andReturn(isValidVersion).anyTimes(); EasyMock.replay(worker); return worker; }
private static MemcachedNode dummyNode(String host, int port) { SocketAddress address = InetSocketAddress.createUnresolved(host, port); MemcachedNode node = EasyMock.createNiceMock(MemcachedNode.class); EasyMock.expect(node.getSocketAddress()).andReturn(address).anyTimes(); EasyMock.replay(node); return node; } }
private void mockEmptyPeon() { EasyMock.expect(mockPeon.getSegmentsToLoad()).andReturn(new HashSet<>()).anyTimes(); EasyMock.expect(mockPeon.getSegmentsMarkedToDrop()).andReturn(new HashSet<>()).anyTimes(); EasyMock.expect(mockPeon.getLoadQueueSize()).andReturn(0L).atLeastOnce(); EasyMock.expect(mockPeon.getNumberOfSegmentsInQueue()).andReturn(0).anyTimes(); EasyMock.replay(mockPeon); }
private StorageLocation fakeLocation(long total, long free, long max, Double percent) { File file = EasyMock.mock(File.class); EasyMock.expect(file.getTotalSpace()).andReturn(total).anyTimes(); EasyMock.expect(file.getFreeSpace()).andReturn(free).anyTimes(); EasyMock.replay(file); return new StorageLocation(file, max, percent); }
private void expectAuthorizationTokenCheck() { AuthenticationResult authenticationResult = new AuthenticationResult("druid", "druid", null, null); EasyMock.expect(req.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).anyTimes(); EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).atLeastOnce(); EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)) .andReturn(authenticationResult) .atLeastOnce(); req.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, false); EasyMock.expectLastCall().anyTimes(); req.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true); EasyMock.expectLastCall().anyTimes(); }
/** * Prepares an executor service mock to expect the start of the timer. * * @param service the mock * @param future the future */ private void prepareStartTimer(final ScheduledExecutorService service, final ScheduledFuture<?> future) { service.scheduleAtFixedRate((Runnable) EasyMock.anyObject(), EasyMock .eq(PERIOD), EasyMock.eq(PERIOD), EasyMock.eq(UNIT)); EasyMock.expectLastCall().andReturn(future); }
@AndroidIncompatible // EasyMock Class Extension doesn't appear to work on Android. public void testMockingEasyMock() throws Exception { RateLimiter mock = EasyMock.createNiceMock(RateLimiter.class); EasyMock.replay(mock); doTestMocking(mock); }
/** * Expects any byte argument. For details, see the EasyMock documentation. * * @return {@code 0}. */ public static byte anyByte() { reportMatcher(Any.ANY); return 0; }
/** * Resets all registered mock objects (more exactly: the controls of the * mock objects) and turn them to a mock with strict behavior. For details, * see the EasyMock documentation. */ public void resetAllToStrict() { for (IMocksControl c : controls) { c.resetToStrict(); } }
/** * @param constructor * Constructor to be called when creating the mock * @param initArgs * Arguments passed to the constructor */ public ConstructorArgs(Constructor<?> constructor, Object... initArgs) { this.constructor = constructor; this.initArgs = initArgs; validateArgs(); }
private static ShardSpec shardSpec(String dimension, boolean contained) { ShardSpec shard = EasyMock.createMock(ShardSpec.class); EasyMock.expect(shard.getDomainDimensions()) .andReturn(ImmutableList.of(dimension)) .anyTimes(); EasyMock.expect(shard.possibleInDomain(EasyMock.anyObject())) .andReturn(contained) .anyTimes(); return shard; } }
/** * Expects any float argument. For details, see the EasyMock documentation. * * @return {@code 0}. */ public static float anyFloat() { reportMatcher(Any.ANY); return 0; }
private static LoadQueuePeon createEmptyPeon() { final LoadQueuePeon mockPeon = EasyMock.createMock(LoadQueuePeon.class); EasyMock.expect(mockPeon.getSegmentsToLoad()).andReturn(new HashSet<>()).anyTimes(); EasyMock.expect(mockPeon.getSegmentsMarkedToDrop()).andReturn(new HashSet<>()).anyTimes(); EasyMock.expect(mockPeon.getLoadQueueSize()).andReturn(0L).anyTimes(); EasyMock.expect(mockPeon.getNumberOfSegmentsInQueue()).andReturn(0).anyTimes(); return mockPeon; }
@Before public void setUp() { tierSelectorStrategy = EasyMock.createMock(TierSelectorStrategy.class); expect(tierSelectorStrategy.getComparator()).andReturn(Integer::compare).anyTimes(); }