@Override
 protected void setup(TestContainer container) {
   container.enableInterfaceMocking(true);
   dsMock = mock(DataService.class);
   when(dsMock.getCurrentUser()).thenReturn(givenUser());
   localizerMock = mock(LocalizerServiceLocal.class);
   when(localizerMock.getLocalizedTextFromDatabase(
           Mockito.anyString(), Mockito.anyLong(), Mockito.any(LocalizedObjectTypes.class)))
       .thenReturn(LOCALIZED_RESOURCE);
   logCollector.localizer = localizerMock;
 }
 @Before
 public void setup() throws Exception {
   dsMock = mock(DataService.class);
   Organization org = new Organization();
   org.setOrganizationId(ORGANIZATIONID);
   PlatformUser user = new PlatformUser();
   user.setUserId(USERID_1);
   user.setLocale("en");
   user.setOrganization(org);
   when(dsMock.getCurrentUser()).thenReturn(user);
   marketplace = new Marketplace();
   marketplace.setKey(1000l);
   doReturn(marketplace).when(dsMock).getReferenceByBusinessKey(any(Marketplace.class));
 }
  @Before
  public void setup() throws Exception {
    ds = mock(DataService.class);

    pt = new PaymentType();
    pt.setPaymentTypeId(PaymentType.INVOICE);
    pt.setKey(12345);

    Organization op = new Organization();
    op.setOrganizationId(OrganizationRoleType.PLATFORM_OPERATOR.name());

    supplier = new Organization();
    supplier.setOrganizationId("supplier");
    Organizations.grantOrganizationRole(supplier, OrganizationRoleType.SUPPLIER);

    reseller = new Organization();
    reseller.setOrganizationId("reseller");
    Organizations.grantOrganizationRole(reseller, OrganizationRoleType.RESELLER);

    OrganizationReference ref =
        OrganizationReferences.addReference(
            op, supplier, OrganizationReferenceType.PLATFORM_OPERATOR_TO_SUPPLIER);
    OrganizationReferences.enablePayment(ref, pt)
        .setOrganizationRole(new OrganizationRole(OrganizationRoleType.SUPPLIER));

    ref =
        OrganizationReferences.addReference(
            op, reseller, OrganizationReferenceType.PLATFORM_OPERATOR_TO_RESELLER);
    OrganizationReferences.enablePayment(ref, pt)
        .setOrganizationRole(new OrganizationRole(OrganizationRoleType.RESELLER));

    customer = new Organization();
    customer.setOrganizationId("customer");

    noCustomer = new Organization();
    noCustomer.setOrganizationId("noCustomer");

    ref =
        OrganizationReferences.addReference(
            supplier, customer, OrganizationReferenceType.SUPPLIER_TO_CUSTOMER);
    OrganizationReferences.enablePayment(ref, pt);

    ref =
        OrganizationReferences.addReference(
            reseller, customer, OrganizationReferenceType.RESELLER_TO_CUSTOMER);
    OrganizationReferences.enablePayment(ref, pt);

    product = new Product();
    product.setKey(9876);
    product.setVendor(supplier);
    product.setType(ServiceType.TEMPLATE);
    product.setPaymentTypes(Arrays.asList(new ProductToPaymentType(product, pt)));

    pcf = new PaymentConfigurationFilter(ds);

    user = new PlatformUser();
    user.setOrganization(supplier);

    when(ds.getCurrentUser()).thenReturn(user);
    when(ds.getReference(eq(Product.class), eq(product.getKey()))).thenReturn(product);
    when(ds.getReference(eq(Product.class), eq(PROD_NOT_FOUND_KEY)))
        .thenThrow(new ObjectNotFoundException(ClassEnum.SERVICE, "product"));

    when(ds.getReferenceByBusinessKey(any(DomainObject.class)))
        .thenAnswer(
            new Answer<DomainObject<?>>() {

              public DomainObject<?> answer(InvocationOnMock invocation) throws Throwable {
                Object object = invocation.getArguments()[0];
                if (object instanceof Organization) {
                  Organization o = (Organization) object;
                  if (customer.getOrganizationId().equals(o.getOrganizationId())) {
                    return customer;
                  }
                  if (noCustomer.getOrganizationId().equals(o.getOrganizationId())) {
                    return noCustomer;
                  }
                  throw new ObjectNotFoundException(ClassEnum.ORGANIZATION, o.getOrganizationId());
                }
                throw new ObjectNotFoundException(
                    ClassEnum.ORGANIZATION, object.getClass().getName());
              }
            });
  }