Skip to content

Commit

Permalink
Merge pull request #31612 from PiotrFLEURY
Browse files Browse the repository at this point in the history
* pr/31612:
  Polish "Provide invalid class name in exception message"
  Provide invalid class name in exception message

Closes gh-31612
  • Loading branch information
snicoll committed Nov 15, 2023
2 parents 05c3ffb + d93114d commit 51cdff5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -161,7 +161,8 @@ default void addFile(Kind kind, String path, ThrowingConsumer<Appendable> conten

private static String getClassNamePath(String className) {
Assert.hasLength(className, "'className' must not be empty");
Assert.isTrue(isJavaIdentifier(className), "'className' must be a valid identifier");
Assert.isTrue(isJavaIdentifier(className),
"'className' must be a valid identifier, got '" + className + "'");
return ClassUtils.convertClassNameToResourcePath(className) + ".java";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -78,7 +78,7 @@ void addSourceFileWithCharSequenceWhenClassNameIsInvalidThrowsException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> this.generatedFiles
.addSourceFile("com/example/HelloWorld.java", "{}"))
.withMessage("'className' must be a valid identifier");
.withMessage("'className' must be a valid identifier, got 'com/example/HelloWorld.java'");
}

@Test
Expand Down

0 comments on commit 51cdff5

Please sign in to comment.