/* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package vogar.target.junit; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import junit.framework.AssertionFailedError; import org.junit.runners.BlockJUnit4ClassRunner; import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.InitializationError; import org.junit.runners.model.RunnerBuilder; /** * A specialization of {@link BlockJUnit4ClassRunner} to implement behavior required by Vogar. * *
It overrides a number of methods that are called during normal processing in order to
* avoid throwing a NPE. It also overrides {@link #validatePublicVoidNoArg(boolean, List)} to
* report the method as being missing. It relies on a {@link ValidateMethodStatement} to call
* that method immediately prior to invoking the method.
*/
private static class MissingFrameworkMethod extends FrameworkMethod {
private static final Annotation[] NO_ANNOTATIONS = new Annotation[0];
private static final Method DUMMY_METHOD;
static {
DUMMY_METHOD = Object.class.getMethods()[0];
}
private final String name;
public MissingFrameworkMethod(String name) {
super(DUMMY_METHOD);
this.name = name;
}
@Override
public String getName() {
// Overridden to avoid NPE.
return name;
}
@Override
public void validatePublicVoidNoArg(boolean isStatic, List