This repository has been archived by the owner on May 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
153 additions
and
94 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
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
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
33 changes: 33 additions & 0 deletions
33
src/main/java/uk/gov/justice/framework/command/client/ReturnCodeFactory.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,33 @@ | ||
package uk.gov.justice.framework.command.client; | ||
|
||
import uk.gov.justice.framework.command.client.io.ToConsolePrinter; | ||
import uk.gov.justice.services.jmx.system.command.client.MBeanClientConnectionException; | ||
import uk.gov.justice.services.jmx.system.command.client.connection.JmxAuthenticationException; | ||
|
||
import javax.inject.Inject; | ||
|
||
public class ReturnCodeFactory { | ||
|
||
private static final int AUTHENTICATION_CODE = 1; | ||
private static final int CONNECTION_FAILED = 2; | ||
private static final int EXCEPTION_OCCURRED = 3; | ||
|
||
@Inject | ||
private ToConsolePrinter toConsolePrinter; | ||
|
||
public int createFor(final Exception exception) { | ||
|
||
if (exception instanceof JmxAuthenticationException) { | ||
toConsolePrinter.println("Authentication failed. Please ensure your username and password are correct"); | ||
return AUTHENTICATION_CODE; | ||
} | ||
|
||
if (exception instanceof MBeanClientConnectionException) { | ||
toConsolePrinter.println(exception.getMessage()); | ||
return CONNECTION_FAILED; | ||
} | ||
|
||
toConsolePrinter.println(exception.getMessage()); | ||
return EXCEPTION_OCCURRED; | ||
} | ||
} |
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
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
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
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
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
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
56 changes: 56 additions & 0 deletions
56
src/test/java/uk/gov/justice/framework/command/client/ReturnCodeFactoryTest.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,56 @@ | ||
package uk.gov.justice.framework.command.client; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import uk.gov.justice.framework.command.client.io.ToConsolePrinter; | ||
import uk.gov.justice.services.jmx.system.command.client.MBeanClientConnectionException; | ||
import uk.gov.justice.services.jmx.system.command.client.connection.JmxAuthenticationException; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ReturnCodeFactoryTest { | ||
|
||
@Mock | ||
private ToConsolePrinter toConsolePrinter; | ||
|
||
@InjectMocks | ||
private ReturnCodeFactory returnCodeFactory; | ||
|
||
@Test | ||
public void shouldReturnCorrectCodeForJmxAuthenticationException() { | ||
|
||
final JmxAuthenticationException jmxAuthenticationException = new JmxAuthenticationException("Test", new Exception()); | ||
|
||
final int resultCode = returnCodeFactory.createFor(jmxAuthenticationException); | ||
|
||
assertThat(resultCode, is(1)); | ||
verify(toConsolePrinter).println("Authentication failed. Please ensure your username and password are correct"); | ||
} | ||
|
||
@Test | ||
public void shouldReturnCorrectCodeForMBeanClientConnectionException() { | ||
|
||
final int resultCode = returnCodeFactory.createFor(new MBeanClientConnectionException("Test")); | ||
|
||
assertThat(resultCode, is(2)); | ||
|
||
verify(toConsolePrinter).println("Test"); | ||
} | ||
|
||
@Test | ||
public void shouldReturnCorrectCodeForAnyOtherException() { | ||
|
||
final int resultCode = returnCodeFactory.createFor(new Exception("Test")); | ||
|
||
assertThat(resultCode, is(3)); | ||
|
||
verify(toConsolePrinter).println("Test"); | ||
} | ||
} |
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
Oops, something went wrong.