2 * Copyright (C) 2022, EfficiOS Inc.
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.
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.
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.
19 package org
.lttng
.ust
.agent
.utils
;
21 import java
.util
.Optional
;
23 import org
.junit
.jupiter
.api
.extension
.AfterTestExecutionCallback
;
24 import org
.junit
.jupiter
.api
.extension
.BeforeTestExecutionCallback
;
25 import org
.junit
.jupiter
.api
.extension
.ExtensionContext
;
26 import org
.junit
.jupiter
.api
.extension
.ExtensionContext
.Namespace
;
27 import org
.junit
.jupiter
.api
.extension
.ExtensionContext
.Store
;
28 import org
.junit
.jupiter
.api
.extension
.TestWatcher
;
31 * Test extension that will print the name of the test being run to stdout.
33 public class TestPrintExtension
implements BeforeTestExecutionCallback
, AfterTestExecutionCallback
, TestWatcher
{
35 private static final String START_TIME
= "start time";
39 public void beforeTestExecution(ExtensionContext context
) throws Exception
{
40 System
.out
.println("\nStarted " + context
.getDisplayName() + "\n");
41 getStore(context
).put(START_TIME
, Long
.valueOf(System
.currentTimeMillis()));
45 public void afterTestExecution(ExtensionContext context
) throws Exception
{
46 long startTime
= getStore(context
).remove(START_TIME
, long.class).longValue();
47 long duration
= System
.currentTimeMillis() - startTime
;
49 System
.out
.println("\nEnded " + context
.getDisplayName() + " in " + duration
+ " ms\n");
53 public void testDisabled(ExtensionContext context
, Optional
<String
> reason
) {
54 System
.out
.println("\nSKIPPING TEST: " + context
.getDisplayName() + "\n");
57 private Store
getStore(ExtensionContext context
) {
58 return context
.getStore(Namespace
.create(getClass(), context
.getRequiredTestMethod()));