Skip to content

Instantly share code, notes, and snippets.

@ittaiz
ittaiz / JacksonMultiMapTest.scala
Last active December 20, 2015 18:18
A test with guava and scala modules which fails due to order of module registration
package com.wixpress.report
import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
import com.fasterxml.jackson.datatype.guava.GuavaModule
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import org.junit._
import Assert._
/**
* @author: ittaiz
@ittaiz
ittaiz / JsonNodeOptionDeserializerTest.scala
Created October 9, 2013 16:12
Test showing classes with an option[JsonNode] stopped serializing
import com.fasterxml.jackson.databind.{ObjectMapper, JsonNode}
import scala.Some
import org.specs2.mutable.SpecificationWithJUnit
import com.fasterxml.jackson.module.scala.DefaultScalaModule
class JsonNodeOptionDeserializerTest extends SpecificationWithJUnit {
"Option[JsonNode] " should {
"serialize its content when contained in an object" in {
val mapper = new ObjectMapper().registerModule(DefaultScalaModule)
val json: String = """{"prop":"value"}"""
@ittaiz
ittaiz / CancellingAScheduledFutureWhileItIsRunningProhibitsItFromRunningTest.java
Created December 26, 2013 13:22
tests which check how jmock and jdk handle canceling a scheduled future while it is running
@Test
public void cancellingAScheduledFutureWhileItIsRunningProhibitsItFromRunningJMock() throws InterruptedException {
final CountDownLatch scheduledHasStarted = new CountDownLatch(1);
final CountDownLatch scheduledHasBeenCancelled = new CountDownLatch(1);
final AtomicInteger counter = new AtomicInteger();
DeterministicScheduler deterministicScheduler = new DeterministicScheduler();
final ScheduledFuture<?> scheduledFuture = deterministicScheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
scheduledHasStarted.countDown();
@ittaiz
ittaiz / CancellingAScheduledFutureWhileItIsRunningHasNoEffect.java
Created December 26, 2013 13:49
cancelling a scheduled future while it is running has no effect
@Test
public void cancellingAScheduledFutureWhileItIsRunningHasNoEffect() {
DeterministicScheduler deterministicScheduler = new DeterministicScheduler();
SchedulerContainer schedulerContainer = new SchedulerContainer(deterministicScheduler);
schedulerContainer.scheduleSelfCancellingTask();
deterministicScheduler.tick(2,TimeUnit.SECONDS);
assertThat(schedulerContainer.runCount(), is(1));
}
public static class SchedulerContainer {
@ittaiz
ittaiz / JacksonRegressionTest.java
Created March 13, 2015 20:29
Jackson Custom exception regression issue
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.scala.DefaultScalaModule;
import org.junit.Test;
import java.io.IOException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
public class JacksonRegressionTest {
@Test
public void jacksonRegressionTest() throws IOException {
SomeException ex = new SomeException("message");
@ittaiz
ittaiz / gist:e4dd2efba31757fe4073
Created March 22, 2015 19:45
Maven polyglot scala build failure
Apache Maven 3.3.1 (cab6659f9874fa96462afef40fcf6bc033d58c1c; 2015-03-13T22:10:27+02:00)
Maven home: /usr/local/Cellar/maven/3.3.1/libexec
Java version: 1.7.0_71, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
[DEBUG] Reading global settings from /usr/local/Cellar/maven/3.3.1/libexec/conf/settings.xml
[DEBUG] Reading user settings from /Users/ittaiz/.m2/settings.xml
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10.0 for /Users/ittaiz/.m2/repository
[DEBUG] Dependency collection stats: {ConflictMarker.analyzeTime=1, ConflictMarker.markTime=0, ConflictMarker.nodeCount=20, ConflictIdSorter.graphTime=0, ConflictIdSorter.topsortTime=1, ConflictIdSorter.conflictIdCount=11, ConflictIdSorter.conflictIdCycleCount=0, ConflictResolver.totalTime=3, ConflictResolver.conflictItemCount=19, DefaultDependencyCollector.collectTime=125, DefaultDependencyCollector.transformTime=6}
[DEBUG] io.takari.poly
@ittaiz
ittaiz / ShutdownAllowingDeterministicScheduler.java
Created December 19, 2015 20:58
ShutdownAllowingDeterministicScheduler suggestion to jmock
private class ShutdownAllowingDeterministicScheduler extends DeterministicScheduler {
override def isShutdown: Boolean = shutdownRequested
override def isTerminated: Boolean = shutdownRequested
override def shutdown(): Unit = shutdownRequested = true
override def shutdownNow: util.List[Runnable] = new util.ArrayList[Runnable]
var shutdownRequested: Boolean = false
@ittaiz
ittaiz / pom.xml
Last active December 24, 2015 08:48
Specs2 uber pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.specs2</groupId>
<artifactId>specs2_2.11</artifactId>
<version>3.5</version>
<name>Specs2 includes</name>
<packaging>pom</packaging>
<dependencies>
<dependency>
@ittaiz
ittaiz / FruitTest.scala
Last active July 28, 2016 12:56
Polymorphic matching
class FruitTest extends SpecificationWithJUnit {
trait Fruit
case class Apple(color: String) extends Fruit
case class Peach(ripeness: Double) extends Fruit
def aColorfulApple(color: String): Matcher[Fruit] = {
val appleMatcher: Matcher[Apple] = be_===(color) ^^ { a: Apple =>
a.color aka "apple color"
@ittaiz
ittaiz / scala_import.bzl
Created September 15, 2017 11:29
scala_import.bzl which allows to depend on maven jar //jar:file and have it recognized in intellij
def _scala_import_impl(ctx):
code_jars = _filter_out_non_code_jars(ctx.attr.jar.files)
code_jars_depset = depset(code_jars)
return struct(
scala = struct(
outputs = struct(
ijar = None,
class_jar = code_jars[0],
),
),