/**
 * Copyright (c) 2010 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.configured;

import java.lang.reflect.Field;

import org.junit.Test;


public class ConfigurationSystemTest {
  @SuppressWarnings("unused")
  private static class OneField {
    private String noDefault;
    private String defaulted = "blah";
  }

  @Test
  public void noDefault() throws SecurityException, NoSuchFieldException {
    ConfigurationSystem s = new ConfigurationSystem();
    s.add(new ConfigurationSource() {

      @Override
      public boolean hasValue(String key) {
        return true;
      }

      @Override
      public String getValue(String key) {
        return key;
      }
    });
    Field field = OneField.class.getDeclaredField("noDefault");
    OneField target = new OneField();
    s.registerField(target, field);
    s.configure();
  }

  @Test(expected=ConfigurationValueNotFoundForKeyException.class)
  public void noValue() throws SecurityException, NoSuchFieldException {
    ConfigurationSystem s = new ConfigurationSystem();
    Field field = OneField.class.getDeclaredField("noDefault");
    OneField target = new OneField();
    s.registerField(target, field);
    s.configure();
  }

}

@@ -979,16 +979,49 @@
 %22blah%22;%0A
+    private OneField noCoercion;%0A
   %7D%0A%0A  @
@@ -1897,10 +1897,361 @@
 );%0A  %7D%0A%0A
+  @Test(expected=CoercionNotFoundForTypeException.class)%0A  public void noCoercion() throws SecurityException, NoSuchFieldException %7B%0A    ConfigurationSystem s = new ConfigurationSystem();%0A    Field field = OneField.class.getDeclaredField(%22noCoercion%22);%0A    OneField target = new OneField();%0A    s.registerField(target, field);%0A    s.configure();%0A  %7D%0A%0A
 %7D%0A

Verify that not having a coercion throws a decent error