git clone of logicmail with some fixes/features added
1/*-
2 * Copyright (c) 2010, Derek Konigsberg
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the project nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29 * OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32package j2meunit.rimui;
33
34import j2meunit.framework.TestCase;
35import j2meunit.framework.TestFailure;
36import net.rim.device.api.ui.component.RichTextField;
37import net.rim.device.api.ui.component.SeparatorField;
38import net.rim.device.api.ui.container.MainScreen;
39
40/**
41 * This screen shows test results for a single TestCase
42 * @author Derek Konigsberg
43 */
44public class TestResultsScreen extends MainScreen {
45 private TestCase testCase;
46 private TestFailure testFailure;
47 private TestFailure testError;
48
49 /**
50 * Creates a new instance of TestResultsScreen.
51 * It is normally expected that an unsuccessful test will produce
52 * either an error or a failure. Since they are both the same type,
53 * they are passed as separate parameters, and passing both is possible.
54 *
55 * @param testCase The test case being viewed
56 * @param testFailure The failure object
57 * @param testError The error object
58 */
59 public TestResultsScreen(TestCase testCase, TestFailure testFailure, TestFailure testError) {
60 this.testCase = testCase;
61 this.testFailure = testFailure;
62 this.testError = testError;
63 initializeFields();
64 }
65
66 /**
67 * Initialize the screen fields.
68 */
69 private void initializeFields() {
70 add(new RichTextField(testCase.getName(), RichTextField.TEXT_ALIGN_HCENTER));
71 if(testFailure != null) {
72 add(new SeparatorField());
73 add(new RichTextField("Failure:", RichTextField.TEXT_ALIGN_HCENTER));
74 RichTextField messageField = new RichTextField(testFailure.thrownException().getMessage());
75 messageField.setEditable(false);
76 add(messageField);
77 }
78 if(testError != null) {
79 add(new SeparatorField());
80 add(new RichTextField("Error:", RichTextField.TEXT_ALIGN_HCENTER));
81 RichTextField messageField = new RichTextField(testError.thrownException().getMessage());
82 messageField.setEditable(false);
83 add(messageField);
84 }
85 if(testFailure == null && testError == null) {
86 add(new SeparatorField());
87 add(new RichTextField("Test successful", RichTextField.TEXT_ALIGN_HCENTER));
88 }
89 }
90}