Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test-1] add test for FrameworkException #523

Merged
merged 2 commits into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}



}