org.easymock.MockType Java Examples
The following examples show how to use
org.easymock.MockType.
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: EasyMockStrictMockExample.java From journaldev with MIT License | 6 votes |
@Test public void test() { ArrayList<Integer> mockList = mock(MockType.STRICT, ArrayList.class); expect(mockList.add(10)).andReturn(true); expect(mockList.add(20)).andReturn(true); expect(mockList.size()).andReturn(2); expect(mockList.get(0)).andReturn(10); replay(mockList); mockList.add(10); mockList.add(20); assertEquals(mockList.size(), 2); assertTrue(mockList.get(0) == 10); verify(mockList); }
Example #2
Source File: EasyMockNiceMockExample.java From journaldev with MIT License | 6 votes |
@Test public void test() { ArrayList<Integer> mockList = mock(MockType.NICE, ArrayList.class); expect(mockList.add(10)).andReturn(true); expect(mockList.size()).andReturn(2); expect(mockList.get(0)).andReturn(10); replay(mockList); mockList.add(10); // below will NOT throw exception because of nice mocking boolean b = mockList.add(30); assertFalse(b); assertEquals(mockList.size(), 2); assertTrue(mockList.get(0) == 10); //verify won't throw error for unexpected calls for nice mock verify(mockList); }
Example #3
Source File: DataSourceTypeTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void inputStreamShouldBeClosedOnHappyPath() throws Exception { DataSource ds = mock(MockType.STRICT, DataSource.class); InputStream is = mock(MockType.STRICT, InputStream.class); expect(ds.getInputStream()).andReturn(is); replay(ds); expect(is.available()).andReturn(1); expect(is.read(anyObject(byte[].class))).andReturn(-1); is.close(); replay(is); DataSourceType dst = new DataSourceType(false, null); dst.getBytes(ds); verify(ds); verify(is); }
Example #4
Source File: DataSourceTypeTest.java From cxf with Apache License 2.0 | 6 votes |
@Test(expected = RuntimeException.class) public void inputStreamShouldBeClosedOnReadingException() throws Exception { DataSource ds = mock(MockType.STRICT, DataSource.class); InputStream is = mock(MockType.STRICT, InputStream.class); expect(ds.getInputStream()).andReturn(is); replay(ds); expect(is.available()).andThrow(new IOException()); is.close(); replay(is); DataSourceType dst = new DataSourceType(false, null); try { dst.getBytes(ds); } finally { verify(ds); verify(is); } }
Example #5
Source File: MockModule.java From arcusplatform with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public <T> MockModule addMockService(Key<T> key, Class<? extends T> value) { this.services.put((Key<Object>) key, EasyMock.createMock(MockType.DEFAULT, value)); return this; }