private MockeryMetadata mockeryMetadata(Class<?> mockingClass, Method method, Object[] args, Type type, Annotation[] annotations) { List<MockeryMetadata> mockeriesMetadata = new ArrayList<>(); for (Annotation annotation : annotations) { Mockery mockeryAnnotation = annotation.annotationType() .getAnnotation(Mockery.class); if (mockeryAnnotation == null) continue; Metadata metadata = new Metadata<>(mockingClass, method, args, annotation, type); Mockery.Behaviour mockery = instantiateInterface.from(mockeryAnnotation.value()); mockeriesMetadata.add(new MockeryMetadata(metadata, mockery)); } if (mockeriesMetadata.isEmpty()) return null; if (mockeriesMetadata.size() > 1) { String message = Messages .multipleMockeryOnMethodOrParam(mockingClass, method); throw new IllegalArgumentException(message); } return mockeriesMetadata.get(0); }
@Test public void When_Get_Mockery_Metadata_From_Method_With_Multiple_Mockery_Get_Exception() throws NoSuchMethodException { Method method = Providers.class.getMethod("multipleMockeryMethod"); Type type = method.getGenericReturnType(); try { getMockeryMetadata.fromMethod(Providers.class, method, type, null); fail(); } catch (RuntimeException e) { String expectedMessage = Messages .multipleMockeryOnMethodOrParam(Providers.class, method); assertThat(expectedMessage, is(e.getMessage())); } }
@Test public void When_Get_Mockery_Metadata_From_Param_With_Multiple_Mockery_Get_Exception() throws NoSuchMethodException { Method method = Providers.class.getMethod("mockeryParams", String.class, String.class, String.class); try { getMockeryMetadata.fromParam(Providers.class, method, null, 1); fail(); } catch (RuntimeException e) { String expectedMessage = Messages .multipleMockeryOnMethodOrParam(Providers.class, method); assertThat(expectedMessage, is(e.getMessage())); } }