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.

YamlProfileStoreTest.java 3.5KB

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