2 * Sone - IdentityTest.java - Copyright © 2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.freenet.wot;
20 import static com.google.common.collect.ImmutableMap.of;
21 import static com.google.common.collect.Sets.newHashSet;
22 import static net.pterodactylus.sone.freenet.wot.Identity.TO_CONTEXTS;
23 import static net.pterodactylus.sone.freenet.wot.Identity.TO_PROPERTIES;
24 import static org.hamcrest.MatcherAssert.assertThat;
25 import static org.hamcrest.Matchers.containsInAnyOrder;
26 import static org.hamcrest.Matchers.empty;
27 import static org.hamcrest.Matchers.hasEntry;
28 import static org.hamcrest.Matchers.hasSize;
29 import static org.hamcrest.Matchers.is;
30 import static org.mockito.Mockito.mock;
31 import static org.mockito.Mockito.when;
36 import org.junit.Test;
39 * Unit test for {@link Identity}.
41 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
43 public class IdentityTest {
46 public void convertingAnIdentityIntoItsSones() {
47 Identity identity = mock(Identity.class);
48 when(identity.getContexts()).thenReturn(newHashSet("Test", "Test2"));
49 Set<String> contexts = TO_CONTEXTS.apply(identity);
50 assertThat(contexts, containsInAnyOrder("Test", "Test2"));
54 public void convertingNullIntoAnEmptySet() {
55 assertThat(TO_CONTEXTS.apply(null), empty());
59 public void convertingAnIdentityIntoItsProperties() {
60 Identity identity = mock(Identity.class);
61 when(identity.getProperties()).thenReturn(of("KeyA", "ValueA", "KeyB", "ValueB"));
62 Map<String, String> properties = TO_PROPERTIES.apply(identity);
63 assertThat(properties.entrySet(), hasSize(2));
64 assertThat(properties, hasEntry("KeyA", "ValueA"));
65 assertThat(properties, hasEntry("KeyB", "ValueB"));
69 public void convertingNullIntoAnEmptyMap() {
70 assertThat(TO_PROPERTIES.apply(null).size(), is(0));