@Test public void testSynchronizeWithExceptionInUnlock() { 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]).unlock(); try { DefaultModelStorage.synchronize(() -> {}, locks); fail(); } catch (RuntimeException e) { assertEquals(ex, e); } for (Lock lock : locks) { verify(lock, times(1)).lock(); verify(lock, times(1)).unlock(); verifyNoMoreInteractions(lock); } }
static void synchronize(Runnable task, Lock... locks) { synchronize(() -> { task.run(); return null; }, locks); }
DefaultModelStorage implements ModelStorage { static void synchronize(Runnable task, Lock... locks) { synchronize(() -> { task.run(); return null; }, locks); } }
DefaultModelStorage implements ModelStorage { static void synchronize(Runnable task, Lock... locks) { synchronize(() -> { task.run(); return null; }, locks); } DefaultModelStorage(ModelStorageProvider storageProvider); }
DefaultModelStorage implements ModelStorage { static void synchronize(Runnable task, Lock... locks) { synchronize(() -> { task.run(); return null; }, locks); } DefaultModelStorage(ModelStorageProvider storageProvider); @Override void putFile(String path, byte[] data, boolean onlyIfNotExist); @Override byte[] getFile(String path); @Override void mkdir(String path, boolean onlyIfNotExist); @Override void mkdirs(String path); @Override Set<String> listFiles(String path); @Override void remove(String path); @Override boolean exists(String path); @Override boolean isDirectory(String path); @Override boolean isFile(String path); @Override FileStat getFileStat(String path); @Override T lockPaths(Supplier<T> supplier, String... paths); }
DefaultModelStorage implements ModelStorage { static void synchronize(Runnable task, Lock... locks) { synchronize(() -> { task.run(); return null; }, locks); } DefaultModelStorage(ModelStorageProvider storageProvider); @Override void putFile(String path, byte[] data, boolean onlyIfNotExist); @Override byte[] getFile(String path); @Override void mkdir(String path, boolean onlyIfNotExist); @Override void mkdirs(String path); @Override Set<String> listFiles(String path); @Override void remove(String path); @Override boolean exists(String path); @Override boolean isDirectory(String path); @Override boolean isFile(String path); @Override FileStat getFileStat(String path); @Override T lockPaths(Supplier<T> supplier, String... paths);  }