Skip to content

[tests] Make sure to assert / fail try catch statements #985

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

Merged
merged 1 commit into from
Apr 19, 2017
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 @@ -128,17 +128,19 @@ public void shouldIgnoreLeadingAndTrailingSpaces() {
public void invalidOldJdbcTypeFormat() {
try {
new ParameterExpression("id:");
Assert.fail();
} catch (BuilderException e) {
e.getMessage().contains("Parsing error in {id:} in position 3");
Assert.assertTrue(e.getMessage().contains("Parsing error in {id:} in position 3"));
}
}

@Test
public void invalidJdbcTypeOptUsingExpression() {
try {
new ParameterExpression("(expression)+");
Assert.fail();
} catch (BuilderException e) {
e.getMessage().contains("Parsing error in {(expression)+} in position 12");
Assert.assertTrue(e.getMessage().contains("Parsing error in {(expression)+} in position 12"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -110,8 +111,9 @@ public void testLoadLazyDeserializeWithoutConfigurationFactory() throws Exceptio
final LazyObjectFoo deserializedFoo = this.deserializeFoo(serializedFoo);
try {
deserializedFoo.getLazyObjectBar();
fail();
} catch (ExecutorException e) {
e.getMessage().contains("Cannot get Configuration as configuration factory was not set.");
assertTrue(e.getMessage().contains("Cannot get Configuration as configuration factory was not set."));
}
} finally {
session.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.Reader;
import java.sql.Connection;
Expand Down Expand Up @@ -273,8 +275,9 @@ public void methodNotFound() throws NoSuchMethodException {
try {
new ProviderSqlSource(new Configuration(),
ErrorMapper.class.getMethod("methodNotFound").getAnnotation(SelectProvider.class));
fail();
} catch (BuilderException e) {
e.getMessage().contains("Error creating SqlSource for SqlProvider. Method 'methodNotFound' not found in SqlProvider 'org.apache.ibatis.submitted.sqlprovider.SqlProviderTest$ErrorSqlBuilder'.");
assertTrue(e.getMessage().contains("Error creating SqlSource for SqlProvider. Method 'methodNotFound' not found in SqlProvider 'org.apache.ibatis.submitted.sqlprovider.SqlProviderTest$ErrorSqlBuilder'."));
}
}

Expand All @@ -283,17 +286,19 @@ public void methodOverload() throws NoSuchMethodException {
try {
new ProviderSqlSource(new Configuration(),
ErrorMapper.class.getMethod("methodOverload", String.class).getAnnotation(SelectProvider.class));
fail();
} catch (BuilderException e) {
e.getMessage().contains("Error creating SqlSource for SqlProvider. Method 'overload' is found multiple in SqlProvider 'org.apache.ibatis.submitted.sqlprovider.SqlProviderTest$ErrorSqlBuilder'. Sql provider method can not overload.");
assertTrue(e.getMessage().contains("Error creating SqlSource for SqlProvider. Method 'overload' is found multiple in SqlProvider 'org.apache.ibatis.submitted.sqlprovider.SqlProviderTest$ErrorSqlBuilder'. Sql provider method can not overload."));
}
}

@Test
public void notSqlProvider() throws NoSuchMethodException {
try {
new ProviderSqlSource(new Configuration(), new Object());
fail();
} catch (BuilderException e) {
e.getMessage().contains("Error creating SqlSource for SqlProvider. Cause: java.lang.NoSuchMethodException: java.lang.Object.type()");
assertTrue(e.getMessage().contains("Error creating SqlSource for SqlProvider. Cause: java.lang.NoSuchMethodException: java.lang.Object.type()"));
}
}

Expand All @@ -303,8 +308,9 @@ public void notSupportParameterObjectOnMultipleArguments() throws NoSuchMethodEx
new ProviderSqlSource(new Configuration(),
Mapper.class.getMethod("getUsersByName", String.class, String.class).getAnnotation(SelectProvider.class))
.getBoundSql(new Object());
fail();
} catch (BuilderException e) {
e.getMessage().contains("Error invoking SqlProvider method (org.apache.ibatis.submitted.sqlprovider.OurSqlBuilder.buildGetUsersByNameQuery). Cannot invoke a method that holds multiple arguments using a specifying parameterObject. In this case, please specify a 'java.util.Map' object.");
assertTrue(e.getMessage().contains("Error invoking SqlProvider method (org.apache.ibatis.submitted.sqlprovider.OurSqlBuilder.buildGetUsersByNameQuery). Cannot invoke a method that holds multiple arguments using a specifying parameterObject. In this case, please specify a 'java.util.Map' object."));
}
}

Expand All @@ -314,8 +320,9 @@ public void notSupportParameterObjectOnNamedArgument() throws NoSuchMethodExcept
new ProviderSqlSource(new Configuration(),
Mapper.class.getMethod("getUsersByNameWithParamName", String.class).getAnnotation(SelectProvider.class))
.getBoundSql(new Object());
fail();
} catch (BuilderException e) {
e.getMessage().contains("Error invoking SqlProvider method (org.apache.ibatis.submitted.sqlprovider.OurSqlBuilder.buildGetUsersByNameWithParamNameQuery). Cannot invoke a method that holds named argument(@Param) using a specifying parameterObject. In this case, please specify a 'java.util.Map' object.");
assertTrue(e.getMessage().contains("Error invoking SqlProvider method (org.apache.ibatis.submitted.sqlprovider.OurSqlBuilder.buildGetUsersByNameWithParamNameQuery). Cannot invoke a method that holds named argument(@Param) using a specifying parameterObject. In this case, please specify a 'java.util.Map' object."));
}
}

Expand All @@ -325,8 +332,9 @@ public void invokeError() throws NoSuchMethodException {
new ProviderSqlSource(new Configuration(),
ErrorMapper.class.getMethod("invokeError").getAnnotation(SelectProvider.class))
.getBoundSql(new Object());
fail();
} catch (BuilderException e) {
e.getMessage().contains("Error invoking SqlProvider method (org.apache.ibatis.submitted.sqlprovider.SqlProviderTest$ErrorSqlBuilder.invokeError). Cause: java.lang.reflect.InvocationTargetException");
assertTrue(e.getMessage().contains("Error invoking SqlProvider method (org.apache.ibatis.submitted.sqlprovider.SqlProviderTest$ErrorSqlBuilder.invokeError). Cause: java.lang.reflect.InvocationTargetException"));
}
}

Expand Down