@Test(expected = Error.class) public void testWhenComputableThrowsError() throws Exception { final Integer input = 1; final Memoizer<Integer, Integer> memoizer = new Memoizer<>(computable); final Error error = new Error(); expect(computable.compute(input)).andThrow(error); replay(computable); memoizer.compute(input); } }
@Test public void testChunking() { Query query = queryBuilder.intervals("2015-01-01T00:00:00.000/2015-01-11T00:00:00.000").context(ImmutableMap.of("chunkPeriod", "P1D")).build(); executors.execute(EasyMock.anyObject(Runnable.class)); EasyMock.expectLastCall().times(10); EasyMock.replay(executors); EasyMock.replay(toolChest); QueryRunner runner = decorator.decorate(baseRunner, toolChest); runner.run(QueryPlus.wrap(query), Collections.EMPTY_MAP); EasyMock.verify(executors); }
@Before public void setUp() { resourceFactory = (ResourceFactory<String, String>) EasyMock.createMock(ResourceFactory.class); EasyMock.replay(resourceFactory); pool = new ResourcePool<String, String>( resourceFactory, new ResourcePoolConfig(2, TimeUnit.MINUTES.toMillis(4)) ); EasyMock.verify(resourceFactory); EasyMock.reset(resourceFactory); }
@Test public void testGetEmitter() { ComposingEmitterConfig config = EasyMock.createMock(ComposingEmitterConfig.class); EasyMock.expect(config.getEmitters()).andReturn(Collections.singletonList(testEmitterType)).anyTimes(); Injector injector = EasyMock.createMock(Injector.class); EasyMock.expect(injector.getInstance(Key.get(Emitter.class, Names.named(testEmitterType)))).andReturn(emitter); EasyMock.replay(config, injector); Emitter composingEmitter = new ComposingEmitterModule().getEmitter(config, injector); composingEmitter.start(); EasyMock.verify(config, emitter, injector); }
@Test(expected = RuntimeException.class) public void testWhenComputableThrowsRuntimeException() throws Exception { final Integer input = 1; final Memoizer<Integer, Integer> memoizer = new Memoizer<>(computable); final RuntimeException runtimeException = new RuntimeException("Some runtime exception"); expect(computable.compute(input)).andThrow(runtimeException); replay(computable); memoizer.compute(input); }
@Test public void testHasNext() { boolean expected = true; EasyMock.expect(peekIterator.hasNext()).andReturn(expected); EasyMock.replay(peekIterator); boolean actual = testingIterator.hasNext(); EasyMock.verify(peekIterator); Assert.assertEquals("The hasNext function is broken", expected, actual); }
private Task createMockTask(String type) { Task mock = EasyMock.createMock(Task.class); EasyMock.expect(mock.getType()).andReturn(type).anyTimes(); EasyMock.replay(mock); return mock; }
/** * Tests a successful initializeUnchecked() operation. * * @throws org.apache.commons.lang3.concurrent.ConcurrentException so we don't have to catch it */ @Test public void testInitializeUnchecked() throws ConcurrentException { @SuppressWarnings("unchecked") final ConcurrentInitializer<Object> init = EasyMock .createMock(ConcurrentInitializer.class); final Object result = new Object(); EasyMock.expect(init.get()).andReturn(result); EasyMock.replay(init); assertSame("Wrong result object", result, ConcurrentUtils .initializeUnchecked(init)); EasyMock.verify(init); }
/** * Tests a successful initialize() operation. * * @throws org.apache.commons.lang3.concurrent.ConcurrentException so we don't have to catch it */ @Test public void testInitialize() throws ConcurrentException { @SuppressWarnings("unchecked") final ConcurrentInitializer<Object> init = EasyMock .createMock(ConcurrentInitializer.class); final Object result = new Object(); EasyMock.expect(init.get()).andReturn(result); EasyMock.replay(init); assertSame("Wrong result object", result, ConcurrentUtils .initialize(init)); EasyMock.verify(init); }
@Test public void testFalseBranchNext() { boolean expected = true; EasyMock.expect(peekIterator.hasNext()).andReturn(expected); expected = false; EasyMock.expect(peekIterator.hasNext()).andReturn(expected); EasyMock.replay(peekIterator); Object res = testingIterator.next(); EasyMock.verify(peekIterator); Assert.assertNull("Should be null", res); }
@Test public void testGetRedirectURL() { String query = "foo=bar&x=y"; String request = "/request"; EasyMock.expect(druidCoordinator.getCurrentLeader()).andReturn("http://localhost").anyTimes(); EasyMock.replay(druidCoordinator); URL url = coordinatorRedirectInfo.getRedirectURL(query, request); Assert.assertEquals("http://localhost/request?foo=bar&x=y", url.toString()); EasyMock.verify(druidCoordinator); } }
@Test public void testGetRedirectURL() { String host = "http://localhost"; String query = "foo=bar&x=y"; String request = "/request"; EasyMock.expect(taskMaster.getCurrentLeader()).andReturn(host).anyTimes(); EasyMock.replay(taskMaster); URL url = redirectInfo.getRedirectURL(query, request); Assert.assertEquals("http://localhost/request?foo=bar&x=y", url.toString()); EasyMock.verify(taskMaster); }
/** * Tests whether the thread name is not modified if no naming pattern is * set. */ @Test public void testNewThreadNoNamingPattern() { final ThreadFactory wrapped = EasyMock.createMock(ThreadFactory.class); final Runnable r = EasyMock.createMock(Runnable.class); final String name = "unchangedThreadName"; final Thread t = new Thread(name); EasyMock.expect(wrapped.newThread(r)).andReturn(t); EasyMock.replay(wrapped, r); final BasicThreadFactory factory = builder.wrappedFactory(wrapped).build(); assertSame("Wrong thread", t, factory.newThread(r)); assertEquals("Name was changed", name, t.getName()); EasyMock.verify(wrapped, r); }
/** * Tests whether the original priority is not changed if no priority is * specified. */ @Test public void testNewThreadNoPriority() { final ThreadFactory wrapped = EasyMock.createMock(ThreadFactory.class); final Runnable r = EasyMock.createMock(Runnable.class); final int orgPriority = Thread.NORM_PRIORITY + 1; final Thread t = new Thread(); t.setPriority(orgPriority); EasyMock.expect(wrapped.newThread(r)).andReturn(t); EasyMock.replay(wrapped, r); final BasicThreadFactory factory = builder.wrappedFactory(wrapped).build(); assertSame("Wrong thread", t, factory.newThread(r)); assertEquals("Wrong priority", orgPriority, t.getPriority()); EasyMock.verify(wrapped, r); }
/** * Tests createIfAbsent() if a null map is passed in. * * @throws org.apache.commons.lang3.concurrent.ConcurrentException so we don't have to catch it */ @Test public void testCreateIfAbsentNullMap() throws ConcurrentException { @SuppressWarnings("unchecked") final ConcurrentInitializer<Integer> init = EasyMock .createMock(ConcurrentInitializer.class); EasyMock.replay(init); assertNull("Wrong result", ConcurrentUtils.createIfAbsent(null, "test", init)); EasyMock.verify(init); }