/** Testing Preparer with empty constraint. Expect: nothing changes. */
 @Test
 public void testPreparerWithEmptyConstraint() throws InterceptorException {
   final AttributeConstraintModel constraint = new AttributeConstraintModel();
   preparer.onPrepare(constraint, null);
   assertNull(constraint.getTarget());
   assertNull(constraint.getType());
   assertNull(constraint.getAnnotation());
   assertNull(constraint.getQualifier());
 }
  /** creating some dummy data. */
  @Before
  public void init() {
    modelService = createMock(ModelService.class);

    preparer = new AttributeConstraintPreparer();
    preparer.setModelService(modelService);
    attrValidator = new AttributeConstraintValidator();
    attrValidator.setModelService(modelService);

    typeValidator = new TypeConstraintValidator();
    typeValidator.setModelService(modelService);

    prodModCT = new ComposedTypeModel();
    prodModCT.setJaloclass(Product.class);
    prodModCT.setCode("Product");

    prodModCodeAD = new AttributeDescriptorModel();
    prodModCodeAD.setQualifier("code");
    prodModCodeAD.setEnclosingType(prodModCT);
  }
  /**
   * Testing preparer, descriptor is set, other attributes filled with dummy data. Expect:
   * descriptor overwrites all other fields.
   */
  @Test
  public void testPreparerWithAttributeDescriptorOnly() throws InterceptorException {
    final AttributeConstraintModel constraint = new AttributeConstraintModel();
    constraint.setDescriptor(prodModCodeAD);
    constraint.setAnnotation(Min.class);
    constraint.setType(new ComposedTypeModel());
    constraint.setTarget(LanguageModel.class);
    constraint.setQualifier("xxx");

    final ProductModel productModel = new ProductModel();
    expect(modelService.create(prodModCT.getCode())).andReturn(productModel);
    modelService.detach(productModel);
    expectLastCall();

    replay(modelService);
    preparer.onPrepare(constraint, null);
    verify(modelService);

    assertEquals(ProductModel.class, constraint.getTarget());
    assertEquals(prodModCT, constraint.getType());
    assertEquals(Min.class, constraint.getAnnotation());
    assertEquals("code", constraint.getQualifier());
  }