您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

LegacyInstallationStrategyTest.java 3.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (c) 2006-2015 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.IOException;
  26. import java.nio.file.Path;
  27. import org.junit.Before;
  28. import org.junit.Test;
  29. import static org.mockito.ArgumentMatchers.any;
  30. import static org.mockito.Mockito.mock;
  31. import static org.mockito.Mockito.verify;
  32. import static org.mockito.Mockito.when;
  33. public class LegacyInstallationStrategyTest {
  34. private LegacyInstallationStrategy strategy;
  35. private UpdateComponent component;
  36. private SingleFileRetrievalResult result;
  37. private UpdateInstallationListener listener;
  38. @Before
  39. public void setup() {
  40. this.strategy = new LegacyInstallationStrategy();
  41. this.component = mock(UpdateComponent.class);
  42. this.result = mock(SingleFileRetrievalResult.class);
  43. this.listener = mock(UpdateInstallationListener.class);
  44. }
  45. @Test
  46. public void testCallsInstallWithCorrectPath() throws Exception { // NOPMD
  47. final Path file = mock(Path.class);
  48. final Path absoluteFile = mock(Path.class);
  49. when(file.toString()).thenReturn("path");
  50. when(file.toAbsolutePath()).thenReturn(absoluteFile);
  51. when(absoluteFile.toString()).thenReturn("/my/path");
  52. when(result.getFile()).thenReturn(file);
  53. strategy.installImpl(component, result);
  54. verify(component).doInstall(file);
  55. }
  56. @Test
  57. public void testRaisesCompletedEvent() throws Exception { // NOPMD
  58. final Path file = mock(Path.class);
  59. final Path absoluteFile = mock(Path.class);
  60. when(file.toString()).thenReturn("path");
  61. when(file.toAbsolutePath()).thenReturn(absoluteFile);
  62. when(absoluteFile.toString()).thenReturn("/my/path");
  63. strategy.addUpdateInstallationListener(listener);
  64. strategy.installImpl(component, result);
  65. verify(listener).installCompleted(component);
  66. }
  67. @Test
  68. public void testRaisesFailedEvent() throws Exception { // NOPMD
  69. final Path file = mock(Path.class);
  70. final Path absoluteFile = mock(Path.class);
  71. when(file.toString()).thenReturn("path");
  72. when(file.toAbsolutePath()).thenReturn(absoluteFile);
  73. when(absoluteFile.toString()).thenReturn("/my/path");
  74. when(component.doInstall(any())).thenThrow(new IOException());
  75. strategy.addUpdateInstallationListener(listener);
  76. strategy.installImpl(component, result);
  77. verify(listener).installFailed(component);
  78. }
  79. }