Skip to content

Commit 1cf53d5

Browse files
convert Expectation to Java
1 parent 9674404 commit 1cf53d5

1 file changed

Lines changed: 86 additions & 34 deletions

File tree

sqldev/src/main/java/org/utplsql/sqldev/model/runner/Expectation.java

Lines changed: 86 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,89 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.utplsql.sqldev.model.runner
17-
18-
import java.util.regex.Pattern
19-
import org.eclipse.xtend.lib.annotations.Accessors
20-
21-
@Accessors
22-
class Expectation {
23-
String description
24-
String message
25-
String caller
26-
27-
def getFailureText() {
28-
return '''
29-
«message.trim»
30-
«caller?.trim»
31-
'''.toString.trim
32-
}
33-
34-
def getShortFailureText() {
35-
return '''«IF description !== null»«description» (line «callerLine»)«ELSE»Line «callerLine»«ENDIF»'''.toString
36-
}
37-
38-
def getCallerLine() {
39-
var Integer line = null
40-
if (caller !== null) {
41-
val p = Pattern.compile("(?i)\"[^\\\"]+\",\\s+line\\s*([0-9]+)")
42-
val m = p.matcher(caller)
43-
if (m.find) {
44-
line = Integer.valueOf(m.group(1))
45-
}
46-
}
47-
return line
48-
}
49-
}
16+
package org.utplsql.sqldev.model.runner;
17+
18+
import java.util.regex.Matcher;
19+
import java.util.regex.Pattern;
20+
21+
import org.eclipse.xtend2.lib.StringConcatenation;
22+
import org.springframework.core.style.ToStringCreator;
23+
import org.utplsql.sqldev.model.UtplsqlToStringStyler;
24+
25+
public class Expectation {
26+
private String description;
27+
private String message;
28+
private String caller;
29+
30+
@Override
31+
public String toString() {
32+
return new ToStringCreator(this, UtplsqlToStringStyler.INSTANCE)
33+
.append("description", description)
34+
.append("message", message)
35+
.append("caller", caller)
36+
.append("failureText", getFailureText())
37+
.append("shortFailureText", getShortFailureText())
38+
.append("callerLine", getCallerLine())
39+
.toString();
40+
}
41+
42+
public String getFailureText() {
43+
final StringBuilder sb = new StringBuilder();
44+
sb.append(message.trim());
45+
if (caller != null) {
46+
sb.append('\n');
47+
sb.append(caller.trim());
48+
}
49+
return sb.toString();
50+
}
51+
52+
public String getShortFailureText() {
53+
final StringConcatenation sb = new StringConcatenation();
54+
if (description != null) {
55+
sb.append(description);
56+
sb.append(" (line ");
57+
sb.append(getCallerLine());
58+
sb.append(")");
59+
} else {
60+
sb.append("Line ");
61+
sb.append(getCallerLine());
62+
}
63+
return sb.toString();
64+
}
65+
66+
public Integer getCallerLine() {
67+
Integer line = null;
68+
if (caller != null) {
69+
final Pattern p = Pattern.compile("(?i)\"[^\\\"]+\",\\s+line\\s*([0-9]+)");
70+
final Matcher m = p.matcher(caller);
71+
if (m.find()) {
72+
line = Integer.valueOf(m.group(1));
73+
}
74+
}
75+
return line;
76+
}
77+
78+
public String getDescription() {
79+
return description;
80+
}
81+
82+
public void setDescription(final String description) {
83+
this.description = description;
84+
}
85+
86+
public String getMessage() {
87+
return message;
88+
}
89+
90+
public void setMessage(final String message) {
91+
this.message = message;
92+
}
93+
94+
public String getCaller() {
95+
return caller;
96+
}
97+
98+
public void setCaller(final String caller) {
99+
this.caller = caller;
100+
}
101+
}

0 commit comments

Comments
 (0)