ParanamerNameProvider implements ParameterNameProvider { public String[] parameterNamesFor(AccessibleObject method) { try { String[] parameterNames = info.lookupParameterNames(method); if (logger.isDebugEnabled()) { logger.debug("Found parameter names with paranamer for {} as {}", Stringnifier.simpleNameFor(method), Arrays.toString(parameterNames)); } String[] defensiveCopy = new String[parameterNames.length]; System.arraycopy(parameterNames, 0, defensiveCopy, 0, parameterNames.length); return defensiveCopy; } catch (ParameterNamesNotFoundException e) { throw new IllegalStateException("Paranamer were not able to find your parameter names for " + method + "You must compile your code with debug information (javac -g) or register another " + "name provider. Try to use " + DefaultParameterNameProvider.class.getName() + " instead."); } }  String[] parameterNamesFor(AccessibleObject method);  }
@Test public void shouldNameObjectTypeAsItsSimpleName() throws SecurityException, NoSuchMethodException { assertThat(provider.parameterNamesFor(Horse.class.getMethod("runThrough", Field.class))[0], is(equalTo("f"))); }
@Test public void shouldNamePrimitiveTypeAsItsSimpleName() throws SecurityException, NoSuchMethodException { assertThat(provider.parameterNamesFor(Horse.class.getMethod("rest", int.class))[0], is(equalTo("hours"))); }
@Test public void shouldNameArrayAsItsSimpleTypeName() throws SecurityException, NoSuchMethodException { assertThat(provider.parameterNamesFor(Horse.class.getMethod("setLeg", int[].class))[0], is(equalTo("length"))); }
@Test public void shouldNameGenericCollectionUsingOf() throws SecurityException, NoSuchMethodException { assertThat(provider.parameterNamesFor(Cat.class.getDeclaredMethod("fightWith", List.class))[0], is(equalTo("cats"))); }
@Test public void shouldIgnoreChangesToTheReturnedArrayInSubsequentCalls() throws Exception { String[] resultOfFirstCall = provider.parameterNamesFor(Horse.class.getMethod("setLeg", int[].class)); assertThat(resultOfFirstCall[0], is(equalTo("length"))); resultOfFirstCall[0] = "ASDF"; String[] resultOfSecondCall = provider.parameterNamesFor(Horse.class.getMethod("setLeg", int[].class)); assertThat(resultOfSecondCall[0], is(equalTo("length"))); }
@Test public void shouldNameFieldsAnnotatedWithNamed() throws SecurityException, NoSuchMethodException { assertThat(provider.parameterNamesFor(Horse.class.getMethod("runThroughWithAnnotation", Field.class))[0], is(equalTo("one"))); }
@Test public void shouldNotNameFieldsByTheFieldNameWhenUsingAnnotation() throws SecurityException, NoSuchMethodException { assertThat(provider.parameterNamesFor(Horse.class.getMethod("runThroughWithAnnotation", Field.class))[0], is(not(equalTo("field")))); }
@Test public void shouldNameMethodsFieldsWhenAnnotatedOrNot() throws SecurityException, NoSuchMethodException { assertThat(provider.parameterNamesFor(Horse.class.getMethod("runThroughWithAnnotation2", Field.class, Field.class))[0], is(equalTo("one"))); assertThat(provider.parameterNamesFor(Horse.class.getMethod("runThroughWithAnnotation2", Field.class, Field.class))[1], is(equalTo("two"))); }
@Test public void shouldNameMethodsFieldsWhenAnnotatedOrNot2() throws SecurityException, NoSuchMethodException { assertThat(provider.parameterNamesFor(Horse.class.getMethod("runThroughWithAnnotation3", Field.class, Field.class))[0], is(equalTo("one"))); assertThat(provider.parameterNamesFor(Horse.class.getMethod("runThroughWithAnnotation3", Field.class, Field.class))[1], is(equalTo("size"))); }