forked from michaelmccaskill/plugin-site-api
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 #89 from halkeye/add-new-exception-for-jira-compon…
…ent-mismatch Add a new exception type specifically for jira component name not found exceptions
- Loading branch information
Showing
4 changed files
with
71 additions
and
7 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
36 changes: 36 additions & 0 deletions
36
src/main/java/io/jenkins/plugins/models/MissingJiraComponentException.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,36 @@ | ||
package io.jenkins.plugins.models; | ||
|
||
import java.util.Objects; | ||
|
||
public class MissingJiraComponentException extends Exception { | ||
private final String pluginName; | ||
private final String componentName; | ||
|
||
public MissingJiraComponentException(String pluginName, String componentName) { | ||
super(String.format("ComponentName(%s) and PluginName(%s) do not match.", componentName, pluginName)); | ||
this.pluginName = pluginName; | ||
this.componentName = componentName; | ||
} | ||
|
||
public String getPluginName() { | ||
return pluginName; | ||
} | ||
|
||
public String getComponentName() { | ||
return componentName; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof MissingJiraComponentException)) return false; | ||
MissingJiraComponentException that = (MissingJiraComponentException) o; | ||
return Objects.equals(pluginName, that.pluginName) && Objects.equals(componentName, that.componentName); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(pluginName, componentName); | ||
} | ||
|
||
} |
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
27 changes: 27 additions & 0 deletions
27
src/test/java/io/jenkins/plugins/models/MissingJiraComponentExceptionTest.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,27 @@ | ||
package io.jenkins.plugins.models; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class MissingJiraComponentExceptionTest { | ||
@Test | ||
public void testMessage() { | ||
MissingJiraComponentException sot = new MissingJiraComponentException("plugin-git", "component-git"); | ||
assertEquals( | ||
"ComponentName(component-git) and PluginName(plugin-git) do not match.", | ||
sot.getMessage() | ||
); | ||
} | ||
|
||
@Test | ||
public void testEquals() { | ||
MissingJiraComponentException sot1 = new MissingJiraComponentException("plugin-git", "component-git"); | ||
MissingJiraComponentException sot2 = new MissingJiraComponentException("plugin-git", "component-git"); | ||
assertEquals( | ||
sot1, | ||
sot2 | ||
); | ||
} | ||
|
||
} |