added a little test of showing how we can use the standard kotlin functions and standard library from Java
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-project</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>kotlin-java</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>stdlib</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-runtime</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${kotlin-sdk}/lib/kotlin-runtime.jar</systemPath>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<testSourceDirectory>src/test/java</testSourceDirectory>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,34 @@
|
||||
package test.kotlin.jtests;
|
||||
|
||||
import static kotlin.namespace.*;
|
||||
import static kotlin.util.namespace.*;
|
||||
|
||||
import jet.Function1;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Lets try using the Kotlin standard library from Java code
|
||||
*/
|
||||
public class CollectionTest extends TestCase {
|
||||
|
||||
public void testCollections() throws Exception {
|
||||
List<String> list = arrayList("foo", "bar");
|
||||
|
||||
String text = join(list, ",", "(", ")");
|
||||
System.out.println("Have text: " + text);
|
||||
assertEquals("(foo,bar)", text);
|
||||
|
||||
Collection<String> actual = filter(list, new Function1<String, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(String text) {
|
||||
return text.startsWith("b");
|
||||
}
|
||||
});
|
||||
|
||||
System.out.println("Filtered list is " + actual);
|
||||
assertEquals("(bar)", join(actual, ",", "(", ")"));
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,8 @@
|
||||
<kotlin-maven-plugin.version>0.2.3.8-beta-10</kotlin-maven-plugin.version>
|
||||
<project-root>${project.basedir}/..</project-root>
|
||||
<kotlin-sdk>${project-root}/../dist/kotlinc</kotlin-sdk>
|
||||
<maven.compiler.source>1.6</maven.compiler.source>
|
||||
<maven.compiler.target>1.6</maven.compiler.target>
|
||||
<pegdown.version>1.1.0</pegdown.version>
|
||||
<surefire-version>2.5</surefire-version>
|
||||
</properties>
|
||||
@@ -41,6 +43,7 @@
|
||||
<module>kdoc</module>
|
||||
<module>kotlin-jdbc</module>
|
||||
<module>website</module>
|
||||
<module>kotlin-java</module>
|
||||
</modules>
|
||||
|
||||
<build>
|
||||
@@ -66,6 +69,16 @@
|
||||
<verbose>false</verbose>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user