1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.crypto.pkix.params.x509certificate

File DistinguishedNameTest.java

 

Code metrics

0
16
5
1
78
51
5
0.31
3.2
5
1

Classes

Class Line # Actions
DistinguishedNameTest 33 16 0% 5 4
0.809523881%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20   
21    package org.xwiki.crypto.pkix.params.x509certificate;
22   
23    import java.io.IOException;
24   
25    import org.bouncycastle.asn1.x500.X500Name;
26    import org.junit.Test;
27    import org.xwiki.crypto.pkix.params.PrincipalIndentifier;
28   
29    import static org.hamcrest.CoreMatchers.equalTo;
30    import static org.hamcrest.CoreMatchers.not;
31    import static org.junit.Assert.assertThat;
32   
 
33    public class DistinguishedNameTest
34    {
 
35  1 toggle @Test
36    public void testEquality() throws Exception
37    {
38  1 PrincipalIndentifier john = new DistinguishedName("CN=John Doe");
39  1 PrincipalIndentifier jane = new DistinguishedName("CN=Jane Doe");
40  1 PrincipalIndentifier johnAlias = new DistinguishedName(new X500Name("CN=John Doe"));
41  1 PrincipalIndentifier johnOtherImpl = new PrincipalIndentifier()
42    {
 
43  0 toggle @Override
44    public byte[] getEncoded() throws IOException
45    {
46  0 return new X500Name("CN=John Doe").getEncoded();
47    }
48   
 
49  1 toggle @Override
50    public String getName()
51    {
52  1 return "CN=John Doe";
53    }
54    };
55  1 PrincipalIndentifier janeOtherImpl = new PrincipalIndentifier()
56    {
 
57  0 toggle @Override
58    public byte[] getEncoded() throws IOException
59    {
60  0 return new X500Name("CN=Jane Doe").getEncoded();
61    }
62   
 
63  1 toggle @Override
64    public String getName()
65    {
66  1 return "CN=Jane Doe";
67    }
68    };
69   
70  1 assertThat(john, equalTo(john));
71  1 assertThat(john, equalTo(johnAlias));
72  1 assertThat(john, equalTo(johnOtherImpl));
73  1 assertThat(john, not(equalTo(jane)));
74  1 assertThat(jane, not(equalTo(john)));
75  1 assertThat(john, not(equalTo(janeOtherImpl)));
76  1 assertThat(john, not(equalTo(new Object())));
77    }
78    }