Skip to content
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

Fix | Thai locale bug in JUnit tests #941

Merged
merged 5 commits into from
Jan 24, 2019
Merged
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
@@ -1,5 +1,6 @@
package com.microsoft.sqlserver.jdbc.datatypes;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
Expand All @@ -17,6 +18,7 @@
import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
import java.text.DateFormatSymbols;
import java.text.MessageFormat;
import java.util.Calendar;
import java.util.EnumSet;
Expand Down Expand Up @@ -1094,7 +1096,6 @@ public void testCallableStatementGetters() throws Exception {
@Test
public void testResultSetMetaData() throws Exception {
try (Connection conn = DriverManager.getConnection(connectionString)) {
TestValue v[] = TestValue.values();
for (TestValue value : TestValue.values())
value.sqlValue.verifyResultSetMetaData(conn);
}
Expand Down Expand Up @@ -1378,9 +1379,21 @@ public void testWithThaiLocale() throws Exception {
rs.next();

// compare these separately since there may be an extra space between the 2
assertEquals("Jan 1 1970", rs.getString(1).substring(0, 11));
assertEquals(timeFormat.format(ts.getTime()),
rs.getString(1).substring(rs.getString(1).length() - 7).trim());
assertTrue(rs.getString(1).startsWith("Jan 1 1970"));

/*
* Timestamp returned from varchar column may be wrongly formatted. E.g: 12:12PM will not pass if
* compared to 12:12p.m.
*/
DateFormatSymbols symbols = new DateFormatSymbols(Locale.getDefault());
symbols.setAmPmStrings(new String[] {"am", "pm"});
timeFormat.setDateFormatSymbols(symbols);
String expectedTimePortion = timeFormat.format(ts);
String recievedTimePortion = rs.getString(1).substring(rs.getString(1).length() - 7).trim();
assertTrue(
"Timestamp mismatch, expected: " + expectedTimePortion + " but recieved: "
+ recievedTimePortion + ".",
expectedTimePortion.equalsIgnoreCase(recievedTimePortion));
}

// Test PreparedStatement with Date
Expand Down