public void testSpecifyingAnyValueOfPrimitiveType() { context.checking(new Expectations() {{ allowing (mock).doSomethingWithBoth(with.booleanIs(any(boolean.class)), with.booleanIs(any(boolean.class))); }}); mock.doSomethingWithBoth(true, true); mock.doSomethingWithBoth(true, false); mock.doSomethingWithBoth(false, true); mock.doSomethingWithBoth(false, false); } }
public void ridiculousJavaTypeName() { @SuppressWarnings("unused") final List<List<Set<String>>> silly = Collections.emptyList(); context.checking(new Expectations() {{ oneOf (mock).beSilly(with.<List<List<Set<String>>>>is(empty())); }}); } }
@Test public void canSetExpectationsWithMatchersForMethodsWithArgumentsOfPrimitiveTypes() { context.checking(new Expectations() {{ exactly(1).of (mock).withBoolean(with.booleanIs(equal(true))); exactly(1).of (mock).withByte(with.byteIs(equal((byte)10))); exactly(1).of (mock).withShort(with.shortIs(equal((short) 10))); exactly(1).of (mock).withInt(with.intIs(equal(10))); exactly(1).of (mock).withLong(with.longIs(equal(10L))); exactly(1).of (mock).withFloat(with.floatIs(equal(10.0f))); exactly(1).of (mock).withDouble(with.doubleIs(equal(10.0))); }}); mock.withBoolean(true); mock.withByte((byte)10); mock.withShort((short)10); mock.withInt(10); mock.withLong(10L); mock.withFloat(10.0f); mock.withDouble(10.0); context.assertIsSatisfied(); }
/** * Will fail unless ExpectationsCreator has added generic overloaded byte code */ @Test public void testNonNullNativeIgnoringDocumentationParameterMatcher() { context.checking(new Expectations() {{ exactly(1).of(mock).withBoolean(with.booleanIs(anything())); exactly(1).of(mock).withByte(with.byteIs(anything())); exactly(1).of(mock).withShort(with.shortIs(anything())); exactly(1).of(mock).withInt(with.intIs(anything())); exactly(1).of(mock).withLong(with.longIs(anything())); exactly(1).of(mock).withFloat(with.floatIs(anything())); exactly(1).of(mock).withDouble(with.doubleIs(anything())); }}); mock.withBoolean(true); mock.withByte((byte)10); mock.withShort((short)10); mock.withInt(10); mock.withLong(10L); mock.withFloat(10.0f); mock.withDouble(10.0); context.assertIsSatisfied(); } }
public void testCanPassLiteralPrimitiveValuesToWithMethodToMeanEqualTo() { context.checking(new Expectations() {{ exactly(2).of (mock).doSomethingWithBoth(with.booleanIs(anything()), with(true)); exactly(2).of (mock).doSomethingWithBoth(with.byteIs(anything()), with((byte)1)); exactly(2).of (mock).doSomethingWithBoth(with.shortIs(anything()), with((short)2)); exactly(2).of (mock).doSomethingWithBoth(with.charIs(anything()), with('x')); exactly(2).of (mock).doSomethingWithBoth(with.intIs(anything()), with(3)); exactly(2).of (mock).doSomethingWithBoth(with.longIs(anything()), with(4L)); exactly(2).of (mock).doSomethingWithBoth(with.floatIs(anything()), with(5.0f)); exactly(2).of (mock).doSomethingWithBoth(with.doubleIs(anything()), with(6.0)); }});
public void testAllOrNoneOfTheParametersMustBeSpecifiedByMatchers() { try { context.checking(new Expectations() {{ oneOf (mock).doSomethingWithBoth(with.<String>is(equal("a-matcher")), "not-a-matcher"); }}); } catch (IllegalArgumentException expected) { } }
public void testCanPassLiteralPrimitiveValuesToWithMethodToMeanEqualTo() { context.checking(new Expectations() {{ exactly(2).of (mock).doSomethingWithBoth(with.booleanIs(any(boolean.class)), with(true)); exactly(2).of (mock).doSomethingWithBoth(with.byteIs(any(byte.class)), with((byte)1)); exactly(2).of (mock).doSomethingWithBoth(with.shortIs(any(short.class)), with((short)2)); exactly(2).of (mock).doSomethingWithBoth(with.charIs(any(char.class)), with('x')); exactly(2).of (mock).doSomethingWithBoth(with.intIs(any(int.class)), with(3)); exactly(2).of (mock).doSomethingWithBoth(with.longIs(any(long.class)), with(4L)); exactly(2).of (mock).doSomethingWithBoth(with.floatIs(any(float.class)), with(5.0f)); exactly(2).of (mock).doSomethingWithBoth(with.doubleIs(any(double.class)), with(6.0)); }});
public void testMatchesParameterValues() { context.checking(new Expectations() {{ oneOf (mock).doSomethingWith(with.<String>is(equal("hello"))); oneOf (mock).doSomethingWith(with.<String>is(equal("goodbye"))); }}); mock.doSomethingWith("hello"); mock.doSomethingWith("goodbye"); context.assertIsSatisfied(); }
public void testDoesNotAllowUnexpectedParameterValues() { context.checking(new Expectations() {{ oneOf (mock).doSomethingWith(with.<String>is(equal("hello"))); oneOf (mock).doSomethingWith(with.<String>is(equal("goodbye"))); }}); try { mock.doSomethingWith("hello"); mock.doSomethingWith("Goodbye"); fail("should have thrown ExpectationError"); } catch (ExpectationError expected) {} }
public void testNotAllExpectationsOfSameMockMustUseMatchers() { context.checking(new Expectations() {{ oneOf (mock).doSomethingWithBoth(with.<String>is(equal("x")), with.<String>is(equal("y"))); oneOf (mock).doSomethingWith("z"); }}); mock.doSomethingWithBoth("x", "y"); mock.doSomethingWith("z"); context.assertIsSatisfied(); }
public void testCanPassLiteralValuesToWithMethodToMeanEqualTo() { context.checking(new Expectations() {{ exactly(2).of (mock).doSomethingWithBoth(with.<String>is(anything()), with("y")); }}); mock.doSomethingWithBoth("x", "y"); mock.doSomethingWithBoth("z", "y"); context.assertIsSatisfied(); }