/**
 * Copyright (c) 2011 RedEngine Ltd, http://www.redengine.co.nz. All rights reserved.
 *
 * This program is licensed to you under the Apache License Version 2.0,
 * and you may not use this file except in compliance with the Apache License Version 2.0.
 * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the Apache License Version 2.0 is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
 */
package net.stickycode.coercion;

import java.util.Arrays;

import org.junit.Test;

import static org.fest.assertions.Assertions.assertThat;

public class ArrayCoercionTest {

  @Test
  public void string() {
    ArrayCoercion coercion = coercion();
    CoercionTarget coercionTarget = coercionTarget(String[].class);
    assertThat(coercion.isApplicableTo(coercionTarget)).isTrue();
    assertThat((String[]) coercion.coerce(coercionTarget, "a")).containsOnly("a");
    assertThat((String[]) coercion.coerce(coercionTarget, "a,b,c")).containsOnly("a", "b", "c");
    assertThat((String[]) coercion.coerce(coercionTarget, "abc,cba,k")).containsOnly("abc", "cba", "k");
  }

  @Test
  public void booleans() {
    ArrayCoercion coercion = coercion();
    CoercionTarget coercionTarget = coercionTarget(Boolean[].class);
    assertThat(coercion.isApplicableTo(coercionTarget)).isTrue();
    assertThat((Boolean[]) coercion.coerce(coercionTarget, "true")).containsOnly(true);
    assertThat((Boolean[]) coercion.coerce(coercionTarget, "true,false,true"))
              .containsOnly(true, false, true);
    assertThat((Boolean[]) coercion.coerce(coercionTarget, "true,true,false"))
              .containsOnly(true, true, false);
  }

  @Test
  public void bytes() {
    ArrayCoercion coercion = coercion();
    CoercionTarget coercionTarget = coercionTarget(byte[].class);
    assertThat(coercion.isApplicableTo(coercionTarget)).isTrue();
    assertThat((byte[]) coercion.coerce(coercionTarget, "45")).containsOnly((byte)45);
    assertThat((byte[]) coercion.coerce(coercionTarget, "45,127,-127")).containsOnly((byte)45, (byte)127, (byte)-127);
  }

  @Test
  public void integers() {
    ArrayCoercion coercion = coercion();
    CoercionTarget coercionTarget = coercionTarget(int[].class);
    assertThat(coercion.isApplicableTo(coercionTarget)).isTrue();
    assertThat((int[]) coercion.coerce(coercionTarget, "45")).containsOnly(45);
    assertThat((int[]) coercion.coerce(coercionTarget, "45,127,-127")).containsOnly(45, 127, -127);

  }

  private CoercionTarget coercionTarget(final Class<?> type) {
    return new CoercionTarget() {

      @Override
      public Class<?> getType() {
        return type;
      }
    };
  }

  @SuppressWarnings("unchecked")
  private ArrayCoercion coercion() {
    return new ArrayCoercion(Arrays.asList(
        new StringCoercion(),
        new StringConstructorCoercion()));
  }
}

@@ -2845,103 +2845,17 @@
 ionT
-arget() %7B%0A%0A      @Override%0A      public Class%3C?%3E getType() %7B%0A        return type;%0A      %7D%0A    %7D
+ype(type)
 ;%0A  

Use the CoercionType now rather than an anonymous one, it because obvious that this concrete type is useful in downstream framesworks as well as tests.