Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
JunitTracer.java
Go to the documentation of this file.
1/**
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2021 Gothel Software e.K.
4 * Copyright (c) 2011 Gothel Software e.K.
5 * Copyright (c) 2011 JogAmp Community.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining
8 * a copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27package jau.test.junit.util;
28
29import java.io.BufferedReader;
30import java.io.IOException;
31import java.io.InputStreamReader;
32
33import org.junit.Assume;
34import org.junit.Before;
35import org.junit.BeforeClass;
36import org.junit.After;
37import org.junit.AfterClass;
38import org.junit.FixMethodOrder;
39import org.junit.Rule;
40import org.junit.rules.TestName;
41import org.junit.runners.MethodSorters;
42
43
44@FixMethodOrder(MethodSorters.NAME_ASCENDING)
45public abstract class JunitTracer {
46 @Rule public final TestName _unitTestName = new TestName();
47
48 static volatile boolean testSupported = true;
49
50 public static final boolean isTestSupported() {
51 return testSupported;
52 }
53
54 public static final void setTestSupported(final boolean v) {
55 System.err.println("setTestSupported: "+v);
56 testSupported = v;
57 }
58
59 public final String getTestMethodName() {
60 return _unitTestName.getMethodName();
61 }
62
63 public final String getSimpleTestName(final String separator) {
64 return getClass().getSimpleName()+separator+getTestMethodName();
65 }
66
67 public final String getFullTestName(final String separator) {
68 return getClass().getName()+separator+getTestMethodName();
69 }
70
71 @BeforeClass
72 public static final void oneTimeSetUpBase() {
73 // one-time initialization code
74 }
75
76 @AfterClass
77 public static final void oneTimeTearDownBase() {
78 // one-time cleanup code
79 System.gc(); // force cleanup
80 }
81
82 @Before
83 public final void setUpBase() {
84 System.err.print("++++ TestCase.setUp: "+getFullTestName(" - "));
85 if(!testSupported) {
86 System.err.println(" - "+unsupportedTestMsg);
87 Assume.assumeTrue(testSupported);
88 }
89 System.err.println();
90 }
91
92 @After
93 public final void tearDownBase() {
94 System.err.println("++++ TestCase.tearDown: "+getFullTestName(" - "));
95 }
96
97 static final String unsupportedTestMsg = "Test not supported on this platform.";
98
99 public static void waitForKey(final String preMessage) {
100 final BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
101 System.err.println(preMessage+"> Press enter to continue");
102 try {
103 System.err.println(stdin.readLine());
104 } catch (final IOException e) { e.printStackTrace(); }
105 }
106}
107
static void waitForKey(final String preMessage)
static final void oneTimeSetUpBase()
static final boolean isTestSupported()
final String getFullTestName(final String separator)
static final void setTestSupported(final boolean v)
final String getSimpleTestName(final String separator)
static final void oneTimeTearDownBase()