Skip to content

Commit

Permalink
add test for FrameworkException (#523)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoheiAh authored and slievrly committed Mar 6, 2019
1 parent ec825e6 commit 50cdf84
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

/**
* @author Otis.z
* @date 2019/2/22
* @date 2019/2/22
*/
public class XIDTest {

Expand Down
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");
}
}


}
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");
}



}

0 comments on commit 50cdf84

Please sign in to comment.