001/* 002 * Copyright 2013 Brian Thomas Matthews 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package ca.uhn.fhir.test.utilities; 018 019/*- 020 * #%L 021 * HAPI FHIR Test Utilities 022 * %% 023 * Copyright (C) 2014 - 2023 Smile CDR, Inc. 024 * %% 025 * Licensed under the Apache License, Version 2.0 (the "License"); 026 * you may not use this file except in compliance with the License. 027 * You may obtain a copy of the License at 028 * 029 * http://www.apache.org/licenses/LICENSE-2.0 030 * 031 * Unless required by applicable law or agreed to in writing, software 032 * distributed under the License is distributed on an "AS IS" BASIS, 033 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 034 * See the License for the specific language governing permissions and 035 * limitations under the License. 036 * #L% 037 */ 038 039import org.junit.jupiter.api.extension.AfterEachCallback; 040import org.junit.jupiter.api.extension.BeforeEachCallback; 041import org.junit.jupiter.api.extension.ExtensionContext; 042import org.slf4j.Logger; 043import org.slf4j.LoggerFactory; 044 045import java.text.MessageFormat; 046 047/** 048 * This JUnit rule generates log messages to delineate the start and finish of a JUnit test case and also to note any exceptions 049 * that are thrown. 050 * 051 * @author <a href="mailto:brian@btmatthews.com">Brian Matthews</a> 052 * @version 1.0.0 053 */ 054public class LoggingExtension implements BeforeEachCallback, AfterEachCallback { 055 056 @Override 057 public void afterEach(ExtensionContext context) { 058 final Logger logger = LoggerFactory.getLogger(context.getTestClass().get()); 059 logger.info(MessageFormat.format("Finished test case [{0}]", context.getTestMethod().get().getName())); 060 } 061 062 @Override 063 public void beforeEach(ExtensionContext context) { 064 final Logger logger = LoggerFactory.getLogger(context.getTestClass().get()); 065 logger.info(MessageFormat.format("Starting test case [{0}]", context.getTestMethod().get().getName())); 066 } 067}