@Override public void onFocus() { publishJsApi(); fireChangeTitleEvent(); fireUpdatedLockStatusEvent(); }
void updateLockInfo(final @Observes LockInfo lockInfo) { /* Comparing URIs since lockInfo.getFile() can be an ObservablePath or a PathImpl. */ if (getLockTarget() != null && lockInfo.getFile().toURI().equals(lockTarget.getPath().toURI())) { this.lockInfo = lockInfo; this.lockSyncComplete = true; fireChangeTitleEvent(); fireUpdatedLockStatusEvent(); for (Runnable runnable : getSyncCompleteRunnables()) { runnable.run(); } getSyncCompleteRunnables().clear(); } }
@Test public void testUpdateLockInfoWhenLockTargetIsNull() { final LockInfo lockInfo = mock(LockInfo.class); final Runnable runnable1 = mock(Runnable.class); final Runnable runnable2 = mock(Runnable.class); final List<Runnable> runnables = spy(new ArrayList<>(Arrays.asList(runnable1, runnable2))); doReturn(runnables).when(lockManager).getSyncCompleteRunnables(); doReturn(null).when(lockManager).getLockTarget(); lockManager.updateLockInfo(lockInfo); assertNotEquals(lockInfo, lockManager.getLockInfo()); assertFalse(lockManager.isLockSyncComplete()); verify(lockManager, never()).fireChangeTitleEvent(); verify(lockManager, never()).fireUpdatedLockStatusEvent(); verify(runnable1, never()).run(); verify(runnable2, never()).run(); verify(runnables, never()).clear(); }
@Test public void testUpdateLockInfoWhenLockInfoURIIsNotEqualToLockTargetURI() { final LockInfo lockInfo = mock(LockInfo.class); final Path path = mock(Path.class); final Runnable runnable1 = mock(Runnable.class); final Runnable runnable2 = mock(Runnable.class); final List<Runnable> runnables = spy(new ArrayList<>(Arrays.asList(runnable1, runnable2))); doReturn(runnables).when(lockManager).getSyncCompleteRunnables(); when(lockInfo.getFile()).thenReturn(path); when(path.toURI()).thenReturn("directory/file1.drl"); when(this.path.toURI()).thenReturn("directory/file2.drl"); lockManager.updateLockInfo(lockInfo); assertNotEquals(lockInfo, lockManager.getLockInfo()); assertFalse(lockManager.isLockSyncComplete()); verify(lockManager, never()).fireChangeTitleEvent(); verify(lockManager, never()).fireUpdatedLockStatusEvent(); verify(runnable1, never()).run(); verify(runnable2, never()).run(); verify(runnables, never()).clear(); }
@Test public void testUpdateLockInfoWhenLockTargetIsNull() { final LockInfo lockInfo = mock(LockInfo.class); final Runnable runnable1 = mock(Runnable.class); final Runnable runnable2 = mock(Runnable.class); final List<Runnable> runnables = spy(new ArrayList<>(Arrays.asList(runnable1, runnable2))); doReturn(runnables).when(lockManager).getSyncCompleteRunnables(); doReturn(null).when(lockManager).getLockTarget(); lockManager.updateLockInfo(lockInfo); assertNotEquals(lockInfo, lockManager.getLockInfo()); assertFalse(lockManager.isLockSyncComplete()); verify(lockManager, never()).fireChangeTitleEvent(); verify(lockManager, never()).fireUpdatedLockStatusEvent(); verify(runnable1, never()).run(); verify(runnable2, never()).run(); verify(runnables, never()).clear(); }
@Test public void testUpdateLockInfoWhenLockInfoURIIsNotEqualToLockTargetURI() { final LockInfo lockInfo = mock(LockInfo.class); final Path path = mock(Path.class); final Runnable runnable1 = mock(Runnable.class); final Runnable runnable2 = mock(Runnable.class); final List<Runnable> runnables = spy(new ArrayList<>(Arrays.asList(runnable1, runnable2))); doReturn(runnables).when(lockManager).getSyncCompleteRunnables(); when(lockInfo.getFile()).thenReturn(path); when(path.toURI()).thenReturn("directory/file1.drl"); when(this.path.toURI()).thenReturn("directory/file2.drl"); lockManager.updateLockInfo(lockInfo); assertNotEquals(lockInfo, lockManager.getLockInfo()); assertFalse(lockManager.isLockSyncComplete()); verify(lockManager, never()).fireChangeTitleEvent(); verify(lockManager, never()).fireUpdatedLockStatusEvent(); verify(runnable1, never()).run(); verify(runnable2, never()).run(); verify(runnables, never()).clear(); }
@Test public void testUpdateLockInfoWhenLockInfoURIIsEqualToLockTargetURI() { final LockInfo lockInfo = mock(LockInfo.class); final Path path = mock(Path.class); final Runnable runnable1 = mock(Runnable.class); final Runnable runnable2 = mock(Runnable.class); final List<Runnable> runnables = spy(new ArrayList<>(Arrays.asList(runnable1, runnable2))); doReturn(runnables).when(lockManager).getSyncCompleteRunnables(); when(lockInfo.getFile()).thenReturn(path); when(path.toURI()).thenReturn("directory/file.drl"); when(this.path.toURI()).thenReturn("directory/file.drl"); lockManager.updateLockInfo(lockInfo); assertEquals(lockInfo, lockManager.getLockInfo()); assertTrue(lockManager.isLockSyncComplete()); verify(lockManager).fireChangeTitleEvent(); verify(lockManager).fireUpdatedLockStatusEvent(); verify(runnable1).run(); verify(runnable2).run(); verify(runnables).clear(); }
@Test public void testUpdateLockInfoWhenLockInfoURIIsEqualToLockTargetURI() { final LockInfo lockInfo = mock(LockInfo.class); final Path path = mock(Path.class); final Runnable runnable1 = mock(Runnable.class); final Runnable runnable2 = mock(Runnable.class); final List<Runnable> runnables = spy(new ArrayList<>(Arrays.asList(runnable1, runnable2))); doReturn(runnables).when(lockManager).getSyncCompleteRunnables(); when(lockInfo.getFile()).thenReturn(path); when(path.toURI()).thenReturn("directory/file.drl"); when(this.path.toURI()).thenReturn("directory/file.drl"); lockManager.updateLockInfo(lockInfo); assertEquals(lockInfo, lockManager.getLockInfo()); assertTrue(lockManager.isLockSyncComplete()); verify(lockManager).fireChangeTitleEvent(); verify(lockManager).fireUpdatedLockStatusEvent(); verify(runnable1).run(); verify(runnable2).run(); verify(runnables).clear(); }