• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016, Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *    * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *    * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *
15  *    * Neither the name of Google Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 package com.google.auth;
33 
34 import static org.junit.Assert.assertEquals;
35 import static org.junit.Assert.assertFalse;
36 import static org.junit.Assert.assertSame;
37 import static org.junit.Assert.assertTrue;
38 
39 import com.google.auth.ServiceAccountSigner.SigningException;
40 import java.io.IOException;
41 import org.junit.Test;
42 
43 public class SigningExceptionTest {
44 
45   private static final String EXPECTED_MESSAGE = "message";
46   private static final RuntimeException EXPECTED_CAUSE = new RuntimeException();
47 
48   @Test
constructor()49   public void constructor() {
50     SigningException signingException = new SigningException(EXPECTED_MESSAGE, EXPECTED_CAUSE);
51     assertEquals(EXPECTED_MESSAGE, signingException.getMessage());
52     assertSame(EXPECTED_CAUSE, signingException.getCause());
53   }
54 
55   @Test
equals_true()56   public void equals_true() throws IOException {
57     SigningException signingException = new SigningException(EXPECTED_MESSAGE, EXPECTED_CAUSE);
58     SigningException otherSigningException = new SigningException(EXPECTED_MESSAGE, EXPECTED_CAUSE);
59     assertTrue(signingException.equals(otherSigningException));
60     assertTrue(otherSigningException.equals(signingException));
61   }
62 
63   @Test
equals_false_message()64   public void equals_false_message() throws IOException {
65     SigningException signingException = new SigningException(EXPECTED_MESSAGE, EXPECTED_CAUSE);
66     SigningException otherSigningException = new SigningException("otherMessage", EXPECTED_CAUSE);
67     assertFalse(signingException.equals(otherSigningException));
68     assertFalse(otherSigningException.equals(signingException));
69   }
70 
71   @Test
equals_false_cause()72   public void equals_false_cause() throws IOException {
73     SigningException signingException = new SigningException(EXPECTED_MESSAGE, EXPECTED_CAUSE);
74     SigningException otherSigningException =
75         new SigningException("otherMessage", new RuntimeException());
76     assertFalse(signingException.equals(otherSigningException));
77     assertFalse(otherSigningException.equals(signingException));
78   }
79 
80   @Test
hashCode_equals()81   public void hashCode_equals() throws IOException {
82     SigningException signingException = new SigningException(EXPECTED_MESSAGE, EXPECTED_CAUSE);
83     SigningException otherSigningException = new SigningException(EXPECTED_MESSAGE, EXPECTED_CAUSE);
84     assertEquals(signingException.hashCode(), otherSigningException.hashCode());
85   }
86 }
87