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 Vladimir N. Molotkov
20* @version $Revision$
21*/
22
23package tests.security.spec;
24
25import junit.framework.TestCase;
26
27import java.security.spec.MGF1ParameterSpec;
28
29/**
30 * Test for MGF1ParameterSpec class
31 *
32 */
33public class MGF1ParameterSpecTest extends TestCase {
34
35    /**
36     * Meaningless algorithm name just for testing purposes
37     */
38    private static final String testAlgName = "TEST";
39
40    //
41    // Tests
42    //
43
44    /**
45     * Test #1 for <code>MGF1ParameterSpec</code> constructor<br>
46     * Assertion: constructs new <code>MGF1ParameterSpec</code>
47     * object using valid parameter
48     */
49    public final void testMGF1ParameterSpec01() {
50        try {
51            MGF1ParameterSpec pgf = new MGF1ParameterSpec(testAlgName);
52            assertNotNull(pgf);
53            assertTrue(pgf instanceof MGF1ParameterSpec);
54        } catch (Exception e) {
55            fail("Unexpected exception: " + e);
56        }
57    }
58
59    /**
60     * Test #2 for <code>MGF1ParameterSpec</code> constructor<br>
61     * Assertion: <code>NullPointerException</code> if parameter is <code>null</code>
62     */
63    public final void testMGF1ParameterSpec02() {
64        try {
65            new MGF1ParameterSpec(null);
66            fail("NullPointerException has not been thrown");
67        } catch (NullPointerException ok) {
68            //expected
69        }
70    }
71
72    /**
73     * Test for <code>getDigestAlgorithm</code> method<br>
74     * Assertion: returns the algorithm name of the message
75     * digest used by the mask generation function
76     */
77    public final void testGetDigestAlgorithm() {
78        MGF1ParameterSpec aps = new MGF1ParameterSpec(testAlgName);
79        assertTrue(testAlgName.equals(aps.getDigestAlgorithm()));
80    }
81
82    /**
83     * Test for public static fields and <code>getDigestAlgorithm</code> method<br>
84     * Assertion: returns the algorithm name of the message
85     * digest used by the mask generation function
86     */
87
88    public final void testFieldsGetDigestAlgorithm() {
89        assertEquals("SHA-1", MGF1ParameterSpec.SHA1.getDigestAlgorithm());
90        assertEquals("SHA-256", MGF1ParameterSpec.SHA256.getDigestAlgorithm());
91        assertEquals("SHA-384", MGF1ParameterSpec.SHA384.getDigestAlgorithm());
92        assertEquals("SHA-512", MGF1ParameterSpec.SHA512.getDigestAlgorithm());
93    }
94}
95