• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2023 Code Intelligence GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.code_intelligence.jazzer.junit;
18 
19 import static org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod;
20 
21 import java.lang.reflect.Method;
22 
23 /**
24  * Small class that allows us to capture the methods that we're using as test data. We need similar
25  * but slightly different data at various points:
26  * 1. the method name with parameters for finding the method initially and for referring to it in
27  * JUnit
28  * 2. the method name without parameters for the findings directories
29  */
30 public class TestMethod {
31   Method method;
32   String nameWithParams;
33 
TestMethod(String className, String methodName)34   TestMethod(String className, String methodName) {
35     nameWithParams = methodName;
36     method = selectMethod(className + "#" + methodName).getJavaMethod();
37   }
38 
39   /**
40    * Returns the {@link org.junit.platform.engine.TestDescriptor} ID for this method
41    */
getDescriptorId()42   String getDescriptorId() {
43     return "test-template:" + nameWithParams;
44   }
45 
46   /**
47    * Returns just the name of the method without parameters
48    */
getName()49   String getName() {
50     return method.getName();
51   }
52 }
53