How to use strictMock method of org.easymock.EasyMock class

Best Easymock code snippet using org.easymock.EasyMock.strictMock

Source:EncryptedBlobTypeTest.java Github

copy

Full Screen

...76 @Test77 public void testGetSet() throws SQLException {78 final String[] columnNames = {"column1"};7980 final SessionImplementor session = EasyMock.strictMock(SessionImplementor.class);81 final SessionFactoryImplementor factory = EasyMock.strictMock(SessionFactoryImplementor.class);82 final JdbcServices services = EasyMock.strictMock(JdbcServices.class);83 final LobCreator lobCreator = EasyMock.strictMock(LobCreator.class);8485 final Blob bIn = EasyMock.strictMock(Blob.class);86 final Blob bOut = EasyMock.strictMock(Blob.class);87 final PreparedStatement ps = EasyMock.strictMock(PreparedStatement.class);88 final ResultSet rs = EasyMock.strictMock(ResultSet.class);8990 EasyMock.expect(bIn.getBinaryStream()).andReturn(new ByteArrayInputStream(TEST_VALUE));91 final Capture<byte[]> encBytesCapt = EasyMock.newCapture();92 ps.setBytes(EasyMock.eq(1), EasyMock.capture(encBytesCapt));93 EasyMock.expectLastCall();94 EasyMock.replay(bIn, ps);95 type.nullSafeSet(ps, bIn, 1, null);96 EasyMock.verify(bIn, ps);97 final byte[] enc = encBytesCapt.getValue();9899 EasyMock.expect(rs.getBinaryStream(columnNames[0])).andReturn(new ByteArrayInputStream(enc));100 EasyMock.expect(rs.wasNull()).andReturn(false);101 EasyMock.expect(session.getFactory()).andReturn(factory);102 EasyMock.expect(factory.getJdbcServices()).andReturn(services);103 EasyMock.expect(services.getLobCreator(session)).andReturn(lobCreator);104 EasyMock.expect(lobCreator.createBlob(TEST_VALUE)).andReturn(bOut);105 EasyMock.replay(bOut, lobCreator, services, factory, session, rs);106 type.nullSafeGet(rs, columnNames, session, null);107 EasyMock.verify(bOut, lobCreator, services, factory, session, rs);108 }109110 @Test111 public void testGetUnencrypted() throws SQLException {112 final String[] columnNames = {"column1"};113114 final SessionImplementor session = EasyMock.strictMock(SessionImplementor.class);115116 final Blob bOut = EasyMock.strictMock(Blob.class);117 final ResultSet rs = EasyMock.strictMock(ResultSet.class);118119 final byte[] bytes = {' '};120 EasyMock.expect(rs.getBinaryStream(columnNames[0])).andReturn(new ByteArrayInputStream(bytes));121 EasyMock.expect(rs.wasNull()).andReturn(false);122 EasyMock.replay(bOut, session, rs);123 HibernateException ex = null;124 try {125 type.nullSafeGet(rs, columnNames, session, null);126 }127 catch (final HibernateException e) {128 ex = e;129 }130 assertNotNull(ex);131 assertSame(GeneralSecurityException.class, ex.getCause().getClass());132 assertTrue(ex.getCause().getMessage().contains("parameter spec data"));133 EasyMock.verify(bOut, session, rs);134 }135136 @Test137 public void testGetSetBuffered() throws Exception {138 final String[] columnNames = {"column1"};139140 final int maxMemBuffSize = ReflectionUtil.invokeMethod(type, "getMaxInMemoryBuffSize");141 final byte[] buff = new byte[maxMemBuffSize << 1];142 RANDOM.nextBytes(buff);143144 final SessionImplementor session = EasyMock.strictMock(SessionImplementor.class);145 final SessionFactoryImplementor factory = EasyMock.strictMock(SessionFactoryImplementor.class);146 final JdbcServices services = EasyMock.strictMock(JdbcServices.class);147 final LobCreator lobCreator = EasyMock.strictMock(LobCreator.class);148149 final Blob bIn = EasyMock.strictMock(Blob.class);150 final Blob bOut = EasyMock.strictMock(Blob.class);151 final PreparedStatement ps = EasyMock.strictMock(PreparedStatement.class);152 final ResultSet rs = EasyMock.strictMock(ResultSet.class);153154 EasyMock.expect(bIn.getBinaryStream()).andReturn(new ByteArrayInputStream(buff));155 final Capture<BufferedInputStream> encCapt = EasyMock.newCapture();156 ps.setBinaryStream(EasyMock.eq(1), EasyMock.capture(encCapt), EasyMock.anyLong());157 EasyMock.expectLastCall();158 EasyMock.replay(bIn, ps);159 type.nullSafeSet(ps, bIn, 1, null);160 EasyMock.verify(bIn, ps);161 final BufferedInputStream enc = encCapt.getValue();162163 EasyMock.expect(rs.getBinaryStream(columnNames[0])).andReturn(enc);164 EasyMock.expect(rs.wasNull()).andReturn(false);165 EasyMock.expect(session.getFactory()).andReturn(factory);166 EasyMock.expect(factory.getJdbcServices()).andReturn(services);167 EasyMock.expect(services.getLobCreator(session)).andReturn(lobCreator);168 final Capture<BufferedInputStream> decCapt = EasyMock.newCapture();169 EasyMock.expect(lobCreator.createBlob(EasyMock.capture(decCapt), EasyMock.eq((long) buff.length))).andReturn(bOut);170 EasyMock.replay(bOut, lobCreator, services, factory, session, rs);171 type.nullSafeGet(rs, columnNames, session, null);172 EasyMock.verify(bOut, lobCreator, services, factory, session, rs);173 }174175 private class BlobEncryptThread extends EncryptThread {176177 final String[] columnNames = {"column1"};178179 final SessionImplementor session = EasyMock.strictMock(SessionImplementor.class);180 final SessionFactoryImplementor factory = EasyMock.strictMock(SessionFactoryImplementor.class);181 final JdbcServices services = EasyMock.strictMock(JdbcServices.class);182 final LobCreator lobCreator = EasyMock.strictMock(LobCreator.class);183184 final Blob bIn = EasyMock.strictMock(Blob.class);185 final Blob bOut = EasyMock.strictMock(Blob.class);186 final PreparedStatement ps = EasyMock.strictMock(PreparedStatement.class);187 final ResultSet rs = EasyMock.strictMock(ResultSet.class);188189 /**190 * {@inheritDoc}191 */192 @Override193 protected void doIteration() throws Throwable {194 EasyMock.expect(bIn.getBinaryStream()).andReturn(new ByteArrayInputStream(TEST_VALUE));195 final Capture<byte[]> encBytesCapt = EasyMock.newCapture();196 ps.setBytes(EasyMock.eq(1), EasyMock.capture(encBytesCapt));197 EasyMock.expectLastCall();198 EasyMock.replay(bIn, ps);199 type.nullSafeSet(ps, bIn, 1, null);200 EasyMock.verify(bIn, ps);201 final byte[] enc = encBytesCapt.getValue(); ...

Full Screen

Full Screen

Source:EncryptedClobTypeTest.java Github

copy

Full Screen

...68 @Test69 public void testGetSet() throws Exception {70 final String[] columnNames = {"column1"};7172 final SessionImplementor session = EasyMock.strictMock(SessionImplementor.class);73 final SessionFactoryImplementor factory = EasyMock.strictMock(SessionFactoryImplementor.class);74 final JdbcServices services = EasyMock.strictMock(JdbcServices.class);75 final LobCreator lobCreator = EasyMock.strictMock(LobCreator.class);7677 final Clob bIn = EasyMock.strictMock(Clob.class);78 final Clob bOut = EasyMock.strictMock(Clob.class);79 final PreparedStatement ps = EasyMock.strictMock(PreparedStatement.class);80 final ResultSet rs = EasyMock.strictMock(ResultSet.class);8182 EasyMock.expect(bIn.getAsciiStream()).andReturn(new ByteArrayInputStream(TEST_VALUE));83 final Capture<byte[]> encBytesCapt = EasyMock.newCapture();84 ps.setBytes(EasyMock.eq(1), EasyMock.capture(encBytesCapt));85 EasyMock.expectLastCall();86 EasyMock.replay(bIn, ps);87 type.nullSafeSet(ps, bIn, 1, null);88 EasyMock.verify(bIn, ps);89 final byte[] enc = encBytesCapt.getValue();9091 EasyMock.expect(rs.getBinaryStream(columnNames[0])).andReturn(new ByteArrayInputStream(enc));92 EasyMock.expect(rs.wasNull()).andReturn(false);93 EasyMock.expect(session.getFactory()).andReturn(factory);94 EasyMock.expect(factory.getJdbcServices()).andReturn(services);95 EasyMock.expect(services.getLobCreator(session)).andReturn(lobCreator);96 EasyMock.expect(lobCreator.createClob(TEXT_VALUE)).andReturn(bOut);97 EasyMock.replay(bOut, lobCreator, services, factory, session, rs);98 type.nullSafeGet(rs, columnNames, session, null);99 EasyMock.verify(bOut, lobCreator, services, factory, session, rs);100 }101102 private class ClobEncryptThread extends EncryptThread {103104 final String[] columnNames = {"column1"};105106 final SessionImplementor session = EasyMock.strictMock(SessionImplementor.class);107 final SessionFactoryImplementor factory = EasyMock.strictMock(SessionFactoryImplementor.class);108 final JdbcServices services = EasyMock.strictMock(JdbcServices.class);109 final LobCreator lobCreator = EasyMock.strictMock(LobCreator.class);110111 final Clob bIn = EasyMock.strictMock(Clob.class);112 final Clob bOut = EasyMock.strictMock(Clob.class);113 final PreparedStatement ps = EasyMock.strictMock(PreparedStatement.class);114 final ResultSet rs = EasyMock.strictMock(ResultSet.class);115116 /**117 * {@inheritDoc}118 */119 @Override120 protected void doIteration() throws Throwable {121 EasyMock.expect(bIn.getAsciiStream()).andReturn(new ByteArrayInputStream(TEST_VALUE));122 final Capture<byte[]> encBytesCapt = EasyMock.newCapture();123 ps.setBytes(EasyMock.eq(1), EasyMock.capture(encBytesCapt));124 EasyMock.expectLastCall();125 EasyMock.replay(bIn, ps);126 type.nullSafeSet(ps, bIn, 1, null);127 EasyMock.verify(bIn, ps);128 final byte[] enc = encBytesCapt.getValue(); ...

Full Screen

Full Screen

Source:AbstractHerderTest.java Github

copy

Full Screen

...34 String workerId = "workerId";35 String connector = "connector";36 int generation = 5;37 ConnectorTaskId taskId = new ConnectorTaskId(connector, 0);38 ConfigBackingStore configStore = strictMock(ConfigBackingStore.class);39 StatusBackingStore statusStore = strictMock(StatusBackingStore.class);40 AbstractHerder herder = partialMockBuilder(AbstractHerder.class)41 .withConstructor(Worker.class, String.class, StatusBackingStore.class, ConfigBackingStore.class)42 .withArgs(worker, workerId, statusStore, configStore)43 .addMockedMethod("generation")44 .createMock();45 EasyMock.expect(herder.generation()).andStubReturn(generation);46 EasyMock.expect(statusStore.get(connector))47 .andReturn(new ConnectorStatus(connector, AbstractStatus.State.RUNNING, workerId, generation));48 EasyMock.expect(statusStore.getAll(connector))49 .andReturn(Collections.singletonList(50 new TaskStatus(taskId, AbstractStatus.State.UNASSIGNED, workerId, generation)));51 replayAll();52 ConnectorStateInfo state = herder.connectorStatus(connector);53 assertEquals(connector, state.name());54 assertEquals("RUNNING", state.connector().state());55 assertEquals(1, state.tasks().size());56 assertEquals(workerId, state.connector().workerId());57 ConnectorStateInfo.TaskState taskState = state.tasks().get(0);58 assertEquals(0, taskState.id());59 assertEquals("UNASSIGNED", taskState.state());60 assertEquals(workerId, taskState.workerId());61 verifyAll();62 }63 @Test64 public void taskStatus() {65 Worker worker = null;66 ConnectorTaskId taskId = new ConnectorTaskId("connector", 0);67 String workerId = "workerId";68 ConfigBackingStore configStore = strictMock(ConfigBackingStore.class);69 StatusBackingStore statusStore = strictMock(StatusBackingStore.class);70 AbstractHerder herder = partialMockBuilder(AbstractHerder.class)71 .withConstructor(Worker.class, String.class, StatusBackingStore.class, ConfigBackingStore.class)72 .withArgs(worker, workerId, statusStore, configStore)73 .addMockedMethod("generation")74 .createMock();75 EasyMock.expect(herder.generation()).andStubReturn(5);76 final Capture<TaskStatus> statusCapture = EasyMock.newCapture();77 statusStore.putSafe(EasyMock.capture(statusCapture));78 EasyMock.expectLastCall();79 EasyMock.expect(statusStore.get(taskId)).andAnswer(new IAnswer<TaskStatus>() {80 @Override81 public TaskStatus answer() throws Throwable {82 return statusCapture.getValue();83 }...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful