|
23 | 23 | import androidx.appcompat.app.AppCompatActivity; |
24 | 24 | import android.view.LayoutInflater; |
25 | 25 | import android.view.View; |
| 26 | +import android.view.ViewGroup; |
26 | 27 | import android.widget.GridView; |
27 | 28 | import android.widget.TextView.BufferType; |
28 | 29 | import androidx.core.util.Pair; |
29 | 30 | import androidx.test.core.app.ApplicationProvider; |
30 | 31 | import com.google.android.material.internal.ParcelableTestUtils; |
31 | 32 | import com.google.android.material.textfield.TextInputLayout; |
| 33 | +import java.text.SimpleDateFormat; |
32 | 34 | import java.util.Calendar; |
33 | 35 | import org.junit.Assert; |
34 | 36 | import org.junit.Before; |
@@ -81,12 +83,13 @@ public void textInputValid() { |
81 | 83 | @Test |
82 | 84 | public void textInputFormatError() { |
83 | 85 | View root = getRootView(); |
| 86 | + ((ViewGroup) activity.findViewById(android.R.id.content)).addView(root); |
| 87 | + |
84 | 88 | TextInputLayout startTextInput = root.findViewById(R.id.mtrl_picker_text_input_range_start); |
85 | 89 | TextInputLayout endTextInput = root.findViewById(R.id.mtrl_picker_text_input_range_end); |
86 | 90 | startTextInput.getEditText().setText("22/22/2010", BufferType.EDITABLE); |
87 | 91 | endTextInput.getEditText().setText("555-555-5555", BufferType.EDITABLE); |
88 | 92 |
|
89 | | - activity.setContentView(root); |
90 | 93 | ShadowLooper.runUiThreadTasksIncludingDelayedTasks(); |
91 | 94 |
|
92 | 95 | assertThat(startTextInput.getError()).isNotNull(); |
@@ -210,8 +213,12 @@ public void textInputHintValidWithPTLocale() { |
210 | 213 | activity.setContentView(root); |
211 | 214 | ShadowLooper.runUiThreadTasksIncludingDelayedTasks(); |
212 | 215 |
|
213 | | - assertThat(startTextInput.getPlaceholderText().toString()).isEqualTo("dd-mm-aaaa"); |
214 | | - assertThat(endTextInput.getPlaceholderText().toString()).isEqualTo("dd-mm-aaaa"); |
| 216 | + // Some JVMs format PT dates as dd-mm-aaaa, and some as dd/mm/aaaa. Derive the expected result |
| 217 | + // programatically to account for the difference. |
| 218 | + boolean slashDateFormat = new SimpleDateFormat().toLocalizedPattern().startsWith("dd/"); |
| 219 | + String expectedDateFormat = slashDateFormat ? "dd/mm/aaaa" : "dd-mm-aaaa"; |
| 220 | + assertThat(startTextInput.getPlaceholderText().toString()).isEqualTo(expectedDateFormat); |
| 221 | + assertThat(endTextInput.getPlaceholderText().toString()).isEqualTo(expectedDateFormat); |
215 | 222 | } |
216 | 223 |
|
217 | 224 | private View getRootView() { |
|
0 commit comments