16
16
// under the License.
17
17
package com .thoughtworks .selenium .condition ;
18
18
19
- import java .lang .reflect .InvocationTargetException ;
20
- import java .lang .reflect .Method ;
21
-
22
19
/**
23
20
* Simple predicate class, which also knows how to wait for the condition to be true. Used by
24
21
* Selenium tests.
@@ -45,39 +42,15 @@ public Condition() {
45
42
46
43
/**
47
44
* Creates an instance of Condition with the given {@code message} and {@code args}, which are in
48
- * the {@link String#format(String, Object...)} modeal .
45
+ * the {@link String#format(String, Object...)} model .
49
46
* @param message message
50
47
* @param args args
51
48
*/
52
49
public Condition (String message , Object [] args ) {
53
50
if (null == message ) {
54
51
throw new NullPointerException ("Condition names must not be null" );
55
52
}
56
- // this.message = String.format(message, args);
57
- this .message = simulateStringDotFormatMethod (message , args );
58
- }
59
-
60
- private String simulateStringDotFormatMethod (String message , Object [] args ) {
61
- int vers = Integer .parseInt (System .getProperty ("java.class.version" ).substring (0 , 2 ));
62
- if (vers >= 49 ) {
63
- try {
64
- Method format = String .class .getMethod ("format" , String .class , Object [].class );
65
- return (String ) format .invoke (null , new Object [] {message , args });
66
- } catch (NoSuchMethodException | IllegalAccessException e ) {
67
- } catch (InvocationTargetException e ) {
68
- Throwable throwable = e .getCause ();
69
- if (throwable instanceof RuntimeException ) {
70
- throw (RuntimeException ) throwable ;
71
- }
72
- }
73
- throw new RuntimeException ("String.format(..) can't be that hard to call" );
74
- }
75
- String msg = "" ;
76
- msg = message ;
77
- for (int i = 0 ; i < args .length ; i ++) {
78
- msg = msg + " " + args [i ];
79
- }
80
- return msg ;
53
+ this .message = String .format (message , args );
81
54
}
82
55
83
56
// drop these for var-args in another year.
0 commit comments