Skip to content

Commit

Permalink
Polish, simplify code and avoid assertj usages
Browse files Browse the repository at this point in the history
  • Loading branch information
roimenashe committed Nov 26, 2023
1 parent 1ea3612 commit 00b2c78
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,11 @@ public Optional<Key> getNewKey(AerospikeWriteData data,
|| key.setName == null || key.namespace == null) {
AerospikePersistentProperty idProperty = entity.getIdProperty();
if (idProperty != null) {
String setName;
if (data.getSetName() != null) {
setName = data.getSetName();
} else {
setName = entity.getSetName();
}
String setName = Optional.ofNullable(data.getSetName()).orElse(entity.getSetName());

// Store record key as it is (if Aerospike supports it natively and configured)
if (aerospikeDataSettings.isKeepOriginalKeyTypes() &&
isValidAerospikeRecordKeyType(idProperty.getType())) {
if (aerospikeDataSettings.isKeepOriginalKeyTypes()
&& isValidAerospikeRecordKeyType(idProperty.getType())) {
log.debug("Attempt to construct record key with original key type");
Object nativeTypeId = accessor.getProperty(idProperty, idProperty.getType());
Assert.notNull(nativeTypeId, "Id must not be null!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.Assertions;
import org.springframework.data.aerospike.config.AerospikeDataSettings;
import org.springframework.util.Assert;

public class KeyAssert extends AbstractAssert<KeyAssert, Key> {

Expand All @@ -18,15 +19,19 @@ public static KeyAssert assertThat(Key key) {
@SuppressWarnings("UnusedReturnValue")
public KeyAssert consistsOf(AerospikeDataSettings aerospikeDataSettings, String namespace, String setName,
Object expectedUserKey) {
Assertions.assertThat(actual.namespace).isEqualTo(namespace);
Assertions.assertThat(actual.setName).isEqualTo(setName);
if (!actual.namespace.equals(namespace)) {
throw new IllegalArgumentException("Inconsistent namespace name");
}
if (!actual.setName.equals(setName)) {
throw new IllegalArgumentException("Inconsistent setName");
}

if (aerospikeDataSettings != null && aerospikeDataSettings.isKeepOriginalKeyTypes()) {
Assertions.assertThat(verifyActualUserKeyType(expectedUserKey)).isTrue();
} else {
// String type is used for unsupported Aerospike key types and previously for all key types in older
// versions of Spring Data Aerospike
Assertions.assertThat(checkIfActualUserKeyTypeIsString()).isTrue();
Assert.isTrue(checkIfActualUserKeyTypeIsString(), "Key type is not string");
}
return this;
}
Expand Down

0 comments on commit 00b2c78

Please sign in to comment.