private void validateReturnValue(Returns answer, MethodInfo methodInfo) { if (methodInfo.isVoid()) { reporter.cannotStubVoidMethodWithAReturnValue(methodInfo.getMethodName()); } if (answer.returnsNull() && methodInfo.returnsPrimitive()) { reporter.wrongTypeOfReturnValue(methodInfo.printMethodReturnType(), "null", methodInfo.getMethodName()); } if (!answer.returnsNull() && !methodInfo.isValidReturnType(answer.getReturnType())) { reporter.wrongTypeOfReturnValue(methodInfo.printMethodReturnType(), answer.printReturnType(), methodInfo.getMethodName()); } }
@Override public Object answer(InvocationOnMock invocation) throws Throwable { assertThat(SecurityContextHolder.getContext()).isEqualTo(securityContext); return super.answer(invocation); } });
@Override public void validateFor(InvocationOnMock invocation) { InvocationInfo invocationInfo = new InvocationInfo(invocation); if (invocationInfo.isVoid()) { throw cannotStubVoidMethodWithAReturnValue(invocationInfo.getMethodName()); } if (returnsNull() && invocationInfo.returnsPrimitive()) { throw wrongTypeOfReturnValue(invocationInfo.printMethodReturnType(), "null", invocationInfo.getMethodName()); } if (!returnsNull() && !invocationInfo.isValidReturnType(returnType())) { throw wrongTypeOfReturnValue(invocationInfo.printMethodReturnType(), printReturnType(), invocationInfo.getMethodName()); } }
public Stubber doReturn(Object toBeReturned) { answers.add(new Returns(toBeReturned)); return this; }
private void validateReturnValue(Returns answer, Invocation invocation) { if (invocation.isVoid()) { reporter.cannotStubVoidMethodWithAReturnValue(invocation.getMethod().getName()); } if (answer.returnsNull() && invocation.returnsPrimitive()) { reporter.wrongTypeOfReturnValue(invocation.printMethodReturnType(), "null", invocation.getMethodName()); } if (!answer.returnsNull() && !invocation.isValidReturnType(answer.getReturnType())) { reporter.wrongTypeOfReturnValue(invocation.printMethodReturnType(), answer.printReturnType(), invocation.getMethodName()); } }
@Override public OngoingStubbing<T> thenReturn(T value) { return thenAnswer(new Returns(value)); }
public DeprecatedOngoingStubbing<T> toReturn(T value) { return toAnswer(new Returns(value)); }
public OngoingStubbing<T> thenReturn(T value) { return thenAnswer(new Returns(value)); }
return MOCKITO_CORE.doAnswer(new Returns(toBeReturned));
return POWERMOCKITO_CORE.doAnswer(new Returns(toBeReturned));
public Stubber doReturn(Object toBeReturned) { answers.add(new Returns(toBeReturned)); return this; }
Map<String, String> map = mock(Map.class, new Returns("I don't know that string")); when(map.get("abcd")).thenReturn("defg"); when(map.get("defg")).thenReturn("ghij");
public DeprecatedOngoingStubbing<T> toReturn(T value) { return toAnswer(new Returns(value)); }
public OngoingStubbing<T> thenReturn(T value) { return thenAnswer(new Returns(value)); }
return MOCKITO_CORE.doAnswer(new Returns(toBeReturned));
private DefinitionRawView mockRawView(DefinitionRawView.Property... properties) { return mock(DefinitionRawView.class, new Returns(Arrays.asList(properties))); }
@Test void testRevertPrimitive() { Class<?> type = Boolean.class; EDataType dataType = mock(EDataType.class); when(dataType.getInstanceClass()).thenAnswer(new Returns(type)); EAttribute attribute = mock(EAttribute.class); when(attribute.getEAttributeType()).thenReturn(dataType); assertThat(converter.revert(true, attribute)).isNotNull().isEqualTo(true); }
@Test void testConvertPrimitive() { Class<?> type = Boolean.class; EDataType dataType = mock(EDataType.class); when(dataType.getInstanceClass()).thenAnswer(new Returns(type)); EAttribute attribute = mock(EAttribute.class); when(attribute.getEAttributeType()).thenReturn(dataType); assertThat(converter.convert(true, attribute)).isNotNull().isEqualTo(true); }
SingleProvider() { super(); // Initialize attributes final EDataType eDataType = mock(EDataType.class); when(eDataType.getInstanceClass()).thenAnswer(new Returns(String.class)); when(eDataType.getInstanceClassName()).thenReturn(String.class.getTypeName()); singleAttribute = mock(EAttribute.class); when(singleAttribute.isMany()).thenReturn(false); when(singleAttribute.getEAttributeType()).thenReturn(eDataType); // Initialize references singleReference = mock(EReference.class); when(singleReference.isMany()).thenReturn(false); when(singleReference.isContainment()).thenReturn(false); }