This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class SealedServices { | |
Services() { | |
// Default scoped constructor prevents extension by client | |
} | |
public abstract FooService getFooService(); | |
public abstract BarService getBarService(); | |
abstract void validate(); // method we don’t want the client to call |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class DefaultSealedServices extends SealedServices { | |
private FooService fooService; | |
private BarService barService; | |
// We don’t want the client to instantiate this class | |
DefaultSealedServices(FooService fooService, BarService barService) { | |
this.fooService = fooService; | |
this.barService = barService; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Choose relevant names for types that are unlikely to exist in another library | |
public final class SealedServicesFactory { | |
// No need to repeat “my” or “service” in the method name, as the type defines the | |
// scope already. | |
public SealedServices create() { | |
return new DefaultSealedServices(new FooService(), new BarService()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GuidedMethodChainExample { | |
public static void main(String[] args) throws SQLException { | |
// The method chain should read like natural language | |
ResultSet rs = SQLQuery.selectFrom("employee") | |
.where("first_name").isEqualTo("John") | |
.and("last_name").isEqualTo("Doe") | |
.execute(); | |
} | |
// These interfaces limit the scope in the method chain |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.reflect.InvocationHandler; | |
import java.lang.reflect.Method; | |
import java.lang.reflect.Proxy; | |
import java.util.HashMap; | |
import java.util.Map; | |
/** | |
* Provides a safe, compiler-checked way to obtain a {@code Method} reference from an interface. eg: | |
* <pre> | |
* {@code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Copyright (c) 2017 Stijn Van Bael. | |
All rights reserved. | |
Redistribution and use in source and binary forms are permitted | |
provided that the above copyright notice and this paragraph are | |
duplicated in all such forms and that any documentation, | |
advertising materials, and other materials related to such | |
distribution and use acknowledge that the software was developed | |
by the <organization>. The name of the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.jdesktop.beansbinding.AutoBinding; | |
import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy; | |
import org.jdesktop.beansbinding.BeanProperty; | |
import org.jdesktop.beansbinding.Bindings; | |
import org.jdesktop.beansbinding.Converter; | |
public class BindingBuilder<S, SV, T, TV> implements PartialBindingBuilder<S, SV> { | |
private final S source; | |
private final String sourceProperty; | |
private AutoBinding<S, SV, T, TV> binding; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Copyright (c) 2014 Stijn Van Bael | |
Permission is hereby granted, free of charge, to any person | |
obtaining a copy of this software and associated documentation | |
files (the "Software"), to deal in the Software without | |
restriction, including without limitation the rights to use, | |
copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the | |
Software is furnished to do so, subject to the following |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.mockito.Mockito; | |
import org.mockito.internal.stubbing.answers.ThrowsException; | |
import org.mockito.invocation.InvocationOnMock; | |
import org.mockito.stubbing.Answer; | |
import org.mockito.stubbing.OngoingStubbing; | |
import org.mockito.stubbing.Stubber; | |
/** | |
* <p> | |
* Provides a way to obtain an OngoingStubbing for spies or void methods. This allows you to write highly readable code in your tests. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.reflect.ParameterizedType; | |
import java.lang.reflect.Type; | |
/** | |
* <p>TypeBuilder builds parameterized {@code Class<?>} references. Example:</p> | |
* <pre> | |
* {@code | |
* Class<List<String>> type = new TypeBuilder<List<String>>() { }.build(); | |
* } | |
* </pre> |
OlderNewer