001package org.conqat.lib.commons.test;
002
003import java.util.Collections;
004import java.util.List;
005import java.util.Set;
006
007import org.conqat.lib.commons.collections.CollectionUtils;
008import org.conqat.lib.commons.resources.Resource;
009import org.junit.platform.launcher.TestExecutionListener;
010import org.junit.platform.launcher.TestPlan;
011
012/**
013 * Test listener that prints all the unused resources to console after tests
014 * have finished. The listener is registered via the service loader mechanism in
015 * META-INF/services/org.junit.platform.launcher.TestExecutionListener. The
016 * results are only printed on the CI server as data is normally incomplete when
017 * running single tests locally.
018 */
019public class UnusedResourcesChecker implements TestExecutionListener {
020
021        @Override
022        public void testPlanExecutionFinished(TestPlan testPlan) {
023                Set<Resource> unusedResources = TestDataManager.getUnusedResources();
024                if (unusedResources.size() == 0 || !TestUtils.isExecutionOnCiServer()) {
025                        return;
026                }
027                System.err.println(unusedResources.size() + " unused test resources");
028                List<String> fileList = CollectionUtils.map(unusedResources, Resource::getAbsolutePath);
029                Collections.sort(fileList);
030                for (String fileName : fileList) {
031                        System.err.println(" - " + fileName);
032                }
033        }
034}