-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#189. New field value changer and documentations improvements
- Loading branch information
Showing
4 changed files
with
136 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/pl/pojo/tester/internal/field/date/InstantFieldValueChanger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package pl.pojo.tester.internal.field.date; | ||
|
||
import pl.pojo.tester.internal.field.AbstractFieldValueChanger; | ||
|
||
import java.time.Instant; | ||
|
||
class InstantFieldValueChanger extends AbstractFieldValueChanger<Instant> { | ||
|
||
@Override | ||
protected Instant increaseValue(final Instant value, final Class<?> type) { | ||
return value.plusSeconds(3600); | ||
} | ||
|
||
@Override | ||
protected boolean canChange(final Class<?> type) { | ||
return type.equals(Instant.class); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
src/test/java/pl/pojo/tester/internal/field/date/InstantFieldValueChangerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package pl.pojo.tester.internal.field.date; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.junit.jupiter.api.DynamicTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestFactory; | ||
import org.junit.jupiter.api.function.Executable; | ||
|
||
import java.time.Instant; | ||
import java.util.Date; | ||
import java.util.stream.Stream; | ||
|
||
import static helpers.TestHelper.getDefaultDisplayName; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.DynamicTest.dynamicTest; | ||
|
||
class InstantFieldValueChangerTest { | ||
|
||
private final InstantFieldValueChanger valueChanger = new InstantFieldValueChanger(); | ||
|
||
@TestFactory | ||
public Stream<DynamicTest> Should_Return_True_Or_False_Whether_Values_Are_Different_Or_Not() { | ||
final Instant instant1 = new Date(123456).toInstant(); | ||
final Instant instant2 = new Date(654321).toInstant(); | ||
return Stream.of(new AreDifferentCase(null, null, false), | ||
new AreDifferentCase(instant1, instant1, false), | ||
new AreDifferentCase(null, instant2, true), | ||
new AreDifferentCase(instant1, null, true), | ||
new AreDifferentCase(instant1, instant2, true)) | ||
.map(value -> dynamicTest(getDefaultDisplayName(value.value1 + " " + value.value2), | ||
Should_Return_True_Or_False_Whether_Values_Are_Different_Or_Not(value))); | ||
} | ||
|
||
public Executable Should_Return_True_Or_False_Whether_Values_Are_Different_Or_Not(final AreDifferentCase testCase) { | ||
return () -> { | ||
// when | ||
final boolean result = valueChanger.areDifferentValues(testCase.value1, testCase.value2); | ||
|
||
// then | ||
assertThat(result).isEqualTo(testCase.result); | ||
}; | ||
} | ||
|
||
@Test | ||
public void Should_Increase_Value() { | ||
// given | ||
final Instant beforeChange = new Date().toInstant(); | ||
|
||
// when | ||
final Instant result = valueChanger.increaseValue(beforeChange, beforeChange.getClass()); | ||
|
||
// then | ||
assertThat(result).isNotEqualTo(beforeChange); | ||
} | ||
|
||
@Test | ||
public void Should_Return_True_If_Can_Change() { | ||
// given | ||
|
||
// when | ||
final boolean result = valueChanger.canChange(Instant.class); | ||
|
||
// then | ||
assertThat(result).isTrue(); | ||
} | ||
|
||
@Test | ||
public void Should_Return_False_If_Can_Not_Change() { | ||
// given | ||
|
||
// when | ||
final boolean result = valueChanger.canChange(String.class); | ||
|
||
// then | ||
assertThat(result).isFalse(); | ||
} | ||
|
||
@AllArgsConstructor | ||
private class AreDifferentCase { | ||
|
||
private Instant value1; | ||
private Instant value2; | ||
private boolean result; | ||
} | ||
} |