Just wrote a couple of methods in my main mock class.
and most of the methods look like this:
Now in the test I write stuff like this:
... do you need explanations on how it works?
What I personally enjoy here is the leisure JavaScript coding style, where you just join the arguments, not giving a fuck about their types.
public void failingOn(String regex) {
this.failureCondition = regex;
}
public void maybeFail(Object...objects) throws HBaseException {
if (failureCondition != null) {
String s = Arrays.asList(objects).toString();
if (s.matches(failureCondition)) {
throw new HBaseException("Congratulations, you hit the jackpot today: " + s);
}
}
}
and most of the methods look like this:
@Override public void bulkDelete(String tableName, CollectionrowKeys, String columnFamily) throws HBaseException { maybeFail("bulkDelete", tableName, rowKeys, columnFamily); table(tableName).family(columnFamily).delete(rowKeys); }
Now in the test I write stuff like this:
@Test
public void testPut_replicating_withErrors() throws Exception {
MockHBaseOperations cluster2 = new MockHBaseOperations();
cluster2.failingOn("\\[sendToCluster, BadTable,.*");
...
}
... do you need explanations on how it works?
What I personally enjoy here is the leisure JavaScript coding style, where you just join the arguments, not giving a fuck about their types.