Skip to content

Commit

Permalink
Added InitBinder for VendorFieldValidationController and added UT for it
Browse files Browse the repository at this point in the history
  • Loading branch information
gastontulipani authored and naponce committed Jun 10, 2019
1 parent 1f334ec commit 27563ab
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.springframework.web.bind.annotation.RestController;

import com.appdirect.sdk.vendorFields.converter.FlowTypeConverter;
import com.appdirect.sdk.vendorFields.converter.LocaleConverter;
import com.appdirect.sdk.vendorFields.converter.OperationTypeConverter;
import com.appdirect.sdk.vendorFields.handler.VendorFieldValidationHandler;
import com.appdirect.sdk.vendorFields.model.FlowType;
Expand All @@ -44,6 +45,7 @@ public class VendorFieldValidationController {
public Callable<VendorFieldsValidationResponse> validateFields(
@RequestBody VendorFieldsValidationRequest vendorFieldsValidationRequest,
@RequestHeader(value = "Accept-Language") List<Locale> locales) {

log.info(
"Calling validate fields API with editionCode={}, flowType={}, operationType={}, partner={}, applicationIdentifier={}, locales={}",
vendorFieldsValidationRequest.getEditionCode(),
Expand All @@ -62,5 +64,6 @@ public Callable<VendorFieldsValidationResponse> validateFields(
public void initBinder(final WebDataBinder webdataBinder) {
webdataBinder.registerCustomEditor(FlowType.class, new FlowTypeConverter());
webdataBinder.registerCustomEditor(OperationType.class, new OperationTypeConverter());
webdataBinder.registerCustomEditor(List.class, new LocaleConverter());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.appdirect.sdk.vendorFields.controller;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.Collections;
Expand All @@ -13,7 +17,11 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.web.bind.WebDataBinder;

import com.appdirect.sdk.vendorFields.converter.FlowTypeConverter;
import com.appdirect.sdk.vendorFields.converter.LocaleConverter;
import com.appdirect.sdk.vendorFields.converter.OperationTypeConverter;
import com.appdirect.sdk.vendorFields.handler.VendorFieldValidationHandler;
import com.appdirect.sdk.vendorFields.model.FlowType;
import com.appdirect.sdk.vendorFields.model.OperationType;
Expand All @@ -26,6 +34,8 @@
public class VendorFieldValidationControllerTest {
@Mock
private VendorFieldValidationHandler mockVendorFieldValidationHandler;
@Mock
private WebDataBinder webdataBinder;

private VendorFieldValidationController vendorFieldValidationController;

Expand Down Expand Up @@ -61,5 +71,14 @@ public void testValidateFields_whenCalled_thenControllerForwardsItsArgumentsToTh
//Then
assertThat(controllerResponse).isEqualTo(response);
}

@Test
public void testInitBinder() {
vendorFieldValidationController.initBinder(webdataBinder);

verify(webdataBinder, times(1)).registerCustomEditor(eq(FlowType.class), any(FlowTypeConverter.class));
verify(webdataBinder, times(1)).registerCustomEditor(eq(OperationType.class), any(OperationTypeConverter.class));
verify(webdataBinder, times(1)).registerCustomEditor(eq(List.class), any(LocaleConverter.class));
}
}

0 comments on commit 27563ab

Please sign in to comment.