/*
* Copyright 2005-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package org.strecks.injection.annotation;
import org.strecks.injection.handler.impl.TestAction;
import org.strecks.injection.internal.InjectionSetter;
import org.testng.annotations.Test;
/**
* @author Phil Zoio
*/
public class TestInjectionSetter
{
@Test
public void testInjectionSetter()
{
InjectionSetter setter = new InjectionSetter(TestAction.class, "setIntegerInput", "integerInput", Integer.class);
TestAction action = new TestAction();
setter.setInput(action, new Integer(1));
assert action.getIntegerInput().equals(1);
}
@Test
public void testPrimitives()
{
TestAction action = new TestAction();
InjectionSetter setter = new InjectionSetter(TestAction.class, "setByteInput", "byteInput", Byte.TYPE);
setter.setInput(action, null);
assert action.getByteInput() == 0;
setter.setInput(action, Byte.valueOf((byte) 1));
assert action.getByteInput() == 1;
setter = new InjectionSetter(TestAction.class, "setBooleanInput", "booleanInput", Boolean.TYPE);
setter.setInput(action, null);
assert action.isBooleanInput() == false;
setter.setInput(action, Boolean.TRUE);
assert action.isBooleanInput() == true;
setter = new InjectionSetter(TestAction.class, "setShortInput", "shortInput", Short.TYPE);
setter.setInput(action, null);
assert action.getShortInput() == 0;
setter.setInput(action, (short) 2);
assert action.getShortInput() == 2;
setter = new InjectionSetter(TestAction.class, "setIntInput", "intInput", Integer.TYPE);
setter.setInput(action, null);
assert action.getIntInput() == 0;
setter.setInput(action, 3);
assert action.getIntInput() == 3;
setter = new InjectionSetter(TestAction.class, "setPrimitiveLongInput", "primitiveLongInput", Long.TYPE);
setter.setInput(action, null);
assert action.getPrimitiveLongInput() == 0;
setter.setInput(action, 4L);
assert action.getPrimitiveLongInput() == 4;
setter = new InjectionSetter(TestAction.class, "setFloatInput", "floatInput", Float.TYPE);
setter.setInput(action, null);
assert action.getFloatInput() == 0;
setter.setInput(action, 5.0F);
assert action.getFloatInput() == 5.0F;
setter = new InjectionSetter(TestAction.class, "setDoubleInput", "doubleInput", Double.TYPE);
setter.setInput(action, null);
assert action.getDoubleInput() == 0;
setter.setInput(action, 6.2);
assert action.getDoubleInput() == 6.2;
}
}