Skip to content

Commit

Permalink
"fully qualified" polishing
Browse files Browse the repository at this point in the history
Although both variants are correct, this commit ensures that we
consistently use "fully qualified" instead of "fully-qualified" for
"fully qualified class name" etc.
  • Loading branch information
sbrannen committed Apr 15, 2024
1 parent 5ee7580 commit 52458c0
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ repository on GitHub.

* New `@FieldSource` annotation for use with `@ParameterizedTest` methods which allows
you to source arguments from a local field or an external field referenced by
fully-qualified field name. This feature is similar to the existing `@MethodSource`
fully qualified field name. This feature is similar to the existing `@MethodSource`
feature. See the
<<../user-guide/index.adoc#writing-tests-parameterized-tests-sources-FieldSource, User
Guide>> for details.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1619,7 +1619,7 @@ Note that `arguments(Object...)` is a static factory method defined in the
====

An external, `static` `@FieldSource` field can be referenced by providing its
_fully-qualified field name_ as demonstrated in the following example.
_fully qualified field name_ as demonstrated in the following example.

[source,java,indent=0]
----
Expand Down
4 changes: 2 additions & 2 deletions documentation/src/test/java/example/RepeatedTestsDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.junit.jupiter.api.TestInfo;

// end::user_guide[]
// Use fully-qualified names to avoid having them show up in the imports.
// Use fully qualified names to avoid having them show up in the imports.
@org.junit.jupiter.api.parallel.Execution(org.junit.jupiter.api.parallel.ExecutionMode.SAME_THREAD)
// tag::user_guide[]
class RepeatedTestsDemo {
Expand Down Expand Up @@ -53,7 +53,7 @@ void repeatedTestWithRepetitionInfo(RepetitionInfo repetitionInfo) {
}

// end::user_guide[]
// Use fully-qualified name to avoid having it show up in the imports.
// Use fully qualified name to avoid having it show up in the imports.
@org.junit.jupiter.api.Disabled("intentional failures would break the build")
// tag::user_guide[]
@RepeatedTest(value = 8, failureThreshold = 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* {@code @FieldSource} is an {@link ArgumentsSource} which provides access to
* values of {@linkplain #value() fields} of the class in which this annotation
* is declared or from static fields in external classes referenced by
* <em>fully-qualified field name</em>.
* <em>fully qualified field name</em>.
*
* <p>Each field must be able to supply a <em>stream</em> of <em>arguments</em>,
* and each set of "arguments" within the "stream" will be provided as the physical
Expand Down Expand Up @@ -121,7 +121,7 @@
* The names of fields within the test class or in external classes to use
* as sources for arguments.
*
* <p>Fields in external classes must be referenced by <em>fully-qualified
* <p>Fields in external classes must be referenced by <em>fully qualified
* field name</em> &mdash; for example,
* {@code "com.example.WebUtils#httpMethodNames"} or
* {@code "com.example.TopLevelClass$NestedClass#numbers"} for a field in a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ private static Method findFactoryMethod(Class<?> testClass, Method testMethod, S
return findFactoryMethodBySimpleName(testClass, testMethod, factoryMethodName);
}

// Convert local factory method name to fully-qualified method name.
// Convert local factory method name to fully qualified method name.
if (!looksLikeAFullyQualifiedMethodName(factoryMethodName)) {
factoryMethodName = testClass.getName() + "#" + factoryMethodName;
}

// Find factory method using fully-qualified name.
// Find factory method using fully qualified name.
Method factoryMethod = findFactoryMethodByFullyQualifiedName(testClass, testMethod, factoryMethodName);

// Ensure factory method has a valid return type and is not a test method.
Expand All @@ -96,9 +96,9 @@ private static boolean looksLikeAFullyQualifiedMethodName(String factoryMethodNa
return indexOfFirstDot < indexOfLastOpeningParenthesis;
}
// If we get this far, we conclude the supplied factory method name "looks"
// like it was intended to be a fully-qualified method name, even if the
// like it was intended to be a fully qualified method name, even if the
// syntax is invalid. We do this in order to provide better diagnostics for
// the user when a fully-qualified method name is in fact invalid.
// the user when a fully qualified method name is in fact invalid.
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
* to use as sources for arguments.
*
* <p>Factory methods in external classes must be referenced by
* <em>fully-qualified method name</em> &mdash; for example,
* <em>fully qualified method name</em> &mdash; for example,
* {@code "com.example.StringsProviders#blankStrings"} or
* {@code "com.example.TopLevelClass$NestedClass#classMethod"} for a factory
* method in a static nested class.
Expand All @@ -123,7 +123,7 @@
* you can supply the formal parameter list in the qualified method name to
* disambiguate between overloaded variants of the factory method. For example,
* {@code "blankStrings(int)"} for a local qualified method name or
* {@code "com.example.StringsProviders#blankStrings(int)"} for a fully-qualified
* {@code "com.example.StringsProviders#blankStrings(int)"} for a fully qualified
* method name.
*
* <p>If no factory method names are declared, a method within the test class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,19 @@ private static void assertStaticIsRequired(PreconditionViolationException except
}

@Test
void throwsExceptionWhenFullyQualifiedFieldNameSyntaxIsInvalid() {
void throwsExceptionWhenFullyQualifiedFieldNameIsMissingFieldName() {
String fieldName = "org.example.wrongSyntax#"; // missing "fieldName"
var exception = assertThrows(PreconditionViolationException.class,
() -> provideArguments(fieldName).toArray());

assertThat(exception.getMessage()).isEqualTo("""
[%s] is not a valid fully qualified field name: \
it must start with a fully qualified class name followed by a \
'#' and then the field name.""", fieldName, TestCase.class.getName());
}

@Test
void throwsExceptionWhenFullyQualifiedFieldNameIsMissingHashAndFieldName() {
String fieldName = "org.example.wrongSyntax"; // missing "#fieldName"
var exception = assertThrows(PreconditionViolationException.class,
() -> provideArguments(fieldName).toArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static Condition<Event> test() {
* {@link Event}'s {@linkplain Event#getTestDescriptor() test descriptor} is
* a {@linkplain TestDescriptor#isContainer() container} and its
* {@linkplain TestDescriptor#getUniqueId() unique id} contains the
* fully-qualified name of the supplied {@link Class}.
* fully qualified name of the supplied {@link Class}.
*/
public static Condition<Event> container(Class<?> clazz) {
Preconditions.notNull(clazz, "Class must not be null");
Expand Down

0 comments on commit 52458c0

Please sign in to comment.