|
EasyMock example source code file (NameTest.java)
The EasyMock NameTest.java source codepackage org.easymock.tests2; import org.easymock.IMocksControl; import org.easymock.tests.IMethods; import org.junit.Test; import static org.easymock.EasyMock.*; import static org.junit.Assert.*; public class NameTest { @Test public void nameForMock() { IMethods mock = createMock("mock", IMethods.class); mock.simpleMethod(); replay(mock); try { verify(mock); } catch (AssertionError expected) { String actualMessage = expected.getMessage(); String expectedMessage = "\n Expectation failure on verify:\n mock.simpleMethod(): expected: 1, actual: 0"; assertEquals(expectedMessage, actualMessage); } } @Test public void nameForStrictMock() { IMethods mock = createStrictMock("mock", IMethods.class); mock.simpleMethod(); replay(mock); try { verify(mock); } catch (AssertionError expected) { String actualMessage = expected.getMessage(); String expectedMessage = "\n Expectation failure on verify:\n mock.simpleMethod(): expected: 1, actual: 0"; assertEquals(expectedMessage, actualMessage); } } @Test public void nameForNiceMock() { IMethods mock = createNiceMock("mock", IMethods.class); mock.simpleMethod(); replay(mock); try { verify(mock); } catch (AssertionError expected) { String actualMessage = expected.getMessage(); String expectedMessage = "\n Expectation failure on verify:\n mock.simpleMethod(): expected: 1, actual: 0"; assertEquals(expectedMessage, actualMessage); } } @Test public void nameForMocksControl() { IMocksControl control = createControl(); IMethods mock = control.createMock("mock", IMethods.class); mock.simpleMethod(); replay(mock); try { verify(mock); } catch (AssertionError expected) { String actualMessage = expected.getMessage(); String expectedMessage = "\n Expectation failure on verify:\n mock.simpleMethod(): expected: 1, actual: 0"; assertEquals(expectedMessage, actualMessage); } } @Test public void shouldThrowIllegalArgumentExceptionIfNameIsNoValidJavaIdentifier() { try { createMock("no-valid-java-identifier", IMethods.class); throw new AssertionError(); } catch (IllegalArgumentException expected) { assertEquals("'no-valid-java-identifier' is not a valid Java identifier.", expected.getMessage()); } } } Other EasyMock examples (source code examples)Here is a short list of links related to this EasyMock NameTest.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.