diff --git a/kotlin/pom.xml b/kotlin/pom.xml index 07fb6863d4..89d9e2b292 100644 --- a/kotlin/pom.xml +++ b/kotlin/pom.xml @@ -26,6 +26,12 @@ ${junit.version} test + + org.jetbrains.kotlin + kotlin-reflect + ${kotlin-reflect.version} + test + @@ -93,6 +99,7 @@ 1.1.1 1.1.1 1.1.1 + 1.1.1 \ No newline at end of file diff --git a/kotlin/src/main/java/com/baeldung/java/ArrayExample.java b/kotlin/src/main/java/com/baeldung/java/ArrayExample.java new file mode 100644 index 0000000000..ef91db517b --- /dev/null +++ b/kotlin/src/main/java/com/baeldung/java/ArrayExample.java @@ -0,0 +1,24 @@ +package com.baeldung.java; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +public class ArrayExample { + + public int sumValues(int[] nums) { + int res = 0; + + for (int x:nums) { + res += x; + } + + return res; + } + + public void writeList() throws IOException { + File file = new File("E://file.txt"); + FileReader fr = new FileReader(file); + fr.close(); + } +} diff --git a/kotlin/src/main/java/com/baeldung/java/Customer.java b/kotlin/src/main/java/com/baeldung/java/Customer.java new file mode 100644 index 0000000000..0156bf7b44 --- /dev/null +++ b/kotlin/src/main/java/com/baeldung/java/Customer.java @@ -0,0 +1,24 @@ +package com.baeldung.java; + +public class Customer { + + private String firstName; + private String lastName; + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + +} diff --git a/kotlin/src/test/kotlin/com/baeldung/kotlin/ArrayTest.kt b/kotlin/src/test/kotlin/com/baeldung/kotlin/ArrayTest.kt new file mode 100644 index 0000000000..f7d1c53b13 --- /dev/null +++ b/kotlin/src/test/kotlin/com/baeldung/kotlin/ArrayTest.kt @@ -0,0 +1,39 @@ +package com.baeldung.kotlin + +import com.baeldung.java.ArrayExample +import com.baeldung.java.Customer +import org.junit.Test +import kotlin.test.assertEquals + +class ArrayTest { + + @Test + fun givenArray_whenValidateArrayType_thenComplete () { + val ex = ArrayExample() + val numArray = intArrayOf(1, 2, 3) + + assertEquals(ex.sumValues(numArray), 6) + } + + @Test + fun givenCustomer_whenGetSuperType_thenComplete() { + val instance = Customer::class + val supertypes = instance.supertypes + + assertEquals(supertypes[0].toString(), "kotlin.Any") + } + + @Test + fun givenCustomer_whenGetConstructor_thenComplete() { + val instance = Customer::class.java + val constructors = instance.constructors + + assertEquals(constructors.size, 1) + assertEquals(constructors[0].name, "com.baeldung.java.Customer") + } + + fun makeReadFile() { + val ax = ArrayExample() + ax.writeList() + } +} \ No newline at end of file diff --git a/kotlin/src/test/kotlin/com/baeldung/kotlin/CustomerTest.kt b/kotlin/src/test/kotlin/com/baeldung/kotlin/CustomerTest.kt new file mode 100644 index 0000000000..6395dfcfed --- /dev/null +++ b/kotlin/src/test/kotlin/com/baeldung/kotlin/CustomerTest.kt @@ -0,0 +1,23 @@ +package com.baeldung.kotlin + +import com.baeldung.java.Customer +import org.junit.Test +import kotlin.test.assertEquals + +class CustomerTest { + + @Test + fun givenCustomer_whenNameAndLastNameAreAssigned_thenComplete() { + val customer = Customer() + + // Setter method is being called + customer.firstName = "Frodo" + customer.lastName = "Baggins" + + // Getter method is being called + assertEquals(customer.firstName, "Frodo") + assertEquals(customer.lastName, "Baggins") + } + +} +