Skip to content

Instantly share code, notes, and snippets.

View soudmaijer's full-sized avatar

Stephan Oudmaijer soudmaijer

View GitHub Profile
@soudmaijer
soudmaijer / DBHelper.java
Last active June 2, 2018 16:32
Small Spring Boot JMS queue load generator
package jms.load;
import oracle.jdbc.pool.OracleDataSource;
import oracle.ucp.jdbc.PoolDataSource;
import oracle.ucp.jdbc.PoolDataSourceFactory;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.pool.PooledConnectionFactory;
import javax.jms.QueueConnectionFactory;
import javax.sql.DataSource;
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()
class ParentType(val id: Long)
class ChildType
class ChildTypeBatchApi {
fun load(keys: List<Long>): List<ChildType> = mutableListOf()
}
val childTypeBatchApi = ChildTypeBatchApi()
// Example BatchLoader
var batchLoader: BatchLoader<Long, ChildType> = BatchLoader { keys ->
@RunWith(JMockit.class)
public class AddressBookTest {
@Injectable
private AddressBookRepository addressBookRepository;
@Tested
private AddressBook addressBook;
@Test
public void retrieveAddressByIdTest() {
@RunWith(JMockit::class)
class AddressBookTest {
@Injectable
private lateinit var addressBookRepository: AddressBookRepository
@Tested
private lateinit var addressBook: AddressBook
@Test
fun retrieveAddressByIdTest() {
class AddressBook {
private AddressBookRepository repository;
public AddressBook(AddressBookRepository repository) {
this.repository = repository;
}
public Address getAddressById(int i) {
return repository.findById(i);
}
object : Expectations() {
init {
// Instruct mocks
}
}
expectations {
// Instruct mocks
}
inline fun expectations(crossinline block: KExpectations.() -> Unit) {
object : KExpectations() {
init {
block()
}
}
}
inline fun verifications(crossinline block: KVerifications.() -> Unit) {
object : KVerifications() {
@RunWith(JMockit::class)
class AddressBookTestKt {
@Injectable
private lateinit var addressBookRepository: AddressBookRepository
@Tested
private lateinit var addressBook: AddressBook
@Test
fun retrieveAddressByIdTest() {