|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.commonwl.view.researchobject; |
| 21 | + |
| 22 | +import org.junit.Test; |
| 23 | + |
| 24 | +import java.net.URI; |
| 25 | +import java.util.HashSet; |
| 26 | +import java.util.Set; |
| 27 | + |
| 28 | +import static org.junit.Assert.assertEquals; |
| 29 | +import static org.junit.Assert.assertNull; |
| 30 | + |
| 31 | +public class HashableAgentTest { |
| 32 | + |
| 33 | + /** |
| 34 | + * If the ORCID of two agents is the same, they are the same person |
| 35 | + * regardless of other information |
| 36 | + */ |
| 37 | + @Test |
| 38 | + public void orcidsMakeAgentsEqual() throws Exception { |
| 39 | + |
| 40 | + HashableAgent firstOrcid = new HashableAgent("Mark Robindsason", |
| 41 | + new URI("http://orcid.org/0000-0002-8184-7507"), |
| 42 | + |
| 43 | + |
| 44 | + HashableAgent secondOrcid = new HashableAgent("Mark Robinson", |
| 45 | + new URI("http://orcid.org/0000-0002-8184-7507"), |
| 46 | + |
| 47 | + |
| 48 | + Set<HashableAgent> testSet = new HashSet<>(); |
| 49 | + testSet.add(firstOrcid); |
| 50 | + testSet.remove(secondOrcid); |
| 51 | + testSet.add(secondOrcid); |
| 52 | + |
| 53 | + assertEquals(1, testSet.size()); |
| 54 | + HashableAgent fromSet = testSet.iterator().next(); |
| 55 | + assertEquals("Mark Robinson", fromSet.getName()); |
| 56 | + assertEquals( new URI( "[email protected]"), fromSet. getUri()); |
| 57 | + assertEquals(new URI("http://orcid.org/0000-0002-8184-7507"), fromSet.getOrcid()); |
| 58 | + |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * When no ORCID is present but emails are the same, the agents are |
| 63 | + * the same person regardless of name |
| 64 | + */ |
| 65 | + @Test |
| 66 | + public void noOrcidEmailSameMakesAgentsEqual() throws Exception { |
| 67 | + |
| 68 | + HashableAgent firstEmail = new HashableAgent("Mark Robindsason", |
| 69 | + null, |
| 70 | + |
| 71 | + |
| 72 | + HashableAgent secondEmail = new HashableAgent("Mark Robinson", |
| 73 | + null, |
| 74 | + |
| 75 | + |
| 76 | + Set<HashableAgent> testSet = new HashSet<>(); |
| 77 | + testSet.add(firstEmail); |
| 78 | + testSet.remove(secondEmail); |
| 79 | + testSet.add(secondEmail); |
| 80 | + |
| 81 | + assertEquals(1, testSet.size()); |
| 82 | + HashableAgent fromSet = testSet.iterator().next(); |
| 83 | + assertEquals("Mark Robinson", fromSet.getName()); |
| 84 | + assertEquals( new URI( "[email protected]"), fromSet. getUri()); |
| 85 | + assertNull(fromSet.getOrcid()); |
| 86 | + |
| 87 | + } |
| 88 | +} |
0 commit comments