This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jakarta.validation.constraints.NotNull; | |
@NotNull | |
public Cart getCart(@NotNull List<Item> items) { | |
return CartFactory.createCart(database.getItems(getUser())); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.mrbear.kotlin.interfaces | |
interface Person { | |
fun getName(): String | |
fun getAge(): Int | |
fun getGender(): String = "Male" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MrBear implements Person { | |
@Override | |
@NotNull | |
public String getName() { | |
return "Mr. Bear"; | |
} | |
@Override | |
public int getAge() { | |
return 50; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.mrbear.kotlin.companionobject | |
import org.testng.annotations.Test | |
import java.time.LocalDate | |
import java.time.Month | |
import org.assertj.core.api.Assertions.assertThat | |
class CompanionObjectTest { | |
@Test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.mrbear.kotlin.operators | |
import org.assertj.core.api.Assertions.assertThat | |
import org.mrbear.kotlin.AddressFactory | |
import org.mrbear.kotlin.Person | |
import org.mrbear.kotlin.PersonFactory | |
import org.testng.annotations.Test | |
class OperatorOverloadingTest { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun testEmpty() { | |
val emptyList: List<String> = listOf() | |
val anotherEmptyList: List<String> = emptyList() | |
assertThat(emptyList).isEmpty() | |
assertThat(anotherEmptyList).isEmpty() | |
assertThat(emptyList).isEqualTo(anotherEmptyList); | |
assertThat(emptyList).isSameAs(anotherEmptyList); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EqualsTest { | |
public enum Day {MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY} | |
/** | |
* Sets in Java are un-ordered. Two sets are equal if they contain the same elements. | |
*/ | |
@Test | |
public void testEqualsSet() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum class ImageMimeType(val description: String) : LookupValue { | |
GIF(".git"), | |
JPEG(".jpeg"), | |
PNG(".png"); | |
override fun getValue(): String = | |
this.name | |
override fun getDescription(): String = description |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface LookupValue { | |
String getValue(); | |
String getDescription(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testSortUnsortedStream() { | |
Person kenThompson = new Person("Ken", "Thompson"); | |
Person edgerDijkstra = new Person("Edger", "Dijkstra"); | |
Person simonThompson = new Person("Simon", "Thompson"); | |
Set<Person> people = Set.of( | |
edgerDijkstra, | |
kenThompson, | |
simonThompson | |
); |
NewerOlder