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.

NewProfileNameValidatorTest.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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.ui.core.profiles;
  23. import com.dmdirc.interfaces.ui.ProfilesDialogModel;
  24. import com.dmdirc.util.validators.Validator;
  25. import com.google.common.collect.Lists;
  26. import java.util.List;
  27. import java.util.Optional;
  28. import org.junit.Before;
  29. import org.junit.Test;
  30. import org.junit.runner.RunWith;
  31. import org.mockito.Mock;
  32. import org.mockito.runners.MockitoJUnitRunner;
  33. import static org.junit.Assert.assertFalse;
  34. import static org.junit.Assert.assertTrue;
  35. import static org.mockito.Mockito.when;
  36. @RunWith(MockitoJUnitRunner.class)
  37. public class NewProfileNameValidatorTest {
  38. @Mock private ProfilesDialogModel model;
  39. @Mock private MutableProfile profile1;
  40. @Mock private MutableProfile profile2;
  41. @Mock private MutableProfile profile3;
  42. @Before
  43. public void setupModel() {
  44. final List<MutableProfile> profiles = Lists.newArrayList(profile1, profile2, profile3);
  45. when(profile1.getName()).thenReturn("profile1");
  46. when(profile2.getName()).thenReturn("profile2");
  47. when(profile3.getName()).thenReturn("profile3");
  48. when(model.getProfileList()).thenReturn(profiles);
  49. }
  50. @Test
  51. public void testDuplicateName() {
  52. final Validator<String> instance = new NewProfileNameValidator(model);
  53. assertTrue("testDuplicateName", instance.validate("profile1").isFailure());
  54. }
  55. @Test
  56. public void testNonDuplicateName() {
  57. final Validator<String> instance = new NewProfileNameValidator(model);
  58. assertFalse("testNonDuplicateName", instance.validate("profile4").isFailure());
  59. }
  60. @Test
  61. public void testSelectedName() {
  62. final Validator<String> instance = new NewProfileNameValidator(model);
  63. assertTrue("testSelectedName", instance.validate("profile2").isFailure());
  64. }
  65. }