-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for FrameworkException (#523)
- Loading branch information
Showing
3 changed files
with
196 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ | |
|
||
/** | ||
* @author Otis.z | ||
* @date 2019/2/22 | ||
* @date 2019/2/22 | ||
*/ | ||
public class XIDTest { | ||
|
||
|
125 changes: 125 additions & 0 deletions
125
common/src/test/java/com/alibaba/fescar/common/exception/FrameworkExceptionTest.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,125 @@ | ||
/* | ||
* Copyright 1999-2018 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.alibaba.fescar.common.exception; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.sql.SQLException; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author Otis.z | ||
* @date 2019/3/1 | ||
*/ | ||
public class FrameworkExceptionTest { | ||
|
||
private Message message = new Message(); | ||
|
||
@Test | ||
public void testGetErrcode() { | ||
try { | ||
message.print4(); | ||
} catch (FrameworkException e) { | ||
assertThat(e).isInstanceOf(FrameworkException.class).hasMessage(FrameworkErrorCode.UnknownAppError.errMessage); | ||
assertThat(e.getErrcode()).isEqualTo(FrameworkErrorCode.UnknownAppError); | ||
} | ||
} | ||
|
||
@Test | ||
public void testNestedException() { | ||
try { | ||
message.print(); | ||
} catch (Exception e) { | ||
assertThat(e).isInstanceOf(FrameworkException.class).hasMessage(""); | ||
} | ||
} | ||
|
||
@Test | ||
public void testNestedException1() { | ||
try { | ||
message.print1(); | ||
} catch (Exception e) { | ||
assertThat(e).isInstanceOf(FrameworkException.class).hasMessage("nestedException"); | ||
} | ||
} | ||
|
||
@Test | ||
public void testNestedException2() { | ||
try { | ||
message.print2(); | ||
} catch (Exception e) { | ||
assertThat(e).isInstanceOf(SQLException.class).hasMessageContaining("Message"); | ||
} | ||
} | ||
|
||
@Test | ||
public void testNestedException3() { | ||
try { | ||
message.print3(); | ||
} catch (Exception e) { | ||
assertThat(e).isInstanceOf(SQLException.class).hasMessageContaining("Message"); | ||
} | ||
} | ||
|
||
|
||
@Test | ||
public void testNestedException5() { | ||
try { | ||
message.print5(); | ||
} catch (Exception e) { | ||
assertThat(e).isInstanceOf(FrameworkException.class).hasMessage(FrameworkErrorCode.ExceptionCaught.errMessage); | ||
} | ||
} | ||
|
||
@Test | ||
public void testNestedException6() { | ||
try { | ||
message.print6(); | ||
} catch (Exception e) { | ||
assertThat(e).isInstanceOf(FrameworkException.class).hasMessage("frameworkException"); | ||
} | ||
} | ||
|
||
@Test | ||
public void testNestedException7() { | ||
try { | ||
message.print7(); | ||
} catch (Exception e) { | ||
assertThat(e).isInstanceOf(FrameworkException.class).hasMessage("frameworkException"); | ||
} | ||
} | ||
|
||
@Test | ||
public void testNestedException8() { | ||
try { | ||
message.print8(); | ||
} catch (Exception e) { | ||
assertThat(e).isInstanceOf(FrameworkException.class).hasMessage("throw"); | ||
} | ||
} | ||
|
||
@Test | ||
public void testNestedException9() { | ||
try { | ||
message.print9(); | ||
} catch (Exception e) { | ||
assertThat(e).isInstanceOf(FrameworkException.class).hasMessage("frameworkExceptionMsg"); | ||
} | ||
} | ||
|
||
|
||
} |
70 changes: 70 additions & 0 deletions
70
common/src/test/java/com/alibaba/fescar/common/exception/Message.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 @@ | ||
/* | ||
* Copyright 1999-2018 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.alibaba.fescar.common.exception; | ||
|
||
import java.sql.SQLException; | ||
|
||
/** | ||
* @author Otis.z | ||
* @since 2019/3/1 | ||
*/ | ||
public class Message { | ||
|
||
public void print() { | ||
throw FrameworkException.nestedException(new Throwable(Message.class.getSimpleName())); | ||
} | ||
|
||
public void print1() { | ||
throw FrameworkException.nestedException("nestedException", new Throwable(Message.class.getSimpleName())); | ||
} | ||
|
||
public void print2() throws SQLException { | ||
throw FrameworkException.nestedSQLException("nestedException", new Throwable(Message.class.getSimpleName())); | ||
} | ||
|
||
public void print3() throws SQLException { | ||
throw FrameworkException.nestedSQLException(new Throwable(Message.class.getSimpleName())); | ||
} | ||
|
||
public void print4() { | ||
throw new FrameworkException(); | ||
} | ||
|
||
public void print5() { | ||
throw new FrameworkException(FrameworkErrorCode.ExceptionCaught); | ||
} | ||
|
||
public void print6() { | ||
throw new FrameworkException("frameworkException", FrameworkErrorCode.InitFescarClientError); | ||
} | ||
|
||
public void print7() { | ||
throw new FrameworkException(new Throwable("throw"), "frameworkException", | ||
FrameworkErrorCode.ChannelIsNotWritable); | ||
} | ||
|
||
public void print8() { | ||
throw new FrameworkException(new Throwable("throw")); | ||
} | ||
|
||
public void print9() { | ||
throw new FrameworkException(new Throwable(), "frameworkExceptionMsg"); | ||
} | ||
|
||
|
||
|
||
} |