diff options
Diffstat (limited to 'qadevOOo/runner/lib/Status.java')
-rw-r--r-- | qadevOOo/runner/lib/Status.java | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/qadevOOo/runner/lib/Status.java b/qadevOOo/runner/lib/Status.java new file mode 100644 index 0000000000..ae7f97ecfd --- /dev/null +++ b/qadevOOo/runner/lib/Status.java @@ -0,0 +1,128 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package lib; + +/** + * Status represents a result of a testing activity performed. The result is + * described in two ways: state and runtime state. The state describes if the + * activity was successful (OK state) or not (FAILED state). The runtime state + * describes what happened during the activity: the test can be: + * - COMPLETED - the activity completed normally (although it can complete with + * FAILED state) + * - SKIPPED - the activity was not performed because of a reason (it also can + * has OK or FAILED state) + * - EXCEPTION - the activity was abnormally terminated because of an + * unexpected exception. It always has a FAILED state. + * - EXCLUDED - the activity is expected to fail. The state represents how + * the state really completed: OK or FAILED. + * - other variants are not formalized now and can be represented by + * Status.failed() method. They always have a FAILED state. + */ +public class Status extends SimpleStatus { + + /** + * Construct a status: use runState and state + * @param runState either COMPLETED, SKIPPED, etc. + * @param bSuccessful OK or FAILED. + */ + public Status(RunState runState, boolean bSuccessful ) { + super(runState, bSuccessful); + } + + /** + * Construct a status: use own message and state. + * @param message An own message for the status. + * @param bSuccessful OK or FAILED. + */ + public Status(String message, boolean state) { + super( message, state ); + } + + /** + * This is a factory method for creating a Status representing normal + * activity termination. + * + * @param bSuccessful describes a test state (OK if state == true, FAILED + * otherwise). + */ + public static Status passed( boolean bSuccessful ) { + return new Status(RunState.COMPLETED, bSuccessful ); + } + + /** + * This is a factory method for creating a Status representing an exception + * activity termination. The Status always has FAILED state. + * + * @param t the exception with that the activity completed. + */ + public static Status exception( Throwable t ) { + return new ExceptionStatus( t ); + } + + /** + * This is a factory method for creating a Status representing a skipped + * activity. + * + * @param state describes a test state (OK if state == true, FAILED + * otherwise). + */ + public static Status skipped( boolean bSuccessful ) { + return new Status( RunState.SKIPPED, bSuccessful ); + } + + + + /** + * Creates a Status representing an activity failed for an arbitrary reason. + * It always has FAILED state. + * + * @param reason describes why the activity failed + */ + public static Status failed(final String reason) { + return new Status(reason, false/*bSuccessful*/); + } + + /** + * The method returns a human-readable description of the status. + * The Status implementation of the method returns the status state + * description and appends to it the reason, for example: + * "FAILED.The getLabel works wrong", "COMPLETED.OK". + */ + @Override + public String toString() { + String str = getRunStateString() + "." + getStateString(); + + return str; + } + + /** + * Checks whether the status runstate is completed. + */ + public boolean isCompleted() { + return getRunState() == RunState.COMPLETED; + } + + /** + * Checks whether the status state is failed. + */ + public boolean isFailed() { + return !isSuccessful(); + } + +} |