You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LegacyInstallationStrategyTest.java 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (c) 2006-2014 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.updater.installing;
  23. import com.dmdirc.updater.UpdateComponent;
  24. import com.dmdirc.updater.retrieving.SingleFileRetrievalResult;
  25. import java.io.File;
  26. import java.io.IOException;
  27. import org.junit.Before;
  28. import org.junit.Test;
  29. import static org.mockito.Mockito.*;
  30. public class LegacyInstallationStrategyTest {
  31. private LegacyInstallationStrategy strategy;
  32. private UpdateComponent component;
  33. private SingleFileRetrievalResult result;
  34. private UpdateInstallationListener listener;
  35. @Before
  36. public void setup() {
  37. this.strategy = new LegacyInstallationStrategy();
  38. this.component = mock(UpdateComponent.class);
  39. this.result = mock(SingleFileRetrievalResult.class);
  40. this.listener = mock(UpdateInstallationListener.class);
  41. }
  42. @Test
  43. public void testCallsInstallWithCorrectPath() throws Exception { // NOPMD
  44. final File file = mock(File.class);
  45. when(file.getAbsolutePath()).thenReturn("/my/path");
  46. when(result.getFile()).thenReturn(file);
  47. strategy.installImpl(component, result);
  48. verify(component).doInstall("/my/path");
  49. }
  50. @Test
  51. public void testRaisesCompletedEvent() throws Exception { // NOPMD
  52. final File file = mock(File.class);
  53. when(result.getFile()).thenReturn(file);
  54. strategy.addUpdateInstallationListener(listener);
  55. strategy.installImpl(component, result);
  56. verify(listener).installCompleted(component);
  57. }
  58. @Test
  59. public void testRaisesFailedEvent() throws Exception { // NOPMD
  60. final File file = mock(File.class);
  61. when(result.getFile()).thenReturn(file);
  62. when(component.doInstall(anyString())).thenThrow(new IOException());
  63. strategy.addUpdateInstallationListener(listener);
  64. strategy.installImpl(component, result);
  65. verify(listener).installFailed(component);
  66. }
  67. }