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.

ProfileManagerDialogTest.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
  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.addons.ui_swing.dialogs.profiles;
  23. import com.dmdirc.Main;
  24. import com.dmdirc.addons.ui_swing.SwingController;
  25. import com.dmdirc.addons.ui_swing.UIUtilities;
  26. import com.dmdirc.addons.ui_swing.components.reorderablelist.ReorderableJList;
  27. import com.dmdirc.config.prefs.validator.FileNameValidator;
  28. import com.dmdirc.config.prefs.validator.IdentValidator;
  29. import com.dmdirc.config.prefs.validator.NotEmptyValidator;
  30. import com.dmdirc.harness.ui.UIClassTestRunner;
  31. import com.dmdirc.harness.ui.UITestIface;
  32. import com.dmdirc.harness.ui.ClassFinder;
  33. import com.dmdirc.harness.ui.ValidatingJTextFieldFinder;
  34. import javax.swing.JList;
  35. import javax.swing.JPanel;
  36. import org.fest.swing.core.EventMode;
  37. import org.fest.swing.fixture.DialogFixture;
  38. import org.junit.After;
  39. import org.junit.Before;
  40. import org.junit.BeforeClass;
  41. import org.junit.Test;
  42. import org.junit.runner.RunWith;
  43. import static org.junit.Assert.*;
  44. @RunWith(UIClassTestRunner.class)
  45. public class ProfileManagerDialogTest implements UITestIface {
  46. private DialogFixture window;
  47. private Profile profile;
  48. @BeforeClass
  49. public static void setUpClass() {
  50. Main.setUI(new SwingController());
  51. }
  52. @Before
  53. public void setUp() {
  54. UIUtilities.initUISettings();
  55. profile = new Profile("unit-test1", "nick1", "real name", "ident");
  56. profile.save();
  57. }
  58. @After
  59. public void tearDown() {
  60. if (window != null) {
  61. window.cleanUp();
  62. }
  63. profile.delete();
  64. }
  65. @Test
  66. public void testDetails() {
  67. setupWindow();
  68. window.list(new ClassFinder<JList>(JList.class, null))
  69. .selectItem("unit-test1").requireSelection("unit-test1");
  70. window.textBox(new ValidatingJTextFieldFinder(FileNameValidator.class))
  71. .requireText("unit-test1"); // Profile name
  72. window.textBox(new ValidatingJTextFieldFinder(NotEmptyValidator.class))
  73. .requireText("real name"); // Real name
  74. window.textBox(new ValidatingJTextFieldFinder(IdentValidator.class))
  75. .requireText("ident"); // Ident
  76. assertEquals(1,
  77. window.list(new ClassFinder<ReorderableJList>(ReorderableJList.class, null))
  78. .selectItem("nick1").requireSelection("nick1").contents().length);
  79. }
  80. protected void setupWindow() {
  81. window = new DialogFixture(ProfileManagerDialog.getProfileManagerDialog(null));
  82. window.robot.settings().eventMode(EventMode.AWT);
  83. window.show();
  84. }
  85. }