package org.simpleframework.xml.core;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import junit.framework.TestCase;

import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;

public class SpecificationTest extends TestCase {
   
   @Root
   private static class SimpleClass {
      
      @Element(name="name")
      private final String name;
      
      @Element(name="value")
      private final int value;
      
      public SimpleClass() {
         this("default");
      }
      
      public SimpleClass(@Element(name="name") String name) {
         this(name, 2);
      }
      
      public SimpleClass(@Element(name="name") String name, @Element(name="value") int value) {
         this.name = name;
         this.value = value;
      }
      
      public String getName() {
         return name;
      }
      
      public int getValue() {
         return value;
      }
      
      public boolean equals(Object other) {
         if(other instanceof SimpleClass) {
            SimpleClass otherClass = (SimpleClass)other;
            return otherClass.name.equals(name) && otherClass.value == value;
         }
         return false;
      }
   }
   
   public void testSpecification() throws Exception {
      ConstructorScanner scanner = new ConstructorScanner(SimpleClass.class);
      Specification spec = scanner.getSpecification();
      
      assertTrue(spec.isDefault());
      assertEquals(spec.getBuilder(toSet("name")).getParameter("name").getType(), String.class);
      assertEquals(spec.getBuilder(toSet("name")).getParameter("name").getIndex(), 0);
      assertEquals(spec.getBuilder(toSet("name")).getParameter("name").getName(), "name");
      assertEquals(spec.getBuilder(toSet("name", "value")).getParameter("name").getType(), String.class);
      assertEquals(spec.getBuilder(toSet("name", "value")).getParameter("name").getIndex(), 0);
      assertEquals(spec.getBuilder(toSet("name", "value")).getParameter("name").getName(), "name");
      assertEquals(spec.getBuilder(toSet("name", "value")).getParameter("value").getType(), int.class);
      assertEquals(spec.getBuilder(toSet("name", "value")).getParameter("value").getIndex(), 1);
      assertEquals(spec.getBuilder(toSet("name", "value")).getParameter("value").getName(), "value");
      assertEquals(spec.getBuilder(Collections.EMPTY_SET).build(Collections.EMPTY_LIST).getClass(), SimpleClass.class);
      assertEquals(spec.getDefault().getClass(), SimpleClass.class);
      assertEquals(spec.getBuilder(Collections.EMPTY_SET).build(Collections.EMPTY_LIST), spec.getDefault());
   }
   
   public Set<String> toSet(String... list) {
      Set<String> set = new HashSet<String>();
      
      for(String value : list) {
         set.add(value);
      }
      return set;
   }

}

@@ -49,27 +49,25 @@
 va.util.
-Collections
+ArrayList
 ;%0Aimport
@@ -86,16 +86,39 @@
 ashSet;%0A
+import java.util.List;%0A
 import j
@@ -2385,59 +2385,31 @@
 der(
-Collections.EMPTY_SET).build(Collections.EMPTY_LIST
+toSet()).build(toList()
 ).ge
@@ -2546,80 +2546,625 @@
 der(
-Collections.EMPTY_SET).build(Collections.EMPTY_LIST), spec.getDefault())
+toSet()).build(toList()), spec.getDefault());%0A      %0A      SimpleClass instance = (SimpleClass)spec.getDefault();%0A      %0A      assertEquals(instance.getName(), %22default%22);%0A      assertEquals(instance.getValue(), 2);%0A      %0A      SimpleClass other = (SimpleClass)spec.getBuilder(toSet(%22name%22, %22value%22)).build(toList(%22test%22, 1));%0A      %0A      assertEquals(other.getName(), %22test%22);%0A      assertEquals(other.getValue(), 1);%0A   %7D%0A   %0A   public List%3CObject%3E toList(Object... list) %7B%0A      List%3CObject%3E arr = new ArrayList%3CObject%3E();%0A      %0A      for(Object value : list) %7B%0A         arr.add(value);%0A      %7D%0A      return arr
 ;%0A  

Update the test