~ubuntu-branches/ubuntu/trusty/libstruts1.2-java/trusty-proposed

« back to all changes in this revision

Viewing changes to src/example/org/apache/struts/webapp/example/memory/TestUserDatabase.java

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Vandyck
  • Date: 2004-11-19 15:35:25 UTC
  • Revision ID: james.westby@ubuntu.com-20041119153525-mdu08a76z4zo67xt
Tags: upstream-1.2.4
ImportĀ upstreamĀ versionĀ 1.2.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 1999-2002,2004 The Apache Software Foundation.
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
package org.apache.struts.webapp.example.memory;
 
17
 
 
18
import org.apache.struts.webapp.example.User;
 
19
import org.apache.struts.webapp.example.ExpiredPasswordException;
 
20
 
 
21
/**
 
22
 * <p>Help test exception handling by throwing exceptions when "magic" user names are requested.</p>
 
23
 */
 
24
public final class TestUserDatabase extends MemoryUserDatabase {
 
25
 
 
26
 
 
27
    /**
 
28
     * If the username is "expired" throw an ExpiredPasswordException
 
29
     * to simulate a business exception.
 
30
     * If the username is "arithmetic" throw an Aritmetic exception to
 
31
     * simulate a system exception.
 
32
     * Otherwise, delegate to MemoryDatabase.
 
33
     * @param username
 
34
     * @return
 
35
     */
 
36
    public User findUser(String username) throws ExpiredPasswordException {
 
37
 
 
38
        if ("expired".equals(username)) throw new ExpiredPasswordException("Testing ExpiredPasswordException ...");
 
39
        if ("arithmetic".equals(username)) throw new ArithmeticException();
 
40
        return super.findUser(username);
 
41
    }
 
42
 
 
43
}