EMMA Coverage Report (generated Wed Feb 13 07:49:24 ICT 2008)
[all classes][net.sourceforge.hiveboard.business]

COVERAGE SUMMARY FOR SOURCE FILE [ValidityChecks.java]

nameclass, %method, %block, %line, %
ValidityChecks.java100% (1/1)80%  (4/5)69%  (110/160)70%  (26/37)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ValidityChecks100% (1/1)80%  (4/5)69%  (110/160)70%  (26/37)
ValidityChecks (): void 0%   (0/1)0%   (0/3)0%   (0/2)
checkMaxValue (int, int, String): void 100% (1/1)44%  (4/9)67%  (2/3)
checkPassword (String): void 100% (1/1)55%  (6/11)67%  (2/3)
checkAccount (Account): void 100% (1/1)70%  (35/50)77%  (10/13)
checkBoard (Board, int, AccountRepository): void 100% (1/1)75%  (65/87)75%  (12/16)

1//  Copyright 2004-2007 Jean-Francois Poilpret
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14 
15package net.sourceforge.hiveboard.business;
16 
17import java.util.HashSet;
18import java.util.Set;
19 
20import net.sourceforge.hiveboard.Account;
21import net.sourceforge.hiveboard.Board;
22import net.sourceforge.hiveboard.DoesNotExistException;
23 
24final public class ValidityChecks
25{
26        private ValidityChecks()
27        {
28        }
29        
30        static public void        checkAccount(Account account)
31        {
32                if (account.getVisa() == null || account.getVisa().length() == 0)
33                {
34                        throw new IllegalArgumentException("Account Visa must not be null");
35                }
36                if (account.getName() == null || account.getName().length() == 0)
37                {
38                        throw new IllegalArgumentException("Account Name must not be null");
39                }
40                if (account.getRole() == null)
41                {
42                        throw new IllegalArgumentException("Account Role must not be null");
43                }
44                String email = account.getEmail();
45                if (email != null)
46                {
47                        email = email.trim();
48                        if (email.equals(""))
49                        {
50                                email = null;
51                        }
52                        account.setEmail(email);
53                }
54        }
55        
56        static public void        checkBoard(Board board, int maxSize, AccountRepository accounts)
57        {
58                // Check size
59                checkMaxValue(        board.getWidth(), maxSize, 
60                                                "Board width must be less than " + maxSize);
61                checkMaxValue(        board.getHeight(), maxSize, 
62                                                "Board height must be less than " + maxSize);
63                String desc = board.getDescription();
64                if (desc != null && desc.trim().equals(""))
65                {
66                        board.setDescription(null);
67                }
68                Set<Integer> participants = board.getParticipants();
69                if (participants == null)
70                {
71                        participants = new HashSet<Integer>();
72                        board.setParticipants(participants);
73                }
74                participants.add(board.getInitiator());
75                if (participants != null)
76                {
77                        for (int id: participants)
78                        {
79                                if (accounts.getAccount(id, false) == null)
80                                {
81                                        throw new DoesNotExistException("Unknown participant id " + id);
82                                }
83                        }
84                }
85        }
86        
87        static public void        checkPassword(String password)
88        {
89                if (password == null || password.length() == 0)
90                {
91                        throw new IllegalArgumentException("Password must not be null");
92                }
93        }
94 
95        static public void        checkMaxValue(int value, int max, String error)
96        {
97                if (value > max)
98                {
99                        throw new IllegalArgumentException(error);
100                }
101        }
102}

[all classes][net.sourceforge.hiveboard.business]
EMMA 2.0.5312 (C) Vladimir Roubtsov