Skip to content

Commit

Permalink
act: update converter
Browse files Browse the repository at this point in the history
  • Loading branch information
ngocnhan-tran1996 committed Jul 25, 2024
1 parent 1b51e2a commit 0198234
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.spring.jdbc.oracle.accessor;

import static io.spring.jdbc.oracle.utils.Strings.NOT_NULL;
import static io.spring.jdbc.oracle.utils.Strings.NOT_BLANK;

import io.spring.jdbc.oracle.exception.ValueException;
import io.spring.jdbc.oracle.utils.Strings;
Expand All @@ -14,7 +14,7 @@ protected ParameterAccessor(String parameterName, Class<T> mappedClass) {

if (Strings.isBlank(parameterName)) {

throw new ValueException(NOT_NULL.formatted("parameter"));
throw new ValueException(NOT_BLANK.formatted("parameter"));
}

this.parameterName = parameterName.toUpperCase();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/io/spring/jdbc/oracle/converter/ConvertKey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.spring.jdbc.oracle.converter;

public record ConvertKey(Class<?> sourceType, Class<?> targetType) {

}
39 changes: 27 additions & 12 deletions src/test/java/io/spring/jdbc/oracle/accessor/ClassRecordTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,50 @@
import static org.assertj.core.api.Assertions.assertThatNullPointerException;

import java.math.BigDecimal;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
class ClassRecordTest {

@Test
void when_class_is_null() {
void throw_exception_when_class_is_null() {

assertThatNullPointerException()
.isThrownBy(() -> new ClassRecord<>(null));
}

@Test
void when_class_is_not_record_type() {
@Nested
@DisplayName("method isTypeRecord")
class IsTypeRecord {

assertThat(new ClassRecord<>(Object.class).isTypeRecord())
.isFalse();
@Test
void return_false_when_class_is_not_record_type() {

assertThat(new ClassRecord<>(BigDecimal.class).isTypeRecord())
.isFalse();
}
assertThat(new ClassRecord<>(Object.class).isTypeRecord())
.isFalse();

@Test
void when_class_is_record_type() {
assertThat(new ClassRecord<>(BigDecimal.class).isTypeRecord())
.isFalse();
}

@Test
void return_true_when_class_is_record_type() {

assertThat(new ClassRecord<>(Record.class).isTypeRecord())
.isTrue();

assertThat(new ClassRecord<>(RecordTest.class).isTypeRecord())
.isTrue();
}

record RecordTest() {

}

assertThat(new ClassRecord<>(Record.class).isTypeRecord())
.isTrue();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.spring.jdbc.oracle.accessor;

import static io.spring.jdbc.oracle.utils.Strings.NOT_BLANK;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatNullPointerException;
Expand All @@ -13,47 +14,48 @@
class ParameterAccessorTest {

@Test
void when_parameterName_is_blank() {
void throw_exception_when_parameterName_is_blank() {

var msg = NOT_BLANK.formatted("parameter ");

assertThatExceptionOfType(ValueException.class)
.isThrownBy(() -> new ParameterAccessorImpl<>(null, Record.class));
.isThrownBy(() -> new ParameterAccessorImpl<>(null, Object.class))
.withMessage(msg);

assertThatExceptionOfType(ValueException.class)
.isThrownBy(() -> new ParameterAccessorImpl<>("", Record.class));
.isThrownBy(() -> new ParameterAccessorImpl<>("", Object.class))
.withMessage(msg);

assertThatExceptionOfType(ValueException.class)
.isThrownBy(() -> new ParameterAccessorImpl<>(" ", Record.class));
.isThrownBy(() -> new ParameterAccessorImpl<>(" ", Object.class))
.withMessage(msg);
}

@Test
void when_class_is_not_null() {

// arrange
var x = "X";
var parameterName = "X";
var clazz = Object.class;
void throw_exception_when_class_is_null() {

// assert
var output = new ParameterAccessorImpl<>(x, Object.class);
assertThat(output.getParameterName())
.isEqualTo(parameterName);
assertThat(output.getMappedClass())
.isEqualTo(clazz);
assertThatNullPointerException()
.isThrownBy(() -> new ParameterAccessorImpl<>("X", null));
}

@Test
void when_class_is_null() {
void success_initial_when_parameterName_and_class_are_not_null() {

assertThatNullPointerException()
.isThrownBy(() -> new ParameterAccessorImpl<>("x", null));
// assert
var output = new ParameterAccessorImpl<>("X", Object.class);
assertThat(output.getParameterName())
.isEqualTo("X");
assertThat(output.getMappedClass())
.isEqualTo(Object.class);
}

static class ParameterAccessorImpl<T> extends ParameterAccessor<T> {

public ParameterAccessorImpl(String parameterName, Class<T> mappedClass) {
ParameterAccessorImpl(String parameterName, Class<T> mappedClass) {

super(parameterName, mappedClass);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void set_converters() {
mapper.setConverters(new OracleConverters() {

@Override
public void addGenericConverter(GenericOracleConverter<?, ?> converterFactory) {
public void addGenericConverter(GenericOracleConverter converterFactory) {

}

Expand Down
1 change: 1 addition & 0 deletions src/test/java/io/spring/jdbc/oracle/utils/StringsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void equals_ignore_case() {
assertFalse(Strings.equalsIgnoreCase("X", null));

assertTrue(Strings.equalsIgnoreCase("X", "x"));
assertTrue(Strings.equalsIgnoreCase("X", "X"));
}

}

0 comments on commit 0198234

Please sign in to comment.