All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mockit.internal.state.ParameterNames Maven / Gradle / Ivy

Go to download

JMockit is a Java toolkit for automated developer testing. It contains mocking/faking APIs and a code coverage tool, supporting both JUnit and TestNG. The mocking APIs allow all kinds of Java code, without testability restrictions, to be tested in isolation from selected dependencies.

There is a newer version: 1.49
Show newest version
/*
 * Copyright (c) 2006 JMockit developers
 * This file is subject to the terms of the MIT license (see LICENSE.txt).
 */
package mockit.internal.state;

import java.util.*;
import javax.annotation.*;

import mockit.internal.util.*;

public final class ParameterNames
{
   private static final Map> classesToMethodsToParameters = new HashMap>();

   private ParameterNames() {}

   public static boolean hasNamesForClass(@Nonnull String classDesc) {
      return classesToMethodsToParameters.containsKey(classDesc);
   }

   public static void register(@Nonnull String classDesc, @Nonnull String memberName, @Nonnull String memberDesc, @Nonnull String[] names) {
      Map methodsToParameters = classesToMethodsToParameters.get(classDesc);

      if (methodsToParameters == null) {
         methodsToParameters = new HashMap();
         classesToMethodsToParameters.put(classDesc, methodsToParameters);
      }

      String methodKey = memberName + memberDesc;
      methodsToParameters.put(methodKey, names);
   }

   @Nonnull
   public static String getName(@Nonnull TestMethod method, @Nonnegative int index) {
      String name = getName(method.testClassDesc, method.testMethodDesc, index);
      return name == null ? "param" + index : name;
   }

   @Nullable
   public static String getName(@Nonnull String classDesc, @Nonnull String methodDesc, @Nonnegative int index) {
      Map methodsToParameters = classesToMethodsToParameters.get(classDesc);

      if (methodsToParameters == null) {
         return null;
      }

      String[] parameterNames = methodsToParameters.get(methodDesc);
      return parameterNames[index];
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy