Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from lanwen/JENKINS-30242_fix
[FIXES JENKINS-30242] don't cast object in converter to string
- Loading branch information
Showing
2 changed files
with
92 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
70 changes: 70 additions & 0 deletions
70
src/test/java/hudson/plugins/jira/EmptyFriendlyURLConverterTest.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package hudson.plugins.jira; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
import org.hamcrest.Matchers; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.WithoutJenkins; | ||
|
||
import java.net.URL; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.nullValue; | ||
|
||
/** | ||
* @author lanwen (Merkushev Kirill) | ||
*/ | ||
public class EmptyFriendlyURLConverterTest { | ||
|
||
public static final String SOME_VALID_URL = "http://localhost/"; | ||
|
||
@Rule | ||
public JenkinsRule jRule = new JenkinsRule(); | ||
|
||
@Test | ||
@WithoutJenkins | ||
public void shouldHandleURLClass() throws Exception { | ||
URL someUrl = new URL(SOME_VALID_URL); | ||
assertThat(new JiraProjectProperty.DescriptorImpl.EmptyFriendlyURLConverter() | ||
.convert(URL.class, someUrl), Matchers.<Object>is(someUrl)); | ||
} | ||
|
||
@Test | ||
@WithoutJenkins | ||
public void shouldHandleStringClass() throws Exception { | ||
assertThat(new JiraProjectProperty.DescriptorImpl.EmptyFriendlyURLConverter() | ||
.convert(URL.class, SOME_VALID_URL), Matchers.<Object>is(new URL(SOME_VALID_URL))); | ||
} | ||
|
||
@Test | ||
@WithoutJenkins | ||
public void shouldHandleNull() throws Exception { | ||
assertThat(new JiraProjectProperty.DescriptorImpl.EmptyFriendlyURLConverter() | ||
.convert(URL.class, null), nullValue()); | ||
} | ||
|
||
@Test | ||
@WithoutJenkins | ||
public void shouldHandleEmptyString() throws Exception { | ||
assertThat(new JiraProjectProperty.DescriptorImpl.EmptyFriendlyURLConverter() | ||
.convert(URL.class, StringUtils.EMPTY), nullValue()); | ||
} | ||
|
||
@Test | ||
@WithoutJenkins | ||
public void shouldHandleNullAsString() throws Exception { | ||
assertThat(new JiraProjectProperty.DescriptorImpl.EmptyFriendlyURLConverter() | ||
.convert(URL.class, "null"), nullValue()); | ||
} | ||
|
||
/** | ||
* Requires jenkins rule because of LOGGER usage starts descriptor creating | ||
*/ | ||
@Test | ||
public void shouldHandleMalformedUrlAsString() throws Exception { | ||
assertThat(new JiraProjectProperty.DescriptorImpl.EmptyFriendlyURLConverter() | ||
.convert(URL.class, "bla"), nullValue()); | ||
} | ||
|
||
} |