SqlMapSession sms = mock(SqlMapSession.class);
when(smc.openSession()).thenReturn(sms);
sms.close();
when(sms.getCurrentConnection()).thenReturn(null);
sms.setUserConnection(null);
sms.startBatch();
when(sms.update("updateFoo", new Foo("bar"))).thenReturn(-2);
List<BatchResult> results = Collections.singletonList(new BatchResult("updateFoo", "update foo"));
results.get(0).setUpdateCounts(new int[] {1});
when(sms.executeBatchDetailed()).thenReturn(results);
writer.write(Collections.singletonList(new Foo("bar")));