Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

OsdPolicyTest.java 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes,
  3. * Simon Mott
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. */
  23. package com.dmdirc.addons.osd;
  24. import java.util.ArrayList;
  25. import org.junit.Before;
  26. import org.junit.Test;
  27. import static org.junit.Assert.*;
  28. import static org.mockito.Mockito.*;
  29. public class OsdPolicyTest {
  30. private OsdManager manager;
  31. @Before
  32. public void setup() {
  33. final ArrayList<OsdWindow> windows = new ArrayList<OsdWindow>();
  34. OsdWindow window = mock(OsdWindow.class);
  35. when(window.getY()).thenReturn(75);
  36. when(window.getHeight()).thenReturn(20);
  37. when(window.isVisible()).thenReturn(false);
  38. windows.add(window);
  39. window = mock(OsdWindow.class);
  40. when(window.getY()).thenReturn(100);
  41. when(window.getHeight()).thenReturn(20);
  42. when(window.isVisible()).thenReturn(true);
  43. windows.add(window);
  44. window = mock(OsdWindow.class);
  45. when(window.getY()).thenReturn(125);
  46. when(window.getHeight()).thenReturn(20);
  47. when(window.isVisible()).thenReturn(true);
  48. windows.add(window);
  49. window = mock(OsdWindow.class);
  50. when(window.getY()).thenReturn(150);
  51. when(window.getHeight()).thenReturn(20);
  52. when(window.isVisible()).thenReturn(true);
  53. windows.add(window);
  54. window = mock(OsdWindow.class);
  55. when(window.getY()).thenReturn(175);
  56. when(window.getHeight()).thenReturn(20);
  57. when(window.isVisible()).thenReturn(false);
  58. windows.add(window);
  59. manager = mock(OsdManager.class);
  60. when(manager.getWindowList()).thenReturn(windows);
  61. }
  62. @Test
  63. public void testOnTop() {
  64. assertEquals(42, OsdPolicy.ONTOP.getYPosition(manager, 42));
  65. }
  66. @Test
  67. public void testClose() {
  68. assertEquals(42, OsdPolicy.CLOSE.getYPosition(manager, 42));
  69. verify(manager).closeAll();
  70. }
  71. @Test
  72. public void testDown() {
  73. assertTrue(OsdPolicy.DOWN.getYPosition(manager, 75) > 170);
  74. }
  75. @Test
  76. public void testUp() {
  77. assertTrue(OsdPolicy.UP.getYPosition(manager, 175) < 80);
  78. }
  79. }