Skip to content

Instantly share code, notes, and snippets.

@davetron5000
davetron5000 / Checkstyle pre-commit hook
Created December 18, 2008 02:40
Pre Commit Hook for running checkstyle on changed files
#!/usr/bin/perl
#
# Pre-commit hook for running checkstyle on changed Java sources
#
# To use this you need:
# 1. checkstyle's jar file somewhere
# 2. a checkstyle XML check file somewhere
# 3. To configure git:
# * git config --add checkstyle.jar <location of jar>
# * git config --add checkstyle.checkfile <location of checkfile>
@mariussoutier
mariussoutier / Mail.scala
Created August 23, 2012 12:13
Sending mails fluently in Scala
package object mail {
implicit def stringToSeq(single: String): Seq[String] = Seq(single)
implicit def liftToOption[T](t: T): Option[T] = Some(t)
sealed abstract class MailType
case object Plain extends MailType
case object Rich extends MailType
case object MultiPart extends MailType
@gkzhong
gkzhong / Checkstyle pre-commit hook
Created October 19, 2012 08:04 — forked from davetron5000/Checkstyle pre-commit hook
Pre Commit Hook for running checkstyle on changed files
#!/usr/bin/perl
#
# Pre-commit hook for running checkstyle on changed Java sources
#
# To use this you need:
# 1. checkstyle's jar file somewhere
# 2. a checkstyle XML check file somewhere
# 3. To configure git:
# * git config --add checkstyle.jar <location of jar>
# * git config --add checkstyle.checkfile <location of checkfile>
@staltz
staltz / introrx.md
Last active May 24, 2024 07:56
The introduction to Reactive Programming you've been missing
@ufuk
ufuk / LazyDeveloper.java
Last active June 27, 2019 13:04
Just another reason to why you shouldn't use Lombok, in another saying another reason to why you should write unit tests: You have two fields in your class. Fields are in the same type. You use @AllArgsConstructor to auto-generate your all args constructor. It works for a moment, until you change the order of the field.
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class LazyDeveloper {
private String firstName;
private String lastName;
@ufuk
ufuk / ComparingUtils.java
Last active September 2, 2020 13:41
Fluent API for comparing two Comparables.
public class ComparingUtils {
public static <T extends Comparable<T>> ComparisonBuilder<T> is(T comparable) {
return new ComparisonBuilder<>(comparable);
}
public static class ComparisonBuilder<T> {
private Comparable<T> subject;
@baybatu
baybatu / IsJVMOnDebugMode.java
Created October 12, 2017 05:33
getting info on whether JVM started in debug mode.
/**
*
* -----------------------------------------------------------------------------------
* From : org.junit.rules.DisableOnDebug#isDebugging(java.util.List<java.lang.String>)
* -----------------------------------------------------------------------------------
*
* Parses arguments passed to the runtime environment for debug flags
* <p>
* Options specified in:
* <ul>
@baybatu
baybatu / ZonedDateTimeAsUTC.java
Last active February 15, 2022 08:37
Setting zoned date time as UTC in a new java.util.Date object
/*
*
* Methods manipulate milliseconds field (fastTime) in java.util.Date object.
*
* UTC : 12/10/2017 11:15:00
* Local date time : 12/10/2017 14:15:00 +03:00
*
* @return new java.util.Date
* UTC : 12/10/2017 14:15:00
* Local date time : 12/10/2017 17:15:00 +03:00
@baybatu
baybatu / MockFinalClass.java
Last active June 9, 2018 11:57
Mocking final class in Java with PowerMockito
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
@PrepareForTest(MyFinalClass.class)
public class MyFinalClassTest {
@baybatu
baybatu / mockito-deep-stubs.md
Last active September 21, 2020 07:48
Mockito deep stubs for nested objects
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private NestedObject nestedObject;

example usage in a test method:

when(nestedObject.getStatusInfo().getValue().getStatus()).thenReturn(1);