Skip to content

Instantly share code, notes, and snippets.

View mgenov's full-sized avatar

Miroslav Genov mgenov

View GitHub Profile
@mgenov
mgenov / MockitoBehaviorTest.java
Created January 20, 2012 14:50
MockitoBehaviorTest.java
public class MockitoBehaviorTest {
interface Registry {
void register(Double amount);
}
class PaymentProcessingListener {
private final Registry registry;
public interface Child1 extends ValueProxy {
String getValue();
void setValue(String value);
Long getId();
void setId(Long id);
}
@mgenov
mgenov / PolymorphicTest.java
Created March 16, 2012 14:44
PolymorphicTest.java
static class Person {
@Id
private Long id;
@Embedded(polymorphic = true)
private State state;
}
static class State {
private String value;
@mgenov
mgenov / PolymorphicTest.java
Created March 16, 2012 14:44
PolymorphicTest.java
static class Person {
@Id
private Long id;
@Embedded(polymorphic = true)
private State state;
}
static class State {
private String value;
@mgenov
mgenov / ReferenceTest.java
Created March 16, 2012 14:50
ReferenceTest.java
static class Parent {
@Id
Long id;
}
static class Child {
@Id
Long id;
public class ChangeLoggers {
customer, @Named("CUSTOMER_NAME") String customerName);
public static <T> T create(Class<? extends ChangeLogger> clazz, final CurrentUser currentUser, final ChangeLogBase base) {
return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class<?>[]{clazz}, new InvocationHandler() {
public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
@mgenov
mgenov / ThreadsSample.java
Created June 12, 2012 14:47
ThredsSample.java
class CountingThread extends Thread {
private final int maxCount;
private final CountingThread terminationThread;
private boolean stopped = false;
public CountingThread(int maxCount, CountingThread terminationThread) {
this.maxCount = maxCount;
this.terminationThread = terminationThread;
}
@mgenov
mgenov / IterableTranslator.java
Created June 22, 2012 07:47
IterableTranslator.java
protected Collection<Object> createCollection(Type type)
{
// support reusing existing implementations
if (datastore.refresh != null)
{
@SuppressWarnings("unchecked")
Collection<Object> result = (Collection<Object>) datastore.refresh;
datastore.refresh = null;
return result;
}
@mgenov
mgenov / CalendarUtil.java
Created June 27, 2012 09:03
QueriesLearningTest
public final class CalendarUtil {
@SuppressWarnings("unused")
CalendarUtil() {
}
public static Date january(int year, int day) {
return newDate(year, 1, day);
}
@mgenov
mgenov / CalculatorTest.java
Created July 22, 2012 10:41
CalculatorTest.java
package com.clouway.calculator;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.util.ArrayList;
import java.util.List;