SelectStatementHandler implements SQLStatementHandler { public static Optional<LockSegment> getLockSegment(final SelectStatement selectStatement) { if (selectStatement instanceof MySQLStatement) { return ((MySQLSelectStatement) selectStatement).getLock(); } if (selectStatement instanceof OracleStatement) { return ((OracleSelectStatement) selectStatement).getLock(); } if (selectStatement instanceof PostgreSQLStatement) { return ((PostgreSQLSelectStatement) selectStatement).getLock(); } return Optional.empty(); }  static Optional<LimitSegment> getLimitSegment(final SelectStatement selectStatement); static Optional<LockSegment> getLockSegment(final SelectStatement selectStatement);  }
@Test public void assertGetLockSegmentWithLockSegmentForMySQL() { MySQLSelectStatement selectStatement = new MySQLSelectStatement(); selectStatement.setLock(new LockSegment(0, 0)); Optional<LockSegment> lockSegment = SelectStatementHandler.getLockSegment(selectStatement); assertTrue(lockSegment.isPresent()); }
@Test public void assertGetLockSegmentWithoutLockSegmentForMySQL() { MySQLSelectStatement selectStatement = new MySQLSelectStatement(); Optional<LockSegment> lockSegment = SelectStatementHandler.getLockSegment(selectStatement); assertFalse(lockSegment.isPresent()); }
@Test public void assertGetLockSegmentWithLockSegmentForOracle() { OracleSelectStatement selectStatement = new OracleSelectStatement(); selectStatement.setLock(new LockSegment(0, 0)); Optional<LockSegment> lockSegment = SelectStatementHandler.getLockSegment(selectStatement); assertTrue(lockSegment.isPresent()); }
@Test public void assertGetLockSegmentWithoutLockSegmentForOracle() { OracleSelectStatement selectStatement = new OracleSelectStatement(); Optional<LockSegment> lockSegment = SelectStatementHandler.getLockSegment(selectStatement); assertFalse(lockSegment.isPresent()); }
@Test public void assertGetLockSegmentWithLockSegmentForPostgreSQL() { PostgreSQLSelectStatement selectStatement = new PostgreSQLSelectStatement(); selectStatement.setLock(new LockSegment(0, 0)); Optional<LockSegment> lockSegment = SelectStatementHandler.getLockSegment(selectStatement); assertTrue(lockSegment.isPresent()); }
@Test public void assertGetLockSegmentWithoutLockSegmentForPostgreSQL() { PostgreSQLSelectStatement selectStatement = new PostgreSQLSelectStatement(); Optional<LockSegment> lockSegment = SelectStatementHandler.getLockSegment(selectStatement); assertFalse(lockSegment.isPresent()); }