org.easymock.IAnswer Java Examples
The following examples show how to use
org.easymock.IAnswer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MappedCreateTest.java From ormlite-core with ISC License | 6 votes |
@Test(expected = SQLException.class) public void testArgumentHolderSetZero() throws Exception { TableInfo<Foo, Integer> tableInfo = new TableInfo<Foo, Integer>(databaseType, Foo.class); Dao<Foo, Integer> dao = createDao(Foo.class, false); MappedCreate<Foo, Integer> mappedCreate = MappedCreate.build(dao, tableInfo); DatabaseConnection conn = createMock(DatabaseConnection.class); expect(conn.insert(isA(String.class), isA(Object[].class), isA(FieldType[].class), isA(GeneratedKeyHolder.class))).andAnswer(new IAnswer<Integer>() { @Override public Integer answer() throws Throwable { GeneratedKeyHolder holder = (GeneratedKeyHolder) getCurrentArguments()[3]; holder.addKey((Integer) 0); return 1; } }); replay(conn); mappedCreate.insert(databaseType, conn, new Foo(), null); }
Example #2
Source File: TestForEachModelAction.java From arcusplatform with Apache License 2.0 | 6 votes |
@Test public void testOneMatchingModel() { mockAction.execute(context); EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() { @Override public Object answer() throws Throwable { // verify that the address has been changed assertEquals(model1.getAddress(), context.getVariable(targetVariable)); return null; } }); EasyMock.replay(mockAction); ForEachModelAction selector = new ForEachModelAction(mockAction, Predicates.<Model>equalTo(model1), "address"); selector.execute(context); assertNull(context.getVariable(targetVariable)); EasyMock.verify(mockAction); }
Example #3
Source File: ProxyTest.java From FlowSpaceFirewall with Apache License 2.0 | 6 votes |
public void setupFSFW(){ fsfw = createMock(FlowSpaceFirewall.class); List<OFStatistics> stats = new ArrayList<OFStatistics>(); proxies = new ArrayList<Proxy>(); expect(fsfw.getStats(EasyMock.anyLong())).andReturn(stats).anyTimes(); expect(fsfw.getSwitchProxies(EasyMock.anyLong())).andReturn(proxies).anyTimes(); fsfw.removeProxy(EasyMock.anyLong(), EasyMock.isA(Proxy.class)); EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() { public Object answer(){ log.error("removed the proxy!"); return null; } }).anyTimes(); fsfw.addFlowCache(EasyMock.anyLong(), EasyMock.anyObject(String.class), EasyMock.anyObject(OFFlowMod.class), EasyMock.anyObject(List.class)); EasyMock.expectLastCall().anyTimes(); fsfw.delFlowCache(EasyMock.anyLong(), EasyMock.anyObject(String.class), EasyMock.anyObject(OFFlowMod.class), EasyMock.anyObject(List.class)); EasyMock.expectLastCall().anyTimes(); EasyMock.replay(fsfw); }
Example #4
Source File: FakeScheduledExecutor.java From attic-aurora with Apache License 2.0 | 6 votes |
private static IAnswer<ScheduledFuture<?>> answerScheduleAtFixedRate( FakeScheduledExecutor executor, int workCount) { return () -> { Object[] args = EasyMock.getCurrentArguments(); Runnable work = (Runnable) args[0]; long initialDelay = (Long) args[1]; long period = (Long) args[2]; TimeUnit unit = (TimeUnit) args[3]; for (int i = 0; i <= workCount; i++) { addDelayedWork(executor, toMillis(initialDelay, unit) + i * toMillis(period, unit), work); } return null; }; }
Example #5
Source File: TestCallTree.java From arcusplatform with Apache License 2.0 | 6 votes |
private static void initEasyMockVariableSupport(final SubsystemContext<? extends SubsystemModel> context){ // basically this is implementing variable support final Capture<String> nameRef = EasyMock.newCapture(CaptureType.LAST); final Capture<Object> valueRef = EasyMock.newCapture(CaptureType.LAST); EasyMock .expect(context.getVariable(EasyMock.capture(nameRef))) .andAnswer(new IAnswer<LooselyTypedReference>() { @Override public LooselyTypedReference answer() throws Throwable { String json = context.model().getAttribute(TypeMarker.string(), "_subvars:" + nameRef.getValue(), "null"); return JSON.fromJson(json, LooselyTypedReference.class); } }) .anyTimes(); context.setVariable(EasyMock.capture(nameRef), EasyMock.capture(valueRef)); EasyMock .expectLastCall() .andAnswer(new IAnswer<Object>() { @Override public Object answer() throws Throwable { context.model().setAttribute("_subvars:" + nameRef.getValue(), JSON.toJson(valueRef.getValue())); return null; } }) .anyTimes(); }
Example #6
Source File: TestForEachModelAction.java From arcusplatform with Apache License 2.0 | 6 votes |
@Test public void testOneMatchingModel() { final RuleContext namespacedContext = new NamespaceContext(model1.getId(), context); mockAction.execute(namespacedContext); EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() { @Override public Object answer() throws Throwable { // verify that the address has been changed assertEquals(model1.getAddress(), namespacedContext.getVariable(targetVariable)); return ActionState.FIRING; } }); EasyMock.replay(mockAction); ForEachModelAction selector = new ForEachModelAction(mockAction, Predicates.<Model>alwaysTrue(), Predicates.<Model>equalTo(model1), "address"); selector.execute(context); assertNull(context.getVariable(targetVariable)); assertEquals(ImmutableList.<Address>of(model1.getAddress()),context.getVariable(ForEachModelAction.VAR_STILL_FIRING)); EasyMock.verify(mockAction); }
Example #7
Source File: LoggingInInterceptorTest.java From cxf with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { loggingMessage = new LoggingMessage("", ""); control = EasyMock.createNiceControl(); StringWriter sw = new StringWriter(); sw.append("<today/>"); message = new MessageImpl(); message.setExchange(new ExchangeImpl()); message.put(Message.CONTENT_TYPE, "application/xml"); message.setContent(Writer.class, sw); inputStream = control.createMock(InputStream.class); EasyMock.expect(inputStream.read(EasyMock.anyObject(byte[].class), EasyMock.anyInt(), EasyMock.anyInt())) .andAnswer(new IAnswer<Integer>() { public Integer answer() { System.arraycopy(bufferContent.getBytes(), 0, EasyMock.getCurrentArguments()[0], 0, bufferLength); return bufferLength; } }).andStubReturn(-1); control.replay(); }
Example #8
Source File: TestSetAttributes.java From arcusplatform with Apache License 2.0 | 6 votes |
private void setupUpdateEmail(String newEmail) { personDao.setUpdateFlag(person.getId(), true); EasyMock.expectLastCall(); EasyMock.expect(personDao.updatePersonAndEmail(person, person.getEmail())).andAnswer(new IAnswer<Person>() { @Override public Person answer() throws Throwable { Person newPerson = person.copy(); newPerson.setEmail(newEmail); return newPerson; } }); personDao.setUpdateFlag(person.getId(), false); EasyMock.expectLastCall(); EasyMock.expect(personPlaceAssocDao.findPlaceIdsByPerson(person.getId())).andReturn(ImmutableSet.<UUID>of(firstPlace.getId())); }
Example #9
Source File: MongoStoreTest.java From todo-apps with Apache License 2.0 | 6 votes |
@Test public void testPersist() { DBCollection coll = createMockCollection(); ToDo td = new ToDo(); td.setTitle("This is a test"); td.setId("aaaaaaaaaaaaaaaaaaaaaaa1"); expect(coll.insert(isA(DBObject.class))).andAnswer(new IAnswer<WriteResult>() { @Override public WriteResult answer() throws Throwable { DBObject obj = (DBObject)getCurrentArguments()[0]; obj.put("_id", new ObjectId("aaaaaaaaaaaaaaaaaaaaaaa1")); return null; } }); replay(coll); MongoStore store = new MongoStore(coll); assertEquals(td, store.persist(td)); verify(coll); }
Example #10
Source File: ArrayUtilsTest.java From saros with GNU General Public License v2.0 | 6 votes |
@Before public void createMock() { adapterManager = EasyMock.createMock(IAdapterManager.class); EasyMock.expect( adapterManager.getAdapter(EasyMock.anyObject(), EasyMock.anyObject(Class.class))) .andAnswer( new IAnswer<Object>() { @Override public Object answer() throws Throwable { return EasyMock.getCurrentArguments()[0]; } }) .anyTimes(); EasyMock.replay(adapterManager); }
Example #11
Source File: MappedCreateTest.java From ormlite-core with ISC License | 6 votes |
@Test(expected = SQLException.class) public void testArgumentHolderDoubleSet() throws Exception { TableInfo<Foo, Integer> tableInfo = new TableInfo<Foo, Integer>(databaseType, Foo.class); Dao<Foo, Integer> dao = createDao(Foo.class, false); MappedCreate<Foo, Integer> mappedCreate = MappedCreate.build(dao, tableInfo); DatabaseConnection conn = createMock(DatabaseConnection.class); expect(conn.insert(isA(String.class), isA(Object[].class), isA(FieldType[].class), isA(GeneratedKeyHolder.class))).andAnswer(new IAnswer<Integer>() { @Override public Integer answer() throws Throwable { GeneratedKeyHolder holder = (GeneratedKeyHolder) getCurrentArguments()[3]; holder.addKey((Integer) 1); holder.addKey((Integer) 2); return 1; } }); replay(conn); mappedCreate.insert(databaseType, conn, new Foo(), null); }
Example #12
Source File: TiffImporterTest.java From proarc with GNU General Public License v3.0 | 6 votes |
private DaoFactory createMockDaoFactory() { DaoFactory daos = EasyMock.createMock(DaoFactory.class); EasyMock.expect(daos.createTransaction()).andAnswer(new IAnswer<Transaction>() { @Override public Transaction answer() throws Throwable { return createMockTransaction(); } }).anyTimes(); EasyMock.expect(daos.createBatchItem()).andAnswer(new IAnswer<BatchItemDao>() { @Override public BatchItemDao answer() throws Throwable { return createMockBatchItemDao(); } }).anyTimes(); EasyMock.replay(daos); toVerify.add(daos); return daos; }
Example #13
Source File: WaveImporterTest.java From proarc with GNU General Public License v3.0 | 6 votes |
private DaoFactory createMockDaoFactory() { DaoFactory daos = EasyMock.createMock(DaoFactory.class); EasyMock.expect(daos.createTransaction()).andAnswer(new IAnswer<Transaction>() { @Override public Transaction answer() throws Throwable { return createMockTransaction(); } }).anyTimes(); EasyMock.expect(daos.createBatchItem()).andAnswer(new IAnswer<BatchItemDao>() { @Override public BatchItemDao answer() throws Throwable { return createMockBatchItemDao(); } }).anyTimes(); EasyMock.replay(daos); toVerify.add(daos); return daos; }
Example #14
Source File: GameProtocolCodecFilterTest.java From gameserver with Apache License 2.0 | 5 votes |
private void encodeAndDecodeProxyMessage(XinqiProxyMessage response, boolean checkDecoder) throws Exception { ProtobufEncoder encoder = new ProtobufEncoder(); ProtobufDecoder decoder = new ProtobufDecoder(); final ArrayList<Object> results = new ArrayList<Object>(); IoSession session = createNiceMock(IoSession.class); expect(session.getTransportMetadata()).andReturn( new DefaultTransportMetadata("testprovider", "default", false, true, InetSocketAddress.class, DefaultSocketSessionConfig.class, SessionMessage.class)).anyTimes(); IoBuffer buffer = (IoBuffer)ProtobufEncoder.encodeXinqiProxyMessage(response); ProtocolDecoderOutput deout = createNiceMock(ProtocolDecoderOutput.class); if ( checkDecoder ) { deout.write(anyObject()); expectLastCall().andAnswer(new IAnswer<Object>() { @Override public Object answer() throws Throwable { results.add(getCurrentArguments()[0]); return null; } }).times(1); } replay(session); replay(deout); decoder.decode(session, buffer, deout); verify(session); verify(deout); if ( checkDecoder ) { XinqiProxyMessage decodeMsg = (XinqiProxyMessage)results.get(0); assertEquals(response.userSessionKey, decodeMsg.userSessionKey); assertEquals(response.xinqi.payload.getClass(), decodeMsg.xinqi.payload.getClass()); } }
Example #15
Source File: FakeScheduledExecutor.java From attic-aurora with Apache License 2.0 | 5 votes |
private static IAnswer<Object> answerExecuteWithDelay(FakeScheduledExecutor executor) { return () -> { Object[] args = EasyMock.getCurrentArguments(); Runnable work = (Runnable) args[0]; @SuppressWarnings("unchecked") long value = (long) args[1]; @SuppressWarnings("unchecked") TimeUnit unit = (TimeUnit) args[2]; addDelayedWork(executor, TimeUnit.MILLISECONDS.convert(value, unit), work); return null; }; }
Example #16
Source File: ProxyTest.java From FlowSpaceFirewall with Apache License 2.0 | 5 votes |
public void setupChannel() throws IOException{ ChannelFuture future = createMock(org.jboss.netty.channel.ChannelFuture.class); ChannelPipeline pipeline = createMock(org.jboss.netty.channel.ChannelPipeline.class); ChannelHandlerContext context = createMock(org.jboss.netty.channel.ChannelHandlerContext.class); handler = EasyMock.createNiceMock(edu.iu.grnoc.flowspace_firewall.OFControllerChannelHandler.class); channel = EasyMock.createNiceMock(org.jboss.netty.channel.socket.SocketChannel.class); ChannelFuture otherFuture = createMock(org.jboss.netty.channel.ChannelFuture.class); expect(channel.getPipeline()).andReturn(pipeline).anyTimes(); expect(pipeline.getContext("handler")).andReturn(context).anyTimes(); expect(context.getHandler()).andReturn(handler).anyTimes(); expect(channel.connect(EasyMock.isA(java.net.InetSocketAddress.class))).andReturn(future).anyTimes(); expect(channel.write(EasyMock.isA(org.openflow.protocol.OFMessage.class))).andReturn(otherFuture).anyTimes(); handler.setSwitch(EasyMock.isA(net.floodlightcontroller.core.IOFSwitch.class)); EasyMock.expectLastCall().anyTimes(); handler.setProxy(EasyMock.isA(edu.iu.grnoc.flowspace_firewall.Proxy.class)); EasyMock.expectLastCall().anyTimes(); handler.sendMessage(EasyMock.isA(org.openflow.protocol.OFMessage.class)); EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() { public Object answer() { //supply your mock implementation here... messagesSentToController.add((OFMessage)EasyMock.getCurrentArguments()[0]); //return the value to be returned by the method (null for void) return null; } }).anyTimes(); EasyMock.replay(future); EasyMock.replay(pipeline); EasyMock.replay(context); //EasyMock.replay(handler); EasyMock.replay(otherFuture); }
Example #17
Source File: MongoStoreTest.java From todo-apps with Apache License 2.0 | 5 votes |
@Test public void testCount() throws Exception { DBCollection coll = createMockCollection(); DBCursor cursor = createMockCursor(); expect(cursor.hasNext()).andAnswer(new IAnswer<Boolean>() { private int count = 0; @Override public Boolean answer() throws Throwable { count++; return count == 3 ? false : true; } }).anyTimes(); expect(cursor.next()).andAnswer(new IAnswer<DBObject>() { private int count = 0; @Override public DBObject answer() throws Throwable { count++; BasicDBObject dbObj = new BasicDBObject(); dbObj.put("title", "This is todo " + count); dbObj.put("completed", false); dbObj.put("order", count); //Object IDs must be 24 characters long dbObj.put("_id", new ObjectId("aaaaaaaaaaaaaaaaaaaaaaa" + count)); return dbObj; } }).anyTimes(); cursor.close(); expectLastCall(); replay(cursor); expect(coll.find()).andReturn(cursor); replay(coll); MongoStore store = new MongoStore(coll); assertEquals(2, store.count()); verify(cursor); verify(coll); }
Example #18
Source File: BceLoginReadyHandlerTest.java From gameserver with Apache License 2.0 | 5 votes |
private void registerUser2(String userName) throws Exception { BceRegister.Builder payload = BceRegister.getDefaultInstance().newBuilderForType(); payload.setUsername(userName); payload.setPassword("000000"); BceRegister msg = payload.build(); XinqiMessage message = new XinqiMessage(); message.index = 1; message.type = MessageToId.messageToId(msg); message.payload = msg; BceRegisterHandler handler = BceRegisterHandler.getInstance(); IoSession session = createMock(IoSession.class); session.write(anyObject()); expectLastCall().andAnswer(new IAnswer<Object>() { public Object answer() { return null; } }); replay(session); handler.messageProcess(session, message, null); verify(session); }
Example #19
Source File: DefaultPageServiceTest.java From attic-rave with Apache License 2.0 | 5 votes |
@Test public void addNewUserPage_existingPages() { final String PAGE_NAME = "my new page"; final Long EXPECTED_RENDER_SEQUENCE = 2L; List<Page> existingPages = new ArrayList<Page>(); existingPages.add(new PageImpl()); Page expectedPage = new PageImpl(); expectedPage.setName(PAGE_NAME); expectedPage.setOwnerId(user.getId()); expectedPage.setPageLayout(pageLayout); expectedPage.setRegions(createEmptyRegionList(pageLayout.getNumberOfRegions())); PageUser lPageUser = new PageUserImpl(user.getId(), expectedPage, EXPECTED_RENDER_SEQUENCE); List<PageUser> members = new ArrayList<PageUser>(); members.add(lPageUser); expectedPage.setMembers(members); expect(userService.getAuthenticatedUser()).andReturn(user); expect(pageLayoutRepository.getByPageLayoutCode(PAGE_LAYOUT_CODE)).andReturn(pageLayout); expect(pageRepository.save(expectedPage)).andAnswer(new IAnswer<Page>() { @Override public Page answer() throws Throwable { return (Page)EasyMock.getCurrentArguments()[0]; } }); expect(pageRepository.getAllPagesForUserType(user.getId(), PageType.USER.toString())).andReturn(existingPages); replay(userService, pageLayoutRepository, pageRepository); Page newPage = pageService.addNewUserPage(PAGE_NAME, PAGE_LAYOUT_CODE); assertThat(newPage.getMembers().get(0).getRenderSequence(), is(EXPECTED_RENDER_SEQUENCE)); assertThat(newPage.getName(), is(PAGE_NAME)); assertThat(newPage.getRegions().size(), is(pageLayout.getNumberOfRegions().intValue())); assertThat(newPage.getPageType(), is(PageType.USER.toString())); for (Region region : newPage.getRegions()) { assertThat(region.isLocked(), is(false)); } verify(userService, pageLayoutRepository, pageRepository); }
Example #20
Source File: DefaultPageServiceTest.java From attic-rave with Apache License 2.0 | 5 votes |
@Test public void clonePage_noRegions() { PageLayout layout = new PageLayoutImpl("foobar"); layout.setNumberOfRegions(0L); layout.setRenderSequence(1L); page.setPageLayout(layout); page.setRegions(new ArrayList<Region>()); page.setSubPages(new ArrayList<Page>()); expect(userService.getAuthenticatedUser()).andReturn(user); expect(pageRepository.get(PAGE_ID)).andReturn(page); List<Page> pages = Lists.newLinkedList(); pages.add(page); expect(pageRepository.getAllPagesForUserType(user.getId(), "user")).andReturn(pages); final Capture<Page> pageCapture = new Capture<Page>(); expect(pageRepository.save(capture(pageCapture))).andAnswer(new IAnswer<Page>() { @Override public Page answer() throws Throwable { Page savedPage = (Page) EasyMock.getCurrentArguments()[0]; savedPage.setId("42"); return savedPage; } }).anyTimes(); expect(pageRepository.get("42")).andAnswer(new IAnswer<Page>() { @Override public Page answer() throws Throwable { return pageCapture.getValue(); } }); expect(pageLayoutRepository.getByPageLayoutCode("foobar")).andReturn(layout); expect(userService.getUserById(user.getId())).andReturn(user); replay(pageLayoutRepository, pageRepository, userService); Page clonedPage = pageService.clonePageForUser(PAGE_ID, user.getId(), null); assertEquals("ID matches", "42", clonedPage.getId()); assertEquals("Owner ID is set", user.getId(), clonedPage.getOwnerId()); assertEquals("Layout is set", "foobar", clonedPage.getPageLayout().getCode()); }
Example #21
Source File: HttpDecoderTest.java From gameserver with Apache License 2.0 | 5 votes |
@Test public void testDoDecodeWithLF() throws Exception { String request = "GET /equipment_config.lua HTTP/1.1\nHost: localhost\n\n"; final HttpMessage expect = new HttpMessage(); expect.setRequestUri("/equipment_config.lua"); HttpDecoder decoder = new HttpDecoder(); IoSession session = createMock(IoSession.class); //Set mock behavior expect(session.getAttribute(eq("HttpDecoder.Session"))).andReturn(null).anyTimes(); expect(session.setAttribute(eq("HttpDecoder.Session"), anyObject())).andReturn(null).anyTimes(); replay(session); ProtocolDecoderOutput out = createNiceMock(ProtocolDecoderOutput.class); out.write(anyObject()); expectLastCall().andAnswer(new IAnswer<Object>() { public Object answer() { HttpMessage message = (HttpMessage)getCurrentArguments()[0]; assertTrue(compareHttpMessage(expect, message)); assertFalse(message.isHead()); return null; } }); replay(out); IoBuffer in = IoBuffer.wrap(request.getBytes()); int l = in.remaining(); boolean result = true; while ( result ) { result = decoder.doDecode(session, in, out); } verify(session); verify(out); assertTrue(true); }
Example #22
Source File: EclipseWorkspaceImplTest.java From saros with GNU General Public License v2.0 | 5 votes |
@Before public void setup() { workspaceDelegateMock = EasyMock.createMock(org.eclipse.core.resources.IWorkspace.class); try { workspaceDelegateMock.run( EasyMock.isA(org.eclipse.core.resources.IWorkspaceRunnable.class), EasyMock.anyObject(org.eclipse.core.runtime.jobs.ISchedulingRule.class), EasyMock.anyInt(), EasyMock.anyObject(org.eclipse.core.runtime.IProgressMonitor.class)); } catch (CoreException e) { // cannot happen } EasyMock.expectLastCall() .andStubAnswer( new IAnswer<Object>() { @Override public Object answer() throws Throwable { ((org.eclipse.core.resources.IWorkspaceRunnable) EasyMock.getCurrentArguments()[0]) .run( (org.eclipse.core.runtime.IProgressMonitor) EasyMock.getCurrentArguments()[3]); return null; } }); EasyMock.expect(workspaceDelegateMock.getRoot()).andStubReturn(null); EasyMock.replay(workspaceDelegateMock); workspace = new EclipseWorkspaceImpl(workspaceDelegateMock); }
Example #23
Source File: BceLoginHandlerTest.java From gameserver with Apache License 2.0 | 5 votes |
private void registerUser2(String userName) throws Exception { BceRegister.Builder payload = BceRegister.getDefaultInstance().newBuilderForType(); payload.setUsername(userName); payload.setPassword("000000"); BceRegister msg = payload.build(); XinqiMessage message = new XinqiMessage(); message.index = 1; message.type = MessageToId.messageToId(msg); message.payload = msg; BceRegisterHandler handler = BceRegisterHandler.getInstance(); IoSession session = createMock(IoSession.class); session.write(anyObject()); expectLastCall().andAnswer(new IAnswer<Object>() { public Object answer() { return null; } }); replay(session); handler.messageProcess(session, message, null); verify(session); }
Example #24
Source File: BceLoginHandlerTest.java From gameserver with Apache License 2.0 | 5 votes |
private void registerUser(String userName) throws Exception { BceRegister.Builder payload = BceRegister.getDefaultInstance().newBuilderForType(); payload.setUsername(userName); payload.setPassword("000000"); BceRegister msg = payload.build(); XinqiMessage message = new XinqiMessage(); message.index = 1; message.type = MessageToId.messageToId(msg); message.payload = msg; BceRegisterHandler handler = BceRegisterHandler.getInstance(); IoSession session = createMock(IoSession.class); session.write(anyObject()); expectLastCall().andAnswer(new IAnswer<Object>() { public Object answer() { XinqiMessage response = (XinqiMessage)getCurrentArguments()[0]; XinqiBseRegister.BseRegister register = (XinqiBseRegister.BseRegister)response.payload; assertEquals(LoginManager.RegisterErrorCode.SUCCESS.ordinal(), register.getCode()); return null; } }); replay(session); handler.messageProcess(session, message, null); verify(session); }
Example #25
Source File: BceLoginHandlerTest.java From gameserver with Apache License 2.0 | 5 votes |
@Test public void testSessionNotFoundUser() throws Exception { String userName = randomUserName(); BceLogin.Builder payload = BceLogin.getDefaultInstance().newBuilderForType(); payload.setUsername(userName); payload.setPassword("000000"); BceLogin msg = payload.build(); XinqiMessage message = new XinqiMessage(); message.index = 1; message.type = MessageToId.messageToId(msg); message.payload = msg; BceLoginHandler handler = BceLoginHandler.getInstance(); IoSession session = createMock(IoSession.class); expect(session.write(anyObject())).andAnswer(new IAnswer<WriteFuture>(){ @Override public WriteFuture answer() throws Throwable { XinqiMessage response = (XinqiMessage)getCurrentArguments()[0]; BseLogin login = (BseLogin)response.payload; assertEquals(ErrorCode.NOTFOUND.ordinal(), login.getCode()); return null; } }).times(1); replay(session); handler.messageProcess(session, message, null); verify(session); }
Example #26
Source File: DurableStorageTest.java From attic-aurora with Apache License 2.0 | 5 votes |
private void expectPersist(Op op, Op... ops) { try { // Workaround for comparing streams. persistence.persist(anyObject()); expectLastCall().andAnswer((IAnswer<Void>) () -> { assertEquals( ImmutableList.<Op>builder().add(op).add(ops).build(), ((Stream<Op>) EasyMock.getCurrentArguments()[0]).collect(Collectors.toList())); return null; }); } catch (Persistence.PersistenceException e) { throw new RuntimeException(e); } }
Example #27
Source File: MessageTransferHandlerTest.java From gameserver with Apache License 2.0 | 5 votes |
@Test public void testMessageReceivedIoSessionObject() throws Exception { MessageTransferHandler handler = new MessageTransferHandler(); final IoSession userSession = createMock(IoSession.class); expect(userSession.isConnected()).andReturn(Boolean.TRUE); final MessageQueue messageQueue = createMock(MessageQueue.class); expect(messageQueue.findSession(anyObject(SessionKey.class))).andReturn(userSession); messageQueue.sessionWrite(anyObject(SessionKey.class), anyObject()); expectLastCall().andAnswer(new IAnswer<Object>() { @Override public Object answer() throws Throwable { SessionKey tmpSessionKey = (SessionKey)getCurrentArguments()[0]; IoBuffer tmpBuf = (IoBuffer)getCurrentArguments()[1]; assertEquals("7F00000100003039", tmpSessionKey.toString().substring(0, 16)); assertEquals(40, tmpBuf.array().length); // System.out.println(msg); return null; } }); TestUtil.setPrivateFieldValue("messageQueue", handler, messageQueue); replay(messageQueue); replay(userSession); SessionRawMessage message = createSessionRawMessage(40); handler.messageReceived(null, message); verify(messageQueue); verify(userSession); }
Example #28
Source File: NetworkRouteTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
public static ExpectationWaiter waiterForLastVoidCall() { final ExpectationWaiter waiter = new ExpectationWaiter(); EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() { @Override public Object answer() throws Throwable { waiter.latch.countDown(); return null; } }); return waiter; }
Example #29
Source File: SarosSessionTest.java From saros with GNU General Public License v2.0 | 5 votes |
private static XMPPConnectionService createConnectionServiceMock() { XMPPConnectionService srv = createNiceMock(XMPPConnectionService.class); expect(srv.getJID()) .andStubAnswer( new IAnswer<JID>() { @Override public JID answer() throws Throwable { return new JID("alice"); } }); replay(srv); return srv; }
Example #30
Source File: NetworkRouteTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
public static ArgHolder holdArgsForLastFutureRequestCall() { final ArgHolder holder = new ArgHolder(); EasyMock.expect(new FutureResponse(null)).andAnswer(new IAnswer<FutureResponse>() { @Override public FutureResponse answer() throws Throwable { Object[] args = EasyMock.getCurrentArguments(); holder.arguments = Arrays.copyOf(args, args.length); return null; } }); return holder; }