-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Refine error message in URLUtil::create #13337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
f720746
changes for fix-for-issue-12186
d1d206a
changes for fix-for-issue-12186
eb1bd34
changes for fix-for-issue-12186
69201fb
changes for fix-for-issue-12186
bc74f41
changes for fix-for-issue-12186
d8d3031
changes for fix-for-issue-12186
a8cac36
changes for fix-for-issue-12186
565dfde
changes for fix-for-issue-12186
78f577e
changes for fix-for-issue-12186
23cfe5b
changes for fix-for-issue-12186
20bbd61
changes for fix-for-issue-12186
6d22919
changes for fix-for-issue-12186
45322fa
Fix imports
calixtus bc0da1a
Rewrite
calixtus 34ef825
Checkstyle
calixtus 967b66b
Merge branch 'main' into fir-for-issue-12186
calixtus 69139ee
Collapse catches
subhramit 7091190
Adapt tests, remove messages
subhramit 117bb4f
Add another test, remove nesting, remove another message
subhramit 014d909
Fix openrewrite
subhramit cee1765
Add missing import for `assertNotEquals`
subhramit 70291b5
Add throws to test
subhramit 1fabaa4
Checkstyle
subhramit ef6217a
remove public modifiers
subhramit a9b65ef
Merge branch 'main' into fir-for-issue-12186
calixtus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,18 @@ | ||
| package org.jabref.logic.net; | ||
|
|
||
| import java.net.MalformedURLException; | ||
| import java.net.URI; | ||
| import java.net.URL; | ||
|
|
||
| import org.jabref.logic.util.URLUtil; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| class URLUtilTest { | ||
|
|
@@ -87,4 +92,49 @@ void createUriShouldHandlePipeCharacter() { | |
| URI uri = URLUtil.createUri(input); | ||
| assertEquals("http://example.com/test%7Cfile", uri.toString()); | ||
| } | ||
|
|
||
| @Test | ||
| public void validUrl() throws MalformedURLException { | ||
calixtus marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| String input = "http://example.com"; | ||
|
|
||
| URL result = URLUtil.create(input); | ||
| assertNotNull(result); | ||
| assertNotEquals("", result.toString().trim()); | ||
| assertEquals(input, result.toString()); | ||
| } | ||
|
|
||
| @Test | ||
| public void nullUrl() { | ||
| IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> | ||
| URLUtil.create(null)); | ||
| assertTrue(exception.getMessage().contains("null or empty")); | ||
| } | ||
|
|
||
| @Test | ||
| public void emptyUrl() { | ||
| IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> | ||
| URLUtil.create(" ")); | ||
| assertTrue(exception.getMessage().contains("null or empty")); | ||
| } | ||
|
|
||
| @Test | ||
| public void uriMissingScheme() { | ||
| MalformedURLException exception = assertThrows(MalformedURLException.class, () -> | ||
| URLUtil.create("www.example.com")); | ||
| assertTrue(exception.getMessage().contains("not absolute")); | ||
| } | ||
|
|
||
| @Test | ||
| public void uriMissingHost() { | ||
| MalformedURLException exception = assertThrows(MalformedURLException.class, () -> | ||
| URLUtil.create("mailto:[email protected]")); | ||
| assertTrue(exception.getMessage().contains("must include both scheme and host")); | ||
| } | ||
|
|
||
| @Test | ||
| public void malformedSyntax() { | ||
| MalformedURLException exception = assertThrows(MalformedURLException.class, () -> | ||
| URLUtil.create("http://[invalid-url]")); | ||
| assertTrue(exception.getMessage().contains("Invalid URI")); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.