Skip to content

Commit

Permalink
IZPACK-1528: Re-add UninstallerListener#beforeDelete(List<File>) for …
Browse files Browse the repository at this point in the history
…backwards compatibility
  • Loading branch information
Michael Aichler committed Apr 4, 2017
1 parent 32ae288 commit 9d1ef8b
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,28 @@ public void initialise()
* Invoked before files are deleted.
*
* @param files all files which should be deleted
* @throws IzPackException for any error
*/
@Override
public void beforeDelete(List<File> files)
{
}

/**
* Invoked before files are deleted.
* <p>
* The default implementation calls {@link #beforeDelete(List)} for
* backwards compatibility.
* </p>
*
* @param files all files which should be deleted
* @param listener the progress listener
* @throws IzPackException for any error
*/
@Override
public void beforeDelete(List<File> files, ProgressListener listener)
{
beforeDelete(files);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
*/
public interface UninstallerListener extends InstallationListener
{
/**
* Invoked before files are deleted.
*
* @param files all files which should be deleted
* @throws IzPackException for any error
*/
void beforeDelete(List<File> files);

/**
* Invoked before files are deleted.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* IzPack - Copyright 2001-2012 Julien Ponge, All Rights Reserved.
*
* http://izpack.org/
* http://izpack.codehaus.org/
*
* Copyright 2012 Tim Anderson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.izforge.izpack.api.event;

import org.junit.Test;
import org.mockito.Mockito;

import java.io.File;
import java.util.Collections;
import java.util.List;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;

public class UninstallerListenerTest {

@Test
public void beforeDeleteWithProgressListenerShouldForwardCallToBeforeDelete() {

final List<File> files = Collections.emptyList();
final ProgressListener progressListener = Mockito.mock(ProgressListener.class);

RecordingUninstallerListener listener = new RecordingUninstallerListener();
listener.beforeDelete(files, progressListener);

assertThat(listener.beforeDeleteMethodCalled, equalTo(true));
}

/*
* Records whether #beforeDelete(List<File>) was called.
*/
public static class RecordingUninstallerListener extends AbstractUninstallerListener {

boolean beforeDeleteMethodCalled = false;

@Override
public void beforeDelete(List<File> files) {
beforeDeleteMethodCalled = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.izforge.izpack.test.listener;

import com.izforge.izpack.api.event.AbstractUninstallerListener;
import com.izforge.izpack.api.event.ProgressListener;
import com.izforge.izpack.api.event.UninstallerListener;
import com.izforge.izpack.api.exception.IzPackException;
Expand All @@ -18,7 +19,7 @@
*
* @author Tim Anderson
*/
public class TestUninstallerListener implements UninstallerListener
public class TestUninstallerListener extends AbstractUninstallerListener
{

/**
Expand Down Expand Up @@ -139,7 +140,7 @@ public boolean isFileListener()
* @throws IzPackException for any error
*/
@Override
public void beforeDelete(List<File> files, ProgressListener listener)
public void beforeDelete(List<File> files)
{
++state.beforeListDeleteCount;
log("beforeDelete: files=" + files.size());
Expand Down

0 comments on commit 9d1ef8b

Please sign in to comment.