@Test
  public void testUniqueValuesArrayGeneration() {
    ArrayElementDescriptor e0 = createArrayElement(0, "int");
    ((SimpleTypeDescriptor) e0.getLocalType(false)).setValues("1,2");

    ArrayElementDescriptor e1 = createArrayElement(1, "int");
    ((SimpleTypeDescriptor) e1.getLocalType(false)).setValues("3,4");

    ArrayTypeDescriptor arrayTypeDescriptor = createArrayType("MyArray");
    arrayTypeDescriptor.addElement(e0);
    arrayTypeDescriptor.addElement(e1);

    InstanceDescriptor arrayInstDescriptor = createInstance("array", arrayTypeDescriptor);
    arrayInstDescriptor.setUnique(true);

    Generator<Object[]> generator =
        (Generator<Object[]>)
            InstanceGeneratorFactory.createSingleInstanceGenerator(
                arrayInstDescriptor, Uniqueness.NONE, context);
    generator.init(context);
    for (int i = 0; i < 4; i++) {
      Object[] product = GeneratorUtil.generateNonNull(generator);
      assertTrue(
          Arrays.equals(INT13, product)
              || Arrays.equals(INT14, product)
              || Arrays.equals(INT23, product)
              || Arrays.equals(INT24, product));
    }
    assertUnavailable(generator);
  }
  /**
   * TODO v0.8 implement array mutation @Test public void testMutatingGeneration() { Object[]
   * MUTATED_ALICE = new Object[] { "Alice", 24 };
   *
   * <p>// define descriptor ArrayTypeDescriptor descriptor = createPersonDescriptor();
   * descriptor.setGenerator(PersonAttrArrayGenerator.class.getName());
   * descriptor.getElement(1).getLocalType(false).setScript("p[1] + 1");
   *
   * <p>// create generator Generator<Object[]> generator =
   * ArrayGeneratorFactory.createArrayGenerator( "p", descriptor, Uniqueness.NONE, context);
   * generator.init(context);
   *
   * <p>// validate for (int i = 0; i < 10; i++) assertEqualArrays(MUTATED_ALICE,
   * GeneratorUtil.generateNonNull(generator)); }
   */
  @Test
  public void testUniqueArrayGeneration() {
    ArrayTypeDescriptor arrayTypeDescriptor = createArrayType("MyArray");

    // create descriptor
    context.set("gen0", new SequenceTestGenerator<Integer>(1, 2));
    ArrayElementDescriptor e0 = createArrayElement(0, "int");
    ((SimpleTypeDescriptor) e0.getLocalType(false)).setGenerator("gen0");
    arrayTypeDescriptor.addElement(e0);

    context.set("gen1", new SequenceTestGenerator<Integer>(3, 4));
    ArrayElementDescriptor e1 = createArrayElement(1, "int");
    ((SimpleTypeDescriptor) e1.getLocalType(false)).setGenerator("gen1");
    arrayTypeDescriptor.addElement(e1);

    InstanceDescriptor arrayInstDescriptor = createInstance("array", arrayTypeDescriptor);
    arrayInstDescriptor.setUnique(true);

    // create generator
    Generator<Object[]> generator =
        (Generator<Object[]>)
            InstanceGeneratorFactory.createSingleInstanceGenerator(
                arrayInstDescriptor, Uniqueness.NONE, context);
    generator.init(context);

    // test generator
    assertArray(INT13, GeneratorUtil.generateNonNull(generator));
    assertArray(INT14, GeneratorUtil.generateNonNull(generator));
    assertArray(INT23, GeneratorUtil.generateNonNull(generator));
    assertArray(INT24, GeneratorUtil.generateNonNull(generator));
    assertUnavailable(generator);
  }
 @SuppressWarnings({"unchecked", "rawtypes"})
 public static GeneratorComponent<?> createGeneratorComponent(
     InstanceDescriptor descriptor, Uniqueness ownerUniqueness, BeneratorContext context) {
   if (descriptor instanceof ComponentDescriptor)
     return ComponentBuilderFactory.createComponentBuilder(
         (ComponentDescriptor) descriptor, ownerUniqueness, context);
   else if (descriptor instanceof VariableDescriptor)
     return new Variable(
         descriptor.getName(),
         VariableGeneratorFactory.createGenerator((VariableDescriptor) descriptor, context),
         descriptor.getTypeDescriptor().getScope());
   else if (descriptor instanceof ArrayElementDescriptor)
     return ComponentBuilderFactory.createComponentBuilder(
         (ArrayElementDescriptor) descriptor, ownerUniqueness, context);
   else
     throw new UnsupportedOperationException(
         "Not a supported generator compnent type: " + descriptor.getClass());
 }