1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package lib; 25 26 /** 27 * Status represents a result of a testing activity performed. The result is 28 * described in two ways: state and runtime state. The state describes if the 29 * activity was successful (OK state) or not (FAILED state). The runtime state 30 * describes what happend during the activity: the test can be: 31 * - PASSED - the activity completed normally (although it can complete with 32 * FAILED state) 33 * - SKIPPED - the activity was not performed because of a reason (it also can 34 * has OK or FAILED state) 35 * - EXCEPTION - the activity was abnormally terminated because of an 36 * unexpected exception. It always has a FAILED state. 37 * - EXCLUDED - the activity is expected to fail. The state represents how 38 * the state really completed: OK or FAILED. 39 * - other variants are not formalized now and can be represented by 40 * Status.failed() method. They always have a FAILED state. 41 */ 42 public class Status extends SimpleStatus { 43 44 /** 45 * Construct a status: use runState and state 46 * @param runState: either PASSED, SKIPPED, etc. 47 * @param state: OK or FAILED. 48 */ 49 public Status(int runState, boolean state ) { 50 super(runState, state); 51 } 52 53 /** 54 * Construct a status: use own message and state. 55 * @parame messaeg An own message for the status. 56 * @param state: OK or FAILED. 57 */ 58 public Status(String message, boolean state) { 59 super( message, state ); 60 } 61 62 /** 63 * This is a factory method for creating a Status representing normal 64 * actibity termination. 65 * 66 * @param state describes a test state (OK if state == true, FAILED 67 * otherwise). 68 */ 69 public static Status passed( boolean state ) { 70 return new Status(PASSED, state ); 71 } 72 73 /** 74 * This is a factory method for creating a Status representing an exception 75 * activity termination. The Status alway has FAILED state. 76 * 77 * @param t the exception with that the activity completed. 78 */ 79 public static Status exception( Throwable t ) { 80 return new ExceptionStatus( t ); 81 } 82 83 /** 84 * This is a factory method for creating a Status representing a skipped 85 * activity. 86 * 87 * @param state describes a test state (OK if state == true, FAILED 88 * otherwise). 89 */ 90 public static Status skipped( boolean state ) { 91 return new Status( SKIPPED, state ); 92 } 93 94 /** 95 * This is a factory method for creating a Status representing that the 96 * result of the activity was excluded. It alwas has FAILED state. 97 */ 98 public static Status excluded() { 99 return new Status( EXCLUDED, false ); 100 } 101 102 /** 103 * Creates a Status representing an activity failed for an arbitrary reason. 104 * It always has FAILED state. 105 * 106 * @param reason describes why the activity failed 107 */ 108 public static Status failed(final String reason) { 109 return new Status(reason, FAILED); 110 } 111 112 /** 113 * The method returns a human-readable description of the status. 114 * The Status implementation of the method returns the status state 115 * description and appends to it it the reason, for example: 116 * "FAILED.The getLabel works wrong", "PASSED.OK". 117 */ 118 public String toString() { 119 String str = getRunStateString() + "." + getStateString(); 120 121 return str; 122 } 123 124 /** 125 * Checks whether the status runstate is passed. 126 */ 127 public boolean isPassed() { 128 return getRunState() == PASSED; 129 } 130 131 /** 132 * Checks whether the status runstate is skipped. 133 */ 134 public boolean isSkipped() { 135 return getRunState() == SKIPPED; 136 } 137 138 /** 139 * Checks whether the status runstate is excluded. 140 */ 141 public boolean isExcluded() { 142 return getRunState() == EXCLUDED; 143 } 144 145 /** 146 * Checks whether the status runstate is exception. 147 */ 148 public boolean isException() { 149 return getRunState() == EXCEPTION; 150 } 151 152 /** 153 * Checks whether the status state is failed. 154 */ 155 public boolean isFailed() { 156 return !getState(); 157 } 158 159 /** 160 * Checks whether the status state is ok. 161 */ 162 public boolean isOK() { 163 return getState(); 164 } 165 166 public String getDescription () { 167 return getRunStateString(); 168 } 169 } 170