BaseTransactionalExecutor implements Executor { protected String buildLockKey(TableRecords rowsIncludingPK) { if (rowsIncludingPK.size() == 0) { return null; } StringBuilder sb = new StringBuilder(); sb.append(rowsIncludingPK.getTableMeta().getTableName()); sb.append(":"); int filedSequence = 0; for (Field field : rowsIncludingPK.pkRows()) { sb.append(field.getValue()); filedSequence++; if (filedSequence < rowsIncludingPK.pkRows().size()) { sb.append(","); } } return sb.toString(); } BaseTransactionalExecutor(StatementProxy<S> statementProxy, StatementCallback<T, S> statementCallback,
                                     SQLRecognizer sqlRecognizer); @Override Object execute(Object... args);  }
@Test public void testBuildLockKey() { String tableName = "test_name"; String fieldOne = "field_one"; String fieldTwo = "field_two"; String split1 = ":"; String split2 = ","; String buildLockKeyExpect = tableName + split1 + fieldOne + split2 + fieldTwo; Field field1 = mock(Field.class); when(field1.getValue()).thenReturn(fieldOne); Field field2 = mock(Field.class); when(field2.getValue()).thenReturn(fieldTwo); List<Field> fieldList = new ArrayList<>(); fieldList.add(field1); fieldList.add(field2); TableMeta tableMeta = mock(TableMeta.class); when(tableMeta.getTableName()).thenReturn(tableName); TableRecords tableRecords = mock(TableRecords.class); when(tableRecords.getTableMeta()).thenReturn(tableMeta); when(tableRecords.pkRows()).thenReturn(fieldList); when(tableRecords.size()).thenReturn(fieldList.size()); BaseTransactionalExecutor executor = mock(BaseTransactionalExecutor.class); when(executor.buildLockKey(tableRecords)).thenCallRealMethod(); assertThat(executor.buildLockKey(tableRecords)).isEqualTo(buildLockKeyExpect); }