Skip to content

Instantly share code, notes, and snippets.

@wreulicke
Last active January 24, 2018 02:51
Show Gist options
  • Save wreulicke/7a4617a6c68b874b3027e695099464e6 to your computer and use it in GitHub Desktop.
Save wreulicke/7a4617a6c68b874b3027e695099464e6 to your computer and use it in GitHub Desktop.
class 辛い {
@SpyBean
HogeService hogeService;
@Test
public void testHoge(){
CyclicBarrier barrier = new CyclicBarrier(2);
doAnswer(invocation -> {
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCommit() {
try {
barrier.await();
} catch (InterruptedException | BrokenBarrierException e) {
throw new AssertionError(e);
}
}
});
return invocation.callRealMethod();
}).when(hogeService)
.hoge(any());
barrier.await();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment