// Path: src/test/java/org/killbill/billing/test/helpers/CustomFieldBuilder.java
// public static CustomFieldBuilder copy(CustomFieldBuilder that) {
//     return new CustomFieldBuilder()//
//             .withObjectType(that.objectType)//
//             .withObjectId(that.objectId)//
//             .withFieldName(that.fieldName)//
//             .withFieldValue(that.fieldValue);
// }
// 
// Path: src/test/java/org/killbill/billing/test/helpers/CustomFieldBuilder.java
// @SuppressWarnings("javadoc")
// public class CustomFieldBuilder implements Builder<CustomField> {
// 
//     private UUID objectId;
//     private ObjectType objectType;
//     private String fieldName, fieldValue;
// 
//     @Override
//     public CustomField build() {
//         return ImmutableCustomField.builder()//
//                 .withObjectId(objectId)//
//                 .withObjectType(objectType)//
//                 .withFieldName(fieldName)//
//                 .withFieldValue(fieldValue)//
//                 .build();
//     }
// 
//     public static CustomFieldBuilder copy(CustomFieldBuilder that) {
//         return new CustomFieldBuilder()//
//                 .withObjectType(that.objectType)//
//                 .withObjectId(that.objectId)//
//                 .withFieldName(that.fieldName)//
//                 .withFieldValue(that.fieldValue);
//     }
// 
//     public CustomFieldBuilder withObjectId(UUID objectId) {
//         this.objectId = objectId;
//         return this;
//     }
// 
//     public CustomFieldBuilder withObjectType(ObjectType objectType) {
//         this.objectType = objectType;
//         return this;
//     }
// 
//     public CustomFieldBuilder withFieldName(String fieldName) {
//         this.fieldName = fieldName;
//         return this;
//     }
// 
//     public CustomFieldBuilder withFieldValue(String fieldValue) {
//         this.fieldValue = fieldValue;
//         return this;
//     }
// }


import static com.google.common.collect.Iterators.forArray;
import static com.google.common.collect.Lists.newArrayList;
import static java.util.UUID.randomUUID;
import static org.apache.commons.lang3.StringUtils.contains;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;
import static org.killbill.billing.ErrorCode.UNEXPECTED_ERROR;
import static org.killbill.billing.ObjectType.ACCOUNT;
import static org.killbill.billing.ObjectType.INVOICE;
import static org.killbill.billing.test.helpers.CustomFieldBuilder.copy;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.osgi.service.log.LogService.LOG_ERROR;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import java.util.List;
import java.util.UUID;
import org.killbill.billing.ObjectType;
import org.killbill.billing.test.helpers.CustomFieldBuilder;
import org.killbill.billing.util.api.CustomFieldApiException;
import org.killbill.billing.util.api.CustomFieldUserApi;
import org.killbill.billing.util.callcontext.CallContext;
import org.killbill.billing.util.callcontext.TenantContext;
import org.killbill.billing.util.customfield.CustomField;
import org.killbill.billing.util.entity.Pagination;
import org.killbill.killbill.osgi.libs.killbill.OSGIKillbillLogService;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InOrder;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.collect.Lists;
    private ArgumentCaptor<List<CustomField>> addedFields;
    @Captor
    private ArgumentCaptor<List<CustomField>> removedFields;

    @Mock
    private TenantContext defaultTenant;
    @Mock
    private Pagination<CustomField> pageStart;
    @Mock
    private Pagination<CustomField> pageMiddle;
    @Mock
    private Pagination<CustomField> pageEnd;

    @BeforeClass
    public void init() {
        initMocks(this);
    }

    private void withThreePagesOfSearchResults(TenantContext tenantContext) {
        when(customFieldApi.searchCustomFields(anyString(), eq(0L), eq(PAGE_SIZE), eq(tenantContext)))//
                .thenReturn(pageStart);
        when(customFieldApi.searchCustomFields(anyString(), eq(PAGE_SIZE), eq(PAGE_SIZE), eq(tenantContext)))//
                .thenReturn(pageMiddle);
        when(customFieldApi.searchCustomFields(anyString(), eq(2 * PAGE_SIZE), eq(PAGE_SIZE), eq(tenantContext)))//
                .thenReturn(pageEnd);

        when(pageStart.getNextOffset()).thenReturn(PAGE_SIZE);
        when(pageMiddle.getNextOffset()).thenReturn(2 * PAGE_SIZE);
        when(pageEnd.getNextOffset()).thenReturn(null);

// Path: src/test/java/org/killbill/billing/test/helpers/CustomFieldBuilder.java
// public static CustomFieldBuilder copy(CustomFieldBuilder that) {
//     return new CustomFieldBuilder()//
//             .withObjectType(that.objectType)//
//             .withObjectId(that.objectId)//
//             .withFieldName(that.fieldName)//
//             .withFieldValue(that.fieldValue);
// }
// 
// Path: src/test/java/org/killbill/billing/test/helpers/CustomFieldBuilder.java
// @SuppressWarnings("javadoc")
// public class CustomFieldBuilder implements Builder<CustomField> {
// 
//     private UUID objectId;
//     private ObjectType objectType;
//     private String fieldName, fieldValue;
// 
//     @Override
//     public CustomField build() {
//         return ImmutableCustomField.builder()//
//                 .withObjectId(objectId)//
//                 .withObjectType(objectType)//
//                 .withFieldName(fieldName)//
//                 .withFieldValue(fieldValue)//
//                 .build();
//     }
// 
//     public static CustomFieldBuilder copy(CustomFieldBuilder that) {
//         return new CustomFieldBuilder()//
//                 .withObjectType(that.objectType)//
//                 .withObjectId(that.objectId)//
//                 .withFieldName(that.fieldName)//
//                 .withFieldValue(that.fieldValue);
//     }
// 
//     public CustomFieldBuilder withObjectId(UUID objectId) {
//         this.objectId = objectId;
//         return this;
//     }
// 
//     public CustomFieldBuilder withObjectType(ObjectType objectType) {
//         this.objectType = objectType;
//         return this;
//     }
// 
//     public CustomFieldBuilder withFieldName(String fieldName) {
//         this.fieldName = fieldName;
//         return this;
//     }
// 
//     public CustomFieldBuilder withFieldValue(String fieldValue) {
//         this.fieldValue = fieldValue;
//         return this;
//     }
// }


// Path: src/test/java/org/killbill/billing/plugin/simpletax/config/http/TestCustomFieldService.java
import static com.google.common.collect.Iterators.forArray;
import static com.google.common.collect.Lists.newArrayList;
import static java.util.UUID.randomUUID;
import static org.apache.commons.lang3.StringUtils.contains;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;
import static org.killbill.billing.ErrorCode.UNEXPECTED_ERROR;
import static org.killbill.billing.ObjectType.ACCOUNT;
import static org.killbill.billing.ObjectType.INVOICE;
import static org.killbill.billing.test.helpers.CustomFieldBuilder.copy;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.osgi.service.log.LogService.LOG_ERROR;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import java.util.List;
import java.util.UUID;
import org.killbill.billing.ObjectType;
import org.killbill.billing.test.helpers.CustomFieldBuilder;
import org.killbill.billing.util.api.CustomFieldApiException;
import org.killbill.billing.util.api.CustomFieldUserApi;
import org.killbill.billing.util.callcontext.CallContext;
import org.killbill.billing.util.callcontext.TenantContext;
import org.killbill.billing.util.customfield.CustomField;
import org.killbill.billing.util.entity.Pagination;
import org.killbill.killbill.osgi.libs.killbill.OSGIKillbillLogService;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InOrder;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.collect.Lists;

    private ArgumentCaptor<List<CustomField>> addedFields;
    @Captor
    private ArgumentCaptor<List<CustomField>> removedFields;

    @Mock
    private TenantContext defaultTenant;
    @Mock
    private Pagination<CustomField> pageStart;
    @Mock
    private Pagination<CustomField> pageMiddle;
    @Mock
    private Pagination<CustomField> pageEnd;

    @BeforeClass
    public void init() {
        initMocks(this);
    }

    private void withThreePagesOfSearchResults(TenantContext tenantContext) {
        when(customFieldApi.searchCustomFields(anyString(), eq(0L), eq(PAGE_SIZE), eq(tenantContext)))//
                .thenReturn(pageStart);
        when(customFieldApi.searchCustomFields(anyString(), eq(PAGE_SIZE), eq(PAGE_SIZE), eq(tenantContext)))//
                .thenReturn(pageMiddle);
        when(customFieldApi.searchCustomFields(anyString(), eq(2 * PAGE_SIZE), eq(PAGE_SIZE), eq(tenantContext)))//
                .thenReturn(pageEnd);

        when(pageStart.getNextOffset()).thenReturn(PAGE_SIZE);
        when(pageMiddle.getNextOffset()).thenReturn(2 * PAGE_SIZE);
        when(pageEnd.getNextOffset()).thenReturn(null);

        CustomFieldBuilder builder = new CustomFieldBuilder().withObjectType(ACCOUNT).withFieldName("toto");