@Test
public void testSynchronizeWithExceptionInLock() {

    Lock[] locks = new Lock[10];
    for (int i = 0; i < locks.length; i++)
        locks[i] = mock(Lock.class);
    RuntimeException ex = new RuntimeException();
    doThrow(ex).when(locks[5]).lock();
    try {
        DefaultModelStorage.synchronize(() -> {}, locks);
        fail();
    }
    catch (RuntimeException e) {
        assertEquals(ex, e);
    }
    for (int i = 0; i < locks.length; i++) {
        if (i <= 4) {
            verify(locks[i], times(1)).lock();
            verify(locks[i], times(1)).unlock();
        }
        else if (i > 5) {
            verify(locks[i], times(0)).lock();
            verify(locks[i], times(0)).unlock();
        }
        else {
            verify(locks[i], times(1)).lock();
            verify(locks[i], times(0)).unlock();
        }
        verifyNoMoreInteractions(locks[i]);
    }
}