Package test.ioc

Source Code of test.ioc.TestIoc

package test.ioc;

import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;

import org.junit.Assert;
import org.junit.Test;

import test.component.AddService;
import test.component.FieldInject;
import test.component.MethodInject;
import test.component2.MethodInject2;

import com.firefly.core.ApplicationContext;
import com.firefly.core.DefaultApplicationContext;

public class TestIoc {
  public static ApplicationContext applicationContext = DefaultApplicationContext
      .getInstance().load();

  @Test
  public void testFieldInject() {
    FieldInject fieldInject = applicationContext.getBean("fieldInject");
    Assert.assertThat(fieldInject.add(5, 4), is(9));
    Assert.assertThat(fieldInject.add2(5, 4), is(9));

    fieldInject = applicationContext.getBean(FieldInject.class);
    Assert.assertThat(fieldInject.add(5, 4), is(9));
    Assert.assertThat(fieldInject.add2(5, 4), is(9));
  }

  @Test
  public void testMethodInject() {
    MethodInject m = applicationContext.getBean("methodInject");
    Assert.assertThat(m.add(5, 4), is(9));
  }

  @Test
  public void testMethodInject2() {
    MethodInject2 m = applicationContext.getBean("methodInject2");
    Assert.assertThat(m.add(5, 5), is(10));
    Assert.assertThat(m.getNum(), is(3));
  }

  @Test
  public void testSingle() {
    AddService t = applicationContext.getBean("addService");
    t.getI();
    t.getI();
    Assert.assertThat(t.getI(), greaterThan(0));
  }
}
TOP

Related Classes of test.ioc.TestIoc

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.