Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
GUVNOR-2680: VersionRecordManager: Index Out of Bounds when opening a…
Browse files Browse the repository at this point in the history
… deleted file (#505)
  • Loading branch information
manstis authored and ederign committed Sep 13, 2016
1 parent 3aec322 commit b16326e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 32 deletions.
Expand Up @@ -259,7 +259,6 @@ private void loadVersions( final Path path,
versionService.call( new RemoteCallback<List<VersionRecord>>() {
@Override
public void callback( final List<VersionRecord> records ) {

String uri = path.toURI();

// We should not recreate the path to latest,
Expand All @@ -268,8 +267,10 @@ public void callback( final List<VersionRecord> records ) {
setPathToLatest( restoreUtil.createObservablePath( path,
uri ) );
}
setVersions( records );
callback.callback( records );
if ( !records.isEmpty() ) {
setVersions( records );
callback.callback( records );
}
}
} ).getVersions( path );
}
Expand Down
Expand Up @@ -17,6 +17,7 @@
package org.uberfire.ext.editor.commons.client.history;

import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -53,31 +54,27 @@ public void setUp() throws Exception {
setUpUtil();
setUpVersions();

versionSelectedEvent = spy(
new VersionSelectedEventMock(
new Callback<VersionSelectedEvent>() {
@Override
public void callback( VersionSelectedEvent result ) {
manager.onVersionSelectedEvent( result );
}
} ) );
manager = spy( new VersionRecordManager(
dropDownButton,
saveButton,
restorePopup,
util,
versionSelectedEvent,
new VersionServiceCallerMock( versions ) ) );

manager.init(
null,
pathTo333,
new Callback<VersionRecord>() {
@Override
public void callback( VersionRecord result ) {
manager.setVersion( result.id() );
}
} );
versionSelectedEvent = spy( new VersionSelectedEventMock( new Callback<VersionSelectedEvent>() {
@Override
public void callback( VersionSelectedEvent result ) {
manager.onVersionSelectedEvent( result );
}
} ) );
manager = spy( new VersionRecordManager( dropDownButton,
saveButton,
restorePopup,
util,
versionSelectedEvent,
new VersionServiceCallerMock( versions ) ) );

manager.init( null,
pathTo333,
new Callback<VersionRecord>() {
@Override
public void callback( VersionRecord result ) {
manager.setVersion( result.id() );
}
} );
}

private void setUpVersions() {
Expand All @@ -101,7 +98,6 @@ private void setUpUtil() {

@Test
public void testSimple() throws Exception {

verify( dropDownButton ).setItems( versions );
assertEquals( pathTo333, manager.getCurrentPath() );
assertEquals( pathTo333, manager.getPathToLatest() );
Expand All @@ -120,7 +116,6 @@ public void testVersionsNull() throws Exception {

@Test
public void testVersionChange() throws Exception {

manager.onVersionSelectedEvent( new VersionSelectedEvent( pathTo333, getVersionRecord( "111" ) ) );

assertEquals( pathTo111, manager.getCurrentPath() );
Expand All @@ -138,7 +133,6 @@ public void testReset() throws Exception {

@Test
public void testReload() throws Exception {

versions.add( getVersionRecord( "444" ) );

ObservablePath pathTo444 = mock( ObservablePath.class );
Expand Down Expand Up @@ -180,7 +174,6 @@ public void saveButtonLabelChangeTest() throws Exception {

@Test
public void testInitNeedsToClearTheState() throws Exception {

// clear the state before to init. This will cover the cases where the init method is invoked multiple
// times. for example if KieEditor.init(...) method is invoked multiple times, or KieMultipleDocumentEditor
// re-initialises VersionRecordManager for different document.
Expand Down Expand Up @@ -246,4 +239,28 @@ public void testReinitialise_WithOlderVersion() {
manager.getVersion() );
}

@Test
@SuppressWarnings("unchecked")
public void zeroVersionRecordsForDeletedFile() {
reset( saveButton );
reset( dropDownButton );

versions.clear();

manager.init( null,
pathTo111,
( VersionRecord result ) -> manager.setVersion( result.id() ) );

verify( dropDownButton,
never() ).setItems( any( List.class ) );
verify( dropDownButton,
never() ).setVersion( any( String.class ) );

assertEquals( pathTo111,
manager.getCurrentPath() );
assertEquals( pathTo111,
manager.getPathToLatest() );
assertNull( manager.getVersion() );
}

}

0 comments on commit b16326e

Please sign in to comment.