Advertisement
Guest User

Untitled

a guest
Nov 28th, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. @Category(IntegrationTest.class)
  2. public class InitialStateIntegrationTest {
  3. private static Connection connection;
  4.  
  5. @BeforeClass
  6. public static void connectToDatabase() throws Exception {
  7. connection = getConnection();
  8. }
  9.  
  10. @AfterClass
  11. public static void closeConnection() throws Exception {
  12. connection.close();
  13. }
  14.  
  15. @Test
  16. public void database_should_contain_unihan_codepoints() throws Exception {
  17. List<Integer> codepoints = asList(connection, "select codepoint from hanzi where codepoint in (25165, 30340, 132878)", Integer.class);
  18. assertThat(codepoints, contains(asInt("才"), asInt("的"), asInt("𠜎")));
  19. }
  20.  
  21. public static <T> List<T> asList(Connection connection, String sql, Class<T> type) throws Exception {
  22. List<T> result = new ArrayList<>();
  23. try (ResultSet resultSet = connection.prepareCall(sql).executeQuery()) {
  24. while (resultSet.next()) {
  25. result.add(resultSet.getObject(1, type));
  26. }
  27. }
  28. return result;
  29. }
  30.  
  31. public static Integer asInt(String hanzi) {
  32. return hanzi.codePointAt(0);
  33. }
  34.  
  35. public static String asString(int codePoint) {
  36. return String.valueOf(Character.toChars(codePoint));
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement