1
1
/**
2
- * Copyright 2009-2016 the original author or authors.
2
+ * Copyright 2009-2017 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
25
25
import org .apache .ibatis .mapping .StatementType ;
26
26
import org .apache .ibatis .session .Configuration ;
27
27
import org .apache .ibatis .type .TypeHandler ;
28
- import org .junit .Rule ;
29
28
import org .junit .Test ;
30
- import org .junit .rules .ExpectedException ;
31
29
32
- import static org . junit . Assert . assertThat ;
33
- import static org .hamcrest . CoreMatchers .* ;
30
+ import static com . googlecode . catchexception . apis . BDDCatchException .* ;
31
+ import static org .assertj . core . api . BDDAssertions . then ;
34
32
35
- public class XmlMapperBuilderTest {
33
+ import static org . assertj . core . api . Assertions . assertThat ;
36
34
37
- @ Rule
38
- public ExpectedException expectedException = ExpectedException .none ();
35
+ public class XmlMapperBuilderTest {
39
36
40
37
@ Test
41
38
public void shouldSuccessfullyLoadXMLMapperFile () throws Exception {
@@ -44,6 +41,7 @@ public void shouldSuccessfullyLoadXMLMapperFile() throws Exception {
44
41
InputStream inputStream = Resources .getResourceAsStream (resource );
45
42
XMLMapperBuilder builder = new XMLMapperBuilder (inputStream , configuration , resource , configuration .getSqlFragments ());
46
43
builder .parse ();
44
+ inputStream .close ();
47
45
}
48
46
49
47
@ Test
@@ -55,110 +53,118 @@ public void mappedStatementWithOptions() throws Exception {
55
53
builder .parse ();
56
54
57
55
MappedStatement mappedStatement = configuration .getMappedStatement ("selectWithOptions" );
58
- assertThat (mappedStatement .getFetchSize (), is (200 ) );
59
- assertThat (mappedStatement .getTimeout (), is (10 ) );
60
- assertThat (mappedStatement .getStatementType (), is (StatementType .PREPARED ) );
61
- assertThat (mappedStatement .getResultSetType (), is (ResultSetType .SCROLL_SENSITIVE ) );
62
- assertThat (mappedStatement .isFlushCacheRequired (), is ( false ) );
63
- assertThat (mappedStatement .isUseCache (), is ( false ) );
64
-
56
+ assertThat (mappedStatement .getFetchSize ()). isEqualTo (200 );
57
+ assertThat (mappedStatement .getTimeout ()). isEqualTo (10 );
58
+ assertThat (mappedStatement .getStatementType ()). isEqualTo (StatementType .PREPARED );
59
+ assertThat (mappedStatement .getResultSetType ()). isEqualTo (ResultSetType .SCROLL_SENSITIVE );
60
+ assertThat (mappedStatement .isFlushCacheRequired ()). isFalse ( );
61
+ assertThat (mappedStatement .isUseCache ()). isFalse ( );
62
+ inputStream . close ();
65
63
}
66
64
67
65
@ Test
68
66
public void parseExpression () {
69
67
BaseBuilder builder = new BaseBuilder (new Configuration ()){{}};
70
68
{
71
69
Pattern pattern = builder .parseExpression ("[0-9]" , "[a-z]" );
72
- assertThat (pattern .matcher ("0" ).find (), is ( true ) );
73
- assertThat (pattern .matcher ("a" ).find (), is ( false ) );
70
+ assertThat (pattern .matcher ("0" ).find ()). isTrue ( );
71
+ assertThat (pattern .matcher ("a" ).find ()). isFalse ( );
74
72
}
75
73
{
76
74
Pattern pattern = builder .parseExpression (null , "[a-z]" );
77
- assertThat (pattern .matcher ("0" ).find (), is ( false ) );
78
- assertThat (pattern .matcher ("a" ).find (), is ( true ) );
75
+ assertThat (pattern .matcher ("0" ).find ()). isFalse ( );
76
+ assertThat (pattern .matcher ("a" ).find ()). isTrue ( );
79
77
}
80
78
}
81
79
82
80
@ Test
83
81
public void resolveJdbcTypeWithUndefinedValue () {
84
82
BaseBuilder builder = new BaseBuilder (new Configuration ()){{}};
85
- expectedException .expect (BuilderException .class );
86
- expectedException .expectMessage (startsWith ("Error resolving JdbcType. Cause: java.lang.IllegalArgumentException: No enum" ));
87
- expectedException .expectMessage (endsWith ("org.apache.ibatis.type.JdbcType.aaa" ));
88
- builder .resolveJdbcType ("aaa" );
83
+ when (builder ).resolveJdbcType ("aaa" );
84
+ then (caughtException ())
85
+ .isInstanceOf (BuilderException .class )
86
+ .hasMessageStartingWith ("Error resolving JdbcType. Cause: java.lang.IllegalArgumentException: No enum" )
87
+ .hasMessageEndingWith ("org.apache.ibatis.type.JdbcType.aaa" );
89
88
}
90
89
91
90
@ Test
92
91
public void resolveResultSetTypeWithUndefinedValue () {
93
92
BaseBuilder builder = new BaseBuilder (new Configuration ()){{}};
94
- expectedException .expect (BuilderException .class );
95
- expectedException .expectMessage (startsWith ("Error resolving ResultSetType. Cause: java.lang.IllegalArgumentException: No enum" ));
96
- expectedException .expectMessage (endsWith ("org.apache.ibatis.mapping.ResultSetType.bbb" ));
97
- builder .resolveResultSetType ("bbb" );
93
+ when (builder ).resolveResultSetType ("bbb" );
94
+ then (caughtException ())
95
+ .isInstanceOf (BuilderException .class )
96
+ .hasMessageStartingWith ("Error resolving ResultSetType. Cause: java.lang.IllegalArgumentException: No enum" )
97
+ .hasMessageEndingWith ("org.apache.ibatis.mapping.ResultSetType.bbb" );
98
98
}
99
99
100
100
@ Test
101
101
public void resolveParameterModeWithUndefinedValue () {
102
102
BaseBuilder builder = new BaseBuilder (new Configuration ()){{}};
103
- expectedException .expect (BuilderException .class );
104
- expectedException .expectMessage (startsWith ("Error resolving ParameterMode. Cause: java.lang.IllegalArgumentException: No enum" ));
105
- expectedException .expectMessage (endsWith ("org.apache.ibatis.mapping.ParameterMode.ccc" ));
106
- builder .resolveParameterMode ("ccc" );
103
+ when (builder ).resolveParameterMode ("ccc" );
104
+ then (caughtException ())
105
+ .isInstanceOf (BuilderException .class )
106
+ .hasMessageStartingWith ("Error resolving ParameterMode. Cause: java.lang.IllegalArgumentException: No enum" )
107
+ .hasMessageEndingWith ("org.apache.ibatis.mapping.ParameterMode.ccc" );
107
108
}
108
109
109
110
@ Test
110
111
public void createInstanceWithAbstractClass () {
111
112
BaseBuilder builder = new BaseBuilder (new Configuration ()){{}};
112
- expectedException .expect (BuilderException .class );
113
- expectedException .expectMessage (is ("Error creating instance. Cause: java.lang.InstantiationException: org.apache.ibatis.builder.BaseBuilder" ));
114
- builder .createInstance ("org.apache.ibatis.builder.BaseBuilder" );
113
+ when (builder ).createInstance ("org.apache.ibatis.builder.BaseBuilder" );
114
+ then (caughtException ())
115
+ .isInstanceOf (BuilderException .class )
116
+ .hasMessage ("Error creating instance. Cause: java.lang.InstantiationException: org.apache.ibatis.builder.BaseBuilder" );
115
117
}
116
118
117
119
@ Test
118
120
public void resolveClassWithNotFound () {
119
121
BaseBuilder builder = new BaseBuilder (new Configuration ()){{}};
120
- expectedException .expect (BuilderException .class );
121
- expectedException .expectMessage (is ("Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'ddd'. Cause: java.lang.ClassNotFoundException: Cannot find class: ddd" ));
122
- builder .resolveClass ("ddd" );
122
+ when (builder ).resolveClass ("ddd" );
123
+ then (caughtException ())
124
+ .isInstanceOf (BuilderException .class )
125
+ .hasMessage ("Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'ddd'. Cause: java.lang.ClassNotFoundException: Cannot find class: ddd" );
123
126
}
124
127
125
128
@ Test
126
129
public void resolveTypeHandlerTypeHandlerAliasIsNull () {
127
130
BaseBuilder builder = new BaseBuilder (new Configuration ()){{}};
128
131
TypeHandler <?> typeHandler = builder .resolveTypeHandler (String .class , (String )null );
129
- assertThat (typeHandler , nullValue () );
132
+ assertThat (typeHandler ). isNull ( );
130
133
}
131
134
132
135
@ Test
133
136
public void resolveTypeHandlerNoAssignable () {
134
137
BaseBuilder builder = new BaseBuilder (new Configuration ()){{}};
135
- expectedException .expect (BuilderException .class );
136
- expectedException .expectMessage (is ("Type java.lang.Integer is not a valid TypeHandler because it does not implement TypeHandler interface" ));
137
- builder .resolveTypeHandler (String .class , "integer" );
138
+ when (builder ).resolveTypeHandler (String .class , "integer" );
139
+ then (caughtException ())
140
+ .isInstanceOf (BuilderException .class )
141
+ .hasMessage ("Type java.lang.Integer is not a valid TypeHandler because it does not implement TypeHandler interface" );
138
142
}
139
143
140
144
@ Test
141
145
public void setCurrentNamespaceValueIsNull () {
142
146
MapperBuilderAssistant builder = new MapperBuilderAssistant (new Configuration (), "resource" );
143
- expectedException .expect (BuilderException .class );
144
- expectedException .expectMessage (is ("The mapper element requires a namespace attribute to be specified." ));
145
- builder .setCurrentNamespace (null );
147
+ when (builder ).setCurrentNamespace (null );
148
+ then (caughtException ())
149
+ .isInstanceOf (BuilderException .class )
150
+ .hasMessage ("The mapper element requires a namespace attribute to be specified." );
146
151
}
147
152
148
153
@ Test
149
154
public void useCacheRefNamespaceIsNull () {
150
155
MapperBuilderAssistant builder = new MapperBuilderAssistant (new Configuration (), "resource" );
151
- expectedException .expect (BuilderException .class );
152
- expectedException .expectMessage (is ("cache-ref element requires a namespace attribute." ));
153
- builder .useCacheRef (null );
156
+ when (builder ).useCacheRef (null );
157
+ then (caughtException ())
158
+ .isInstanceOf (BuilderException .class )
159
+ .hasMessage ("cache-ref element requires a namespace attribute." );
154
160
}
155
161
156
162
@ Test
157
163
public void useCacheRefNamespaceIsUndefined () {
158
164
MapperBuilderAssistant builder = new MapperBuilderAssistant (new Configuration (), "resource" );
159
- expectedException . expect ( IncompleteElementException . class );
160
- expectedException . expectMessage ( is ( "No cache for namespace 'eee' could be found." ));
161
- builder . useCacheRef ( " eee" );
165
+ when ( builder ). useCacheRef ( "eee" );
166
+ then ( caughtException ())
167
+ . hasMessage ( "No cache for namespace ' eee' could be found. " );
162
168
}
163
169
164
170
// @Test
0 commit comments