MediaWikiApiErrorHandler { public static void throwMediaWikiApiErrorException(String errorCode, String errorMessage) throws MediaWikiApiErrorException { switch (errorCode) { case ERROR_NO_TOKEN: case ERROR_INVALID_TOKEN: throw new TokenErrorException(errorCode, errorMessage); case ERROR_EDIT_CONFLICT: throw new EditConflictErrorException(errorMessage); case ERROR_NO_SUCH_ENTITY: throw new NoSuchEntityErrorException(errorMessage); case ERROR_MAXLAG: throw new MaxlagErrorException(errorMessage); case ERROR_ASSERT_USER_FAILED: throw new AssertUserFailedException(errorMessage); case ERROR_TAGS_APPLY_NOT_ALLOWED: throw new TagsApplyNotAllowedException(errorMessage); default: throw new MediaWikiApiErrorException(errorCode, errorMessage); } }  static void throwMediaWikiApiErrorException(String errorCode,
			String errorMessage); final static String ERROR_EDIT_CONFLICT; final static String ERROR_NO_TOKEN; final static String ERROR_INVALID_TOKEN; final static String ERROR_NO_SUCH_ENTITY; final static String ERROR_MAXLAG; final static String ERROR_ASSERT_USER_FAILED; final static String ERROR_TAGS_APPLY_NOT_ALLOWED; }
@Test public void testUnknownError() { String code = ""; String message = ""; try { MediaWikiApiErrorHandler.throwMediaWikiApiErrorException("unknown", "some message"); } catch (MediaWikiApiErrorException e) { code = e.getErrorCode(); message = e.getErrorMessage(); } assertEquals("unknown", code); assertEquals("some message", message); }
@Test(expected = TokenErrorException.class) public void testNoTokenError() throws MediaWikiApiErrorException { MediaWikiApiErrorHandler.throwMediaWikiApiErrorException( MediaWikiApiErrorHandler.ERROR_NO_TOKEN, "some message"); }
@Test(expected = TokenErrorException.class) public void testBadTokenError() throws MediaWikiApiErrorException { MediaWikiApiErrorHandler.throwMediaWikiApiErrorException( MediaWikiApiErrorHandler.ERROR_INVALID_TOKEN, "some message"); }
@Test(expected = EditConflictErrorException.class) public void testEditConflictError() throws MediaWikiApiErrorException { MediaWikiApiErrorHandler.throwMediaWikiApiErrorException( MediaWikiApiErrorHandler.ERROR_EDIT_CONFLICT, "some message"); }
@Test(expected = NoSuchEntityErrorException.class) public void testNoSuchEntityError() throws MediaWikiApiErrorException { MediaWikiApiErrorHandler.throwMediaWikiApiErrorException( MediaWikiApiErrorHandler.ERROR_NO_SUCH_ENTITY, "some message"); }
@Test(expected = MaxlagErrorException.class) public void testMaxlagError() throws MediaWikiApiErrorException { MediaWikiApiErrorHandler.throwMediaWikiApiErrorException( MediaWikiApiErrorHandler.ERROR_MAXLAG, "Waiting for 10.64.16.27: 2 seconds lagged"); }