StartupShutdownService { static Integer extractSchemaVersion(String sqlLine) { return Optional.ofNullable(sqlLine) .map(SCHEMA_VERSION_SQL_PATTERN::matcher) .filter(Matcher::matches) .map(m -> m.group(1)) .map(Integer::parseInt) .orElse(null); }  @PostConstruct void startup(); @PreDestroy void shutdown(); static final String SORMAS_TO_SORMAS_USER_NAME; }
@Test public void testExtractSchemaVersion() { assertThat(StartupShutdownService.extractSchemaVersion(null), nullValue()); assertThat(StartupShutdownService.extractSchemaVersion(""), nullValue()); assertThat(StartupShutdownService.extractSchemaVersion("select * from test;"), nullValue()); assertThat( StartupShutdownService.extractSchemaVersion("--INSERT INTO schema_version (version_number, comment) VALUES (1, 'Init database');"), nullValue()); assertThat( StartupShutdownService.extractSchemaVersion("INSERT INTO schema_version (version_number, comment) VALUES (1, 'Init database');"), is(1)); assertThat( StartupShutdownService.extractSchemaVersion( " \tINSERT \tINTO \tschema_version( \tversion_number \t,comment \t)VALUES( 123543,'Init database');"), is(123543)); }