Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

YamlProfileStoreTest.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.config.profiles;
  23. import com.google.common.collect.Lists;
  24. import com.google.common.jimfs.Configuration;
  25. import com.google.common.jimfs.Jimfs;
  26. import java.io.IOException;
  27. import java.net.URISyntaxException;
  28. import java.nio.file.FileSystem;
  29. import java.nio.file.Paths;
  30. import java.util.Collection;
  31. import java.util.List;
  32. import java.util.Optional;
  33. import org.junit.Before;
  34. import org.junit.Test;
  35. import org.junit.runner.RunWith;
  36. import org.mockito.runners.MockitoJUnitRunner;
  37. import static junit.framework.TestCase.assertEquals;
  38. import static junit.framework.TestCase.assertTrue;
  39. @RunWith(MockitoJUnitRunner.class)
  40. public class YamlProfileStoreTest {
  41. private Profile profile1;
  42. private Profile profile2;
  43. private Profile profile3;
  44. @Before
  45. public void setup() {
  46. profile1 = Profile.create("profile1", "realname1", Optional.empty(),
  47. Lists.newArrayList("nickname1", "nickname2"));
  48. profile2 = Profile.create("profile2", "realname2", Optional.of("ident2"),
  49. Lists.newArrayList("nickname1", "nickname3"));
  50. profile3 = Profile.create("profile3", "realname3", Optional.empty(),
  51. Lists.newArrayList("nickname3"));
  52. }
  53. @Test
  54. public void testReadProfiles() throws URISyntaxException {
  55. final ProfileStore store = new YamlProfileStore(Paths.get(getClass()
  56. .getResource("profiles.yml").toURI()));
  57. final Collection<Profile> profiles = store.readProfiles();
  58. assertEquals(3, profiles.size());
  59. assertTrue(profiles.contains(profile1));
  60. assertTrue(profiles.contains(profile2));
  61. assertTrue(profiles.contains(profile3));
  62. }
  63. @Test
  64. public void testWriteProfiles() throws IOException {
  65. try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) {
  66. final ProfileStore store = new YamlProfileStore(fs.getPath("/")
  67. .resolve("profiles.yml"));
  68. final List<Profile> profiles = Lists.newArrayList(profile1, profile2, profile3);
  69. store.writeProfiles(profiles);
  70. final Collection<Profile> readProfiles = store.readProfiles();
  71. assertEquals(3, readProfiles.size());
  72. assertTrue(readProfiles.contains(profile1));
  73. assertTrue(readProfiles.contains(profile2));
  74. assertTrue(readProfiles.contains(profile3));
  75. }
  76. }
  77. }