This file contains 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
class CollateralArrangement(val trackingNumber: Int) | |
class Facility(val collateralArrangement: List<CollateralArrangement>) | |
class CollateralArrangementTuple(val collateralArrangement: CollateralArrangement, val facility: Facility) | |
val facilities = listOf(Facility(collateralArrangement = listOf(CollateralArrangement(1), CollateralArrangement(2), CollateralArrangement(3)))) | |
// with Kotlin, results in: Map<Int, CollateralArrangementTuple> | |
val map = facilities.flatMap { facility -> facility.collateralArrangement.map { Pair(it.trackingNumber, CollateralArrangementTuple(it, facility)) } }.toMap() |
This file contains 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
class AddressBook { | |
private AddressBookRepository repository; | |
public AddressBook(AddressBookRepository repository) { | |
this.repository = repository; | |
} | |
public Address getAddressById(int i) { | |
return repository.findById(i); | |
} |
This file contains 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
@RunWith(JMockit.class) | |
public class AddressBookTest { | |
@Injectable | |
private AddressBookRepository addressBookRepository; | |
@Tested | |
private AddressBook addressBook; | |
@Test | |
public void retrieveAddressByIdTest() { |
This file contains 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
@RunWith(JMockit::class) | |
class AddressBookTest { | |
@Injectable | |
private lateinit var addressBookRepository: AddressBookRepository | |
@Tested | |
private lateinit var addressBook: AddressBook | |
@Test | |
fun retrieveAddressByIdTest() { |
This file contains 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
object : Expectations() { | |
init { | |
// Instruct mocks | |
} | |
} |
This file contains 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
expectations { | |
// Instruct mocks | |
} |
This file contains 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
inline fun expectations(crossinline block: KExpectations.() -> Unit) { | |
object : KExpectations() { | |
init { | |
block() | |
} | |
} | |
} | |
inline fun verifications(crossinline block: KVerifications.() -> Unit) { | |
object : KVerifications() { |
This file contains 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
@RunWith(JMockit::class) | |
class AddressBookTestKt { | |
@Injectable | |
private lateinit var addressBookRepository: AddressBookRepository | |
@Tested | |
private lateinit var addressBook: AddressBook | |
@Test | |
fun retrieveAddressByIdTest() { |
This file contains 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 org.springframework.jdbc.core.JdbcTemplate | |
import org.springframework.jdbc.core.RowMapper | |
import org.springframework.stereotype.Repository | |
@Repository | |
class OrderRepository(private val jdbcTemplate: JdbcTemplate) { | |
private val rowMapper: RowMapper<Order> = RowMapper { rs, i -> Order(rs.getLong("id")) } | |
fun findOrderById(id: Long): Order? { | |
val result = jdbcTemplate.query<Order>("select * from orders where id=:id", rowMapper, id) |
This file contains 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 org.springframework.jdbc.core.JdbcTemplate | |
import org.springframework.jdbc.core.RowMapper | |
import org.springframework.stereotype.Repository | |
import java.util.* | |
@Repository | |
class OrderRepository(private val jdbcTemplate: JdbcTemplate) { | |
private val rowMapper: RowMapper<Order> = RowMapper { rs, i -> Order(rs.getLong("id")) } | |
fun findOrderById(id: Long): Optional<Order> { |
OlderNewer