Handle filter strings being passed by the sessiond
[lttng-ust-java-tests.git] / lttng-ust-java-tests / src / test / java / org / lttng / ust / agent / utils / TestPrintRunner.java
CommitLineData
64c5b50c
AM
1/*
2 * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19package org.lttng.ust.agent.utils;
20
21import org.junit.runner.Description;
22import org.junit.runner.notification.Failure;
23import org.junit.runner.notification.RunListener;
24import org.junit.runner.notification.RunNotifier;
25import org.junit.runners.BlockJUnit4ClassRunner;
26import org.junit.runners.model.InitializationError;
27
28/**
29 * Test runner that will print the name of the test being run to stdout.
30 *
31 * Thanks to http://stackoverflow.com/a/27070843/4227853 for the tips.
32 *
33 * @author Alexandre Montplaisir
34 */
35public class TestPrintRunner extends BlockJUnit4ClassRunner {
36
37 /**
07ecbfdf 38 * Constructor
64c5b50c
AM
39 *
40 * @param klass
41 * @throws InitializationError
42 */
43 public TestPrintRunner(Class<?> klass) throws InitializationError {
44 super(klass);
45 }
46
47 @Override
48 public void run(RunNotifier notifier) {
ebb26270
AM
49 RunListener listener = new TestPrintListener();
50
51 notifier.addListener(listener);
64c5b50c 52 super.run(notifier);
ebb26270 53 notifier.removeListener(listener);
64c5b50c
AM
54 }
55
56 /**
57 * Listener that will print the class and test name to stdout.
58 */
59 public static class TestPrintListener extends RunListener {
60
61 @Override
62 public void testStarted(Description description) {
63 System.out.println("Running " + getTestName(description));
64 }
65
66 @Override
67 public void testAssumptionFailure(Failure failure) {
68 System.out.println("SKIPPING TEST: " + getTestName(failure.getDescription()));
69 System.out.println(failure.getMessage());
70 }
71
72 /**
73 * Get the className#methodName from a Description.
74 */
75 private static String getTestName(Description description) {
76 return description.getClassName() + '#' + description.getMethodName();
77 }
78 }
79
80}
This page took 0.025547 seconds and 4 git commands to generate.