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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (c) 2006-2013 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.Matchers.*;
  30. import static org.mockito.Mockito.*;
  31. public class LegacyInstallationStrategyTest {
  32. private LegacyInstallationStrategy strategy;
  33. private UpdateComponent component;
  34. private SingleFileRetrievalResult result;
  35. private UpdateInstallationListener listener;
  36. @Before
  37. public void setup() {
  38. this.strategy = new LegacyInstallationStrategy();
  39. this.component = mock(UpdateComponent.class);
  40. this.result = mock(SingleFileRetrievalResult.class);
  41. this.listener = mock(UpdateInstallationListener.class);
  42. }
  43. @Test
  44. public void testCallsInstallWithCorrectPath() throws Exception {
  45. final File file = mock(File.class);
  46. when(file.getAbsolutePath()).thenReturn("/my/path");
  47. when(result.getFile()).thenReturn(file);
  48. strategy.installImpl(component, result);
  49. verify(component).doInstall("/my/path");
  50. }
  51. @Test
  52. public void testRaisesCompletedEvent() throws Exception {
  53. final File file = mock(File.class);
  54. when(result.getFile()).thenReturn(file);
  55. strategy.addUpdateInstallationListener(listener);
  56. strategy.installImpl(component, result);
  57. verify(listener).installCompleted(component);
  58. }
  59. @Test
  60. public void testRaisesFailedEvent() throws Exception {
  61. final File file = mock(File.class);
  62. when(result.getFile()).thenReturn(file);
  63. when(component.doInstall(anyString())).thenThrow(new IOException());
  64. strategy.addUpdateInstallationListener(listener);
  65. strategy.installImpl(component, result);
  66. verify(listener).installFailed(component);
  67. }
  68. }