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, ",", "(", ")"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user