[ANN] KotlinPrimavera 0.2.4_M7

This new version add map-like access to BeanFactory

package org.kotlinprimavera.beans.factory

import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Bean
import org.testng.annotations.Test
import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.testng.Assert.*
import org.springframework.beans.BeansException
import org.springframework.context.annotation.Scope
import org.springframework.beans.factory.config.ConfigurableBeanFactory

public class BeanFactoryTest {

  private val context = AnnotationConfigApplicationContext(javaClass<TestConfig>())

  [Test]
  fun testGetA() {
  val a = context[“a”]
  assertTrue(a is A)
  }

  [Test]
  fun testGetB() {
  try {
           context[javaClass<B>()]
  } catch(e: BeansException) {
           fail()
  }
  }

  [Test]
  fun testGetC() {
  val c1 = context[“c1”, javaClass<C>()]
  assertEquals(c1.value, 1)
  }

  [Test]
  fun testGetD() {
  val dAsAny = context[“d”, 42, “kotlin”]
  assertTrue(dAsAny is D)
  val (num, str) = dAsAny as D
  assertEquals(num, 42)
  assertEquals(str, “kotlin”)

  }

}

class A {
}

class B {
}

class C(val value: Int) {
}

data class D(val num: Int, val str: String) {
}

[Configuration]
public open class TestConfig {

  [Bean]
  public open fun a(): A {
  return A()
  }

  [Bean]
  public open fun b(): B {
  return B()
  }

  [Bean]
  public open fun c1(): C {
  return C(1)
  }

  [Bean]
  public open fun c2(): C {
  return C(2)
  }

  [Bean] [Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)]
  public open fun d(num: Int, str: String): D {
  return D(num, str)
  }
}