Line data Source code
1 : // Copyright (C) 2019 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.testing; 16 : 17 : import com.google.common.base.CharMatcher; 18 : import org.junit.BeforeClass; 19 : import org.junit.rules.TestName; 20 : import org.junit.rules.TestRule; 21 : import org.junit.runner.Description; 22 : import org.junit.runners.model.Statement; 23 : 24 6 : public class GerritTestName implements TestRule { 25 6 : private final TestName delegate = new TestName(); 26 : 27 : @BeforeClass 28 : public static void beforeClassTest() { 29 0 : TestLoggingActivator.configureLogging(); 30 0 : } 31 : 32 : public String getSanitizedMethodName() { 33 6 : String name = delegate.getMethodName().toLowerCase(); 34 6 : name = 35 6 : CharMatcher.inRange('a', 'z') 36 6 : .or(CharMatcher.inRange('A', 'Z')) 37 6 : .or(CharMatcher.inRange('0', '9')) 38 6 : .negate() 39 6 : .replaceFrom(name, '_'); 40 6 : name = CharMatcher.is('_').trimTrailingFrom(name); 41 6 : return name; 42 : } 43 : 44 : @Override 45 : public Statement apply(Statement base, Description description) { 46 6 : return delegate.apply(base, description); 47 : } 48 : }