|
EasyMock example source code file (UsageExpectAndThrowTest.java)
The EasyMock UsageExpectAndThrowTest.java source code/* * Copyright (c) 2001-2007 OFFIS, Tammo Freese. * This program is made available under the terms of the MIT License. */ package org.easymock.tests; import static org.junit.Assert.*; import org.easymock.MockControl; import org.junit.Before; import org.junit.Test; public class UsageExpectAndThrowTest { private MockControl<IMethods> control; private IMethods mock; private static RuntimeException EXCEPTION = new RuntimeException(); @Before public void setup() { control = MockControl.createControl(IMethods.class); mock = control.getMock(); } @Test public void booleanType() { control.expectAndThrow(mock.booleanReturningMethod(4), EXCEPTION); control.replay(); try { mock.booleanReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); } @Test public void longType() { control.expectAndThrow(mock.longReturningMethod(4), EXCEPTION); control.replay(); try { mock.longReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); } @Test public void floatType() { control.expectAndThrow(mock.floatReturningMethod(4), EXCEPTION); control.replay(); try { mock.floatReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); } @Test public void doubleType() { control.expectAndThrow(mock.doubleReturningMethod(4), EXCEPTION); control.replay(); try { mock.doubleReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); } @Test public void object() { control.expectAndThrow(mock.objectReturningMethod(4), EXCEPTION); control.replay(); try { mock.objectReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); } @Test public void booleanAndRange() { control.expectAndThrow(mock.booleanReturningMethod(4), EXCEPTION, MockControl.ONE); control.replay(); try { mock.booleanReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); } @Test public void longAndRange() { control.expectAndThrow(mock.longReturningMethod(4), EXCEPTION, MockControl.ONE); control.replay(); try { mock.longReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); } @Test public void floatAndRange() { control.expectAndThrow(mock.floatReturningMethod(4), EXCEPTION, MockControl.ONE); control.replay(); try { mock.floatReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); } @Test public void doubleAndRange() { control.expectAndThrow(mock.doubleReturningMethod(4), EXCEPTION, MockControl.ONE); control.replay(); try { mock.doubleReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); } @Test public void objectAndRange() { control.expectAndThrow(mock.objectReturningMethod(4), EXCEPTION, MockControl.ONE); control.replay(); try { mock.objectReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); } @Test public void booleanAndCount() { control.expectAndThrow(mock.booleanReturningMethod(4), EXCEPTION, 2); control.replay(); try { mock.booleanReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } try { mock.booleanReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); } @Test public void longAndCount() { control.expectAndThrow(mock.longReturningMethod(4), EXCEPTION, 2); control.replay(); try { mock.longReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } try { mock.longReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); } @Test public void floatAndCount() { control.expectAndThrow(mock.floatReturningMethod(4), EXCEPTION, 2); control.replay(); try { mock.floatReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } try { mock.floatReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); } @Test public void doubleAndCount() { control.expectAndThrow(mock.doubleReturningMethod(4), EXCEPTION, 2); control.replay(); try { mock.doubleReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } try { mock.doubleReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); } @Test public void objectAndCount() { control.expectAndThrow(mock.objectReturningMethod(4), EXCEPTION, 2); control.replay(); try { mock.objectReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } try { mock.objectReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); } @Test public void booleanAndMinMax() { control.expectAndThrow(mock.booleanReturningMethod(4), EXCEPTION, 2, 3); control.replay(); try { mock.booleanReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } try { mock.booleanReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); try { mock.booleanReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); } @Test public void longAndMinMax() { control.expectAndThrow(mock.longReturningMethod(4), EXCEPTION, 2, 3); control.replay(); try { mock.longReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } try { mock.longReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); try { mock.longReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); } @Test public void floatAndMinMax() { control.expectAndThrow(mock.floatReturningMethod(4), EXCEPTION, 2, 3); control.replay(); try { mock.floatReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } try { mock.floatReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); try { mock.floatReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); } @Test public void doubleAndMinMax() { control.expectAndThrow(mock.doubleReturningMethod(4), EXCEPTION, 2, 3); control.replay(); try { mock.doubleReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } try { mock.doubleReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); try { mock.doubleReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); } @Test public void objectAndMinMax() { control.expectAndThrow(mock.objectReturningMethod(4), EXCEPTION, 2, 3); control.replay(); try { mock.objectReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } try { mock.objectReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); try { mock.objectReturningMethod(4); fail(); } catch (RuntimeException exception) { assertSame(EXCEPTION, exception); } control.verify(); } } Other EasyMock examples (source code examples)Here is a short list of links related to this EasyMock UsageExpectAndThrowTest.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.