MultiPartParamAnnotationHandler extends ParamAnnotationHandler<MultiPartParam> { @Override public void handleInterfaceAnnotation(MultiPartParam annotation, InterfaceConfigBuilder builder) { builder.startMethodsExtraParamConfig() .setType(FORM) .setName(ph(annotation.value())) .setDefaultValue(nullIfUnset(ph(annotation.defaultValue()))) .setMetaDatas(MultiParts.toMetaDatas(nullIfUnset(ph(annotation.contentType())), nullIfUnset(ph(annotation.fileName())))); } MultiPartParamAnnotationHandler(CRestConfig crestConfig); @Override void handleInterfaceAnnotation(MultiPartParam annotation, InterfaceConfigBuilder builder); @Override void handleMethodAnnotation(MultiPartParam annotation, MethodConfigBuilder builder); @Override void handleParameterAnnotation(MultiPartParam annotation, ParamConfigBuilder builder);  }
@Test public void handleInterfaceAnnotationShouldSetParamsTypeAndNameAndDefaultValue() throws Exception { when(mockInterfaceConfigBuilder.startMethodsExtraParamConfig()).thenReturn(mockParamConfigBuilder); when(mockParamConfigBuilder.setType(any(ParamType.class))).thenReturn(mockParamConfigBuilder); when(mockParamConfigBuilder.setName(any(String.class))).thenReturn(mockParamConfigBuilder); when(mockParamConfigBuilder.setDefaultValue(anyString())).thenReturn(mockParamConfigBuilder); when(mockParamConfigBuilder.setMetaDatas(any(Map.class))).thenReturn(mockParamConfigBuilder); when(mockAnnotation.value()).thenReturn("a"); when(mockAnnotation.defaultValue()).thenReturn("b"); when(mockAnnotation.contentType()).thenReturn("c"); when(mockAnnotation.fileName()).thenReturn("d"); toTest.handleInterfaceAnnotation(mockAnnotation, mockInterfaceConfigBuilder); verify(mockInterfaceConfigBuilder).startMethodsExtraParamConfig(); verify(mockParamConfigBuilder).setType(ParamType.FORM); verify(mockParamConfigBuilder).setName("a"); verify(mockParamConfigBuilder).setDefaultValue("b"); verify(mockParamConfigBuilder).setMetaDatas(MultiParts.toMetaDatas("c", "d")); verify(mockAnnotation).value(); verify(mockAnnotation).defaultValue(); verify(mockAnnotation).contentType(); verify(mockAnnotation).fileName(); }
@Test public void handleInterfaceAnnotationShouldSetParamsTypeAndName() throws Exception { when(mockInterfaceConfigBuilder.startMethodsExtraParamConfig()).thenReturn(mockParamConfigBuilder); when(mockParamConfigBuilder.setType(any(ParamType.class))).thenReturn(mockParamConfigBuilder); when(mockParamConfigBuilder.setName(any(String.class))).thenReturn(mockParamConfigBuilder); when(mockParamConfigBuilder.setDefaultValue(anyString())).thenReturn(mockParamConfigBuilder); when(mockParamConfigBuilder.setMetaDatas(any(Map.class))).thenReturn(mockParamConfigBuilder); when(mockAnnotation.value()).thenReturn("a"); when(mockAnnotation.defaultValue()).thenReturn(""); when(mockAnnotation.contentType()).thenReturn(""); when(mockAnnotation.fileName()).thenReturn(""); toTest.handleInterfaceAnnotation(mockAnnotation, mockInterfaceConfigBuilder); verify(mockInterfaceConfigBuilder).startMethodsExtraParamConfig(); verify(mockParamConfigBuilder).setType(ParamType.FORM); verify(mockParamConfigBuilder).setName("a"); verify(mockParamConfigBuilder).setDefaultValue(null); verify(mockParamConfigBuilder).setMetaDatas(MultiParts.toMetaDatas(null,null)); verify(mockAnnotation).value(); verify(mockAnnotation).defaultValue(); verify(mockAnnotation).contentType(); verify(mockAnnotation).fileName(); }
@Test public void handleInterfaceAnnotationShouldMergePlaceholdersAndSetParamsTypeAndNameAndDefaultValue() throws Exception { when(mockInterfaceConfigBuilder.startMethodsExtraParamConfig()).thenReturn(mockParamConfigBuilder); when(mockParamConfigBuilder.setType(any(ParamType.class))).thenReturn(mockParamConfigBuilder); when(mockParamConfigBuilder.setName(any(String.class))).thenReturn(mockParamConfigBuilder); when(mockParamConfigBuilder.setDefaultValue(anyString())).thenReturn(mockParamConfigBuilder); when(mockParamConfigBuilder.setMetaDatas(any(Map.class))).thenReturn(mockParamConfigBuilder); when(mockAnnotation.value()).thenReturn(VAL_WITH_PH + "a"); when(mockAnnotation.defaultValue()).thenReturn(VAL_WITH_PH + "b"); when(mockAnnotation.contentType()).thenReturn(VAL_WITH_PH + "c"); when(mockAnnotation.fileName()).thenReturn(VAL_WITH_PH + "d"); toTest.handleInterfaceAnnotation(mockAnnotation, mockInterfaceConfigBuilder); verify(mockInterfaceConfigBuilder).startMethodsExtraParamConfig(); verify(mockParamConfigBuilder).setType(ParamType.FORM); verify(mockParamConfigBuilder).setName(EXPECTED_MERGE_VAL + "a"); verify(mockParamConfigBuilder).setDefaultValue(EXPECTED_MERGE_VAL + "b"); verify(mockParamConfigBuilder).setMetaDatas(MultiParts.toMetaDatas(EXPECTED_MERGE_VAL + "c", EXPECTED_MERGE_VAL + "d")); verify(mockAnnotation).value(); verify(mockAnnotation).defaultValue(); verify(mockAnnotation).contentType(); verify(mockAnnotation).fileName(); }