Power
DaggerMapstruct
Autovalue
Safety
Error-pronePure4j
Writing your own
JavapoetAutoservice
Mostly tech stuff
We branch tag 1.2 to hotfix/1.2-LN.
We branch hotfix/1.2-LN to bugfix/777...
setup();
doWork();
cleanup();
void setup() {
setupForDataSourceA();
setupForDataSourceB();
...
}
void doWork() {
workForDataSourceA();
workForDataSourceB();
...
}
...
The idiomatic way to handle this in java is with interfaces:
interface DataSource {
void setup();
void doWork();
void cleanup();
}
So each data source implements the interface, and many parts of the general code loop over a set of instances of the interface.
for (DataSource datasource : datasources) {
datasource.setup();
}
for (DataSource datasource : datasources) {
datasource.doWork();
}
...
If you're using Guice for your dependency injection, when you hear the word "set" you might be tempted to use multibindings.
@Singleton
class DataSources {
Set datasources = new HashSet();
public Set getDataSources() {
return Colletions.unmodifiableSet(set);
}
@Inject void setDataSourceA(DataSourceA datasource) {
datasources.add(datasource);
}
@Inject void setDataSourceB(DataSourceB datasource) {
datasources.add(datasource);
}
...
}
This works without any additional binding configuration, using Guice's JustInTimeBindings support for eligible constructors.
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import java.lang.annotation.*;
/*
* To use in a testcase, include a line:
*
@Rule
public NotImplemented.MustFail notImplementedRule = new NotImplemented.MustFail();
*
* and annotate individual test methods:
*
@NotImplemented @Test
public void someTest() {
...
}
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface NotImplemented {
String value() default ""; //to enable grouping tests; doesn't affect tests
boolean invertTest() default true;
public static class MustFail implements TestRule {
@Override
public Statement apply(final Statement base, Description description) {
NotImplemented annotation = description.getAnnotation(NotImplemented.class);
if (annotation == null || !annotation.invertTest()) {
return base;
} else {
return new Statement() {
@Override
public void evaluate() throws Throwable {
try {
base.evaluate();
} catch (AssertionError e) {
return;
}
throw new AssertionError();
}
};
}
}
}
}
if [ "$1" ]
then
totem --fullscreen "$@" &
fi
xtrlock
((ArtisticCowboy)joe).draw()
runs one method, and((Cowboy)joe).draw()
runs another.