1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 /** 19 * @author Alexander V. Esin 20 */ 21 package org.ietf.jgss; 22 23 import junit.framework.TestCase; 24 25 /** 26 * Tests GSSException class 27 */ 28 public class GSSExceptionTest extends TestCase { 29 30 public void testGetMajor() { 31 GSSException gssException= new GSSException(GSSException.BAD_NAME); 32 assertEquals(GSSException.BAD_NAME, gssException.getMajor() ); 33 } 34 35 public void testGetMajor_0() { 36 GSSException gssException= new GSSException(0); 37 assertEquals(GSSException.FAILURE, gssException.getMajor() ); 38 } 39 40 public void testGetMajor_1() { 41 GSSException gssException= new GSSException(GSSException.BAD_NAME, GSSException.BAD_NAME, "Bad day today"); 42 assertEquals(GSSException.BAD_NAME, gssException.getMajor() ); 43 } 44 45 public void testGetMajor_2() { 46 GSSException gssException= new GSSException(0, 0, "Bad day today"); 47 assertEquals(GSSException.FAILURE, gssException.getMajor() ); 48 } 49 50 public void testGetMajor_3() { 51 GSSException gssException= new GSSException(GSSException.NO_CRED); 52 assertEquals(GSSException.NO_CRED, gssException.getMajor()); 53 } 54 55 public void testGetMajor_4() { 56 GSSException gssException= new GSSException(-1, -1, "Bad day today"); 57 assertEquals(GSSException.FAILURE, gssException.getMajor()); 58 } 59 60 public void testGetMajorString() { 61 GSSException gssException= new GSSException(GSSException.BAD_NAME); 62 String majorString= gssException.getMajorString(); 63 assertEquals("BAD NAME", majorString ); 64 } 65 66 public void testGetMinor() { 67 GSSException gssException= new GSSException(GSSException.BAD_NAME); 68 assertEquals(0, gssException.getMinor() ); 69 } 70 71 public void testGetMinor_0() { 72 GSSException gssException= new GSSException(GSSException.BAD_NAME, GSSException.BAD_NAME, "Bad day today"); 73 assertEquals(GSSException.BAD_NAME, gssException.getMinor() ); 74 } 75 76 public void testGetMinor_1() { 77 GSSException gssException= new GSSException(GSSException.BAD_NAME); 78 gssException.setMinor(GSSException.BAD_NAME, "Unclear reason"); 79 assertEquals(GSSException.BAD_NAME, gssException.getMinor() ); 80 } 81 82 public void testGetMinor_2() { 83 GSSException gssException= new GSSException(-1, -1, "Bad day today"); 84 assertEquals(-1, gssException.getMinor() ); 85 } 86 87 public void testGetMinor_3() { 88 GSSException gssException= new GSSException(GSSException.BAD_NAME); 89 gssException.setMinor(-1, "Unclear reason"); 90 assertEquals(-1, gssException.getMinor() ); 91 } 92 93 94 public void testGetMinorString() { 95 GSSException gssException= new GSSException(GSSException.BAD_NAME); 96 String minorString= gssException.getMinorString(); 97 assertNull(minorString); 98 } 99 100 public void testGetMinorString_0() { 101 GSSException gssException= new GSSException(GSSException.BAD_NAME, GSSException.BAD_NAME, "Bad day today"); 102 String minorString= gssException.getMinorString(); 103 assertEquals("Bad day today", minorString ); 104 } 105 106 public void testGetMinorString_1() { 107 GSSException gssException= new GSSException(GSSException.BAD_NAME); 108 gssException.setMinor(-1, "Bad day today"); 109 String minorString= gssException.getMinorString(); 110 assertEquals("Bad day today", minorString ); 111 } 112 public void testGetMinorString_2() { 113 GSSException gssException= new GSSException(GSSException.BAD_NAME, 0, "Bad day today"); 114 String minorString= gssException.getMinorString(); 115 assertNull(minorString); 116 } 117 118 public void testGetMinorString_3() { 119 GSSException gssException= new GSSException(GSSException.BAD_NAME); 120 gssException.setMinor(0, "Bad day today"); 121 String minorString= gssException.getMinorString(); 122 assertNull(minorString); 123 } 124 125 public void testGetMessage() { 126 GSSException gssException= new GSSException(GSSException.BAD_NAME); 127 assertEquals("BAD NAME", gssException.getMessage() ); 128 } 129 130 public void testGetMessage_0() { 131 GSSException gssException= new GSSException(GSSException.BAD_NAME, GSSException.BAD_NAME, "Bad day today"); 132 assertEquals("BAD NAME (Bad day today)", gssException.getMessage() ); 133 } 134 135 public void testGetMessage_1() { 136 GSSException gssException= new GSSException(GSSException.BAD_NAME); 137 gssException.setMinor(GSSException.BAD_NAME, "Unclear reason"); 138 assertEquals("BAD NAME (Unclear reason)", gssException.getMessage() ); 139 } 140 141 public void testGetMessage_2() { 142 GSSException gssException= new GSSException(GSSException.BAD_NAME, GSSException.BAD_NAME, "Bad day today"); 143 gssException.setMinor(GSSException.BAD_NAME, "Unclear reason"); 144 assertEquals("BAD NAME (Unclear reason)", gssException.getMessage() ); 145 } 146 147 public void testToString() { 148 GSSException gssException= new GSSException(GSSException.BAD_NAME); 149 assertEquals("GSSException: BAD NAME", gssException.toString() ); 150 } 151 152 public void testToString_0() { 153 GSSException gssException= new GSSException(GSSException.BAD_NAME, GSSException.BAD_NAME, "Bad day today"); 154 assertEquals("GSSException: BAD NAME (Bad day today)", gssException.toString() ); 155 } 156 } 157