Skip to content

Instantly share code, notes, and snippets.

Avatar

Stephan Oudmaijer soudmaijer

View GitHub Profile
@soudmaijer
soudmaijer / DBHelper.java
Last active Jun 2, 2018
Small Spring Boot JMS queue load generator
View DBHelper.java
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;
View Kotlin.kt
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()
View GraphQLJavaToolsDataLoader.kt
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 ->
View AddressBookTest.java
@RunWith(JMockit.class)
public class AddressBookTest {
@Injectable
private AddressBookRepository addressBookRepository;
@Tested
private AddressBook addressBook;
@Test
public void retrieveAddressByIdTest() {
View AddressBookTest.kt
@RunWith(JMockit::class)
class AddressBookTest {
@Injectable
private lateinit var addressBookRepository: AddressBookRepository
@Tested
private lateinit var addressBook: AddressBook
@Test
fun retrieveAddressByIdTest() {
View AddressBook.java
class AddressBook {
private AddressBookRepository repository;
public AddressBook(AddressBookRepository repository) {
this.repository = repository;
}
public Address getAddressById(int i) {
return repository.findById(i);
}
View JMockitExpectations.kt
object : Expectations() {
init {
// Instruct mocks
}
}
View JMockitExtentions.kt
inline fun expectations(crossinline block: KExpectations.() -> Unit) {
object : KExpectations() {
init {
block()
}
}
}
inline fun verifications(crossinline block: KVerifications.() -> Unit) {
object : KVerifications() {
View AddressBookTestRevamped.kt
@RunWith(JMockit::class)
class AddressBookTestKt {
@Injectable
private lateinit var addressBookRepository: AddressBookRepository
@Tested
private lateinit var addressBook: AddressBook
@Test
fun retrieveAddressByIdTest() {