1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package lib; 29 30 /** 31 * Status represents a result of a testing activity performed. The result is 32 * described in two ways: state and runtime state. The state describes if the 33 * activity was successful (OK state) or not (FAILED state). The runtime state 34 * describes what happend during the activity: the test can be: 35 * - PASSED - the activity completed normally (although it can complete with 36 * FAILED state) 37 * - SKIPPED - the activity was not performed because of a reason (it also can 38 * has OK or FAILED state) 39 * - EXCEPTION - the activity was abnormally terminated because of an 40 * unexpected exception. It always has a FAILED state. 41 * - EXCLUDED - the activity is expected to fail. The state represents how 42 * the state really completed: OK or FAILED. 43 * - other variants are not formalized now and can be represented by 44 * Status.failed() method. They always have a FAILED state. 45 */ 46 public class Status extends SimpleStatus { 47 48 /** 49 * Construct a status: use runState and state 50 * @param runState: either PASSED, SKIPPED, etc. 51 * @param state: OK or FAILED. 52 */ 53 public Status(int runState, boolean state ) { 54 super(runState, state); 55 } 56 57 /** 58 * Construct a status: use own message and state. 59 * @parame messaeg An own message for the status. 60 * @param state: OK or FAILED. 61 */ 62 public Status(String message, boolean state) { 63 super( message, state ); 64 } 65 66 /** 67 * This is a factory method for creating a Status representing normal 68 * actibity termination. 69 * 70 * @param state describes a test state (OK if state == true, FAILED 71 * otherwise). 72 */ 73 public static Status passed( boolean state ) { 74 return new Status(PASSED, state ); 75 } 76 77 /** 78 * This is a factory method for creating a Status representing an exception 79 * activity termination. The Status alway has FAILED state. 80 * 81 * @param t the exception with that the activity completed. 82 */ 83 public static Status exception( Throwable t ) { 84 return new ExceptionStatus( t ); 85 } 86 87 /** 88 * This is a factory method for creating a Status representing a skipped 89 * activity. 90 * 91 * @param state describes a test state (OK if state == true, FAILED 92 * otherwise). 93 */ 94 public static Status skipped( boolean state ) { 95 return new Status( SKIPPED, state ); 96 } 97 98 /** 99 * This is a factory method for creating a Status representing that the 100 * result of the activity was excluded. It alwas has FAILED state. 101 */ 102 public static Status excluded() { 103 return new Status( EXCLUDED, false ); 104 } 105 106 /** 107 * Creates a Status representing an activity failed for an arbitrary reason. 108 * It always has FAILED state. 109 * 110 * @param reason describes why the activity failed 111 */ 112 public static Status failed(final String reason) { 113 return new Status(reason, FAILED); 114 } 115 116 /** 117 * The method returns a human-readable description of the status. 118 * The Status implementation of the method returns the status state 119 * description and appends to it it the reason, for example: 120 * "FAILED.The getLabel works wrong", "PASSED.OK". 121 */ 122 public String toString() { 123 String str = getRunStateString() + "." + getStateString();; 124 125 return str; 126 } 127 128 /** 129 * Checks whether the status runstate is passed. 130 */ 131 public boolean isPassed() { 132 return getRunState() == PASSED; 133 } 134 135 /** 136 * Checks whether the status runstate is skipped. 137 */ 138 public boolean isSkipped() { 139 return getRunState() == SKIPPED; 140 } 141 142 /** 143 * Checks whether the status runstate is excluded. 144 */ 145 public boolean isExcluded() { 146 return getRunState() == EXCLUDED; 147 } 148 149 /** 150 * Checks whether the status runstate is exception. 151 */ 152 public boolean isException() { 153 return getRunState() == EXCEPTION; 154 } 155 156 /** 157 * Checks whether the status state is failed. 158 */ 159 public boolean isFailed() { 160 return !getState(); 161 } 162 163 /** 164 * Checks whether the status state is ok. 165 */ 166 public boolean isOK() { 167 return getState(); 168 } 169 170 public String getDescription () { 171 return getRunStateString(); 172 } 173 } 174