-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: check for pre-defined specimen in factory
Refs: #98
- Loading branch information
1 parent
b099bba
commit f0d872d
Showing
7 changed files
with
28 additions
and
113 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
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
31 changes: 7 additions & 24 deletions
31
src/test/java/com/github/nylle/javafixture/specimen/EnumSpecimenTest.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 |
---|---|---|
@@ -1,63 +1,46 @@ | ||
package com.github.nylle.javafixture.specimen; | ||
|
||
import com.github.nylle.javafixture.Configuration; | ||
import com.github.nylle.javafixture.Context; | ||
import com.github.nylle.javafixture.SpecimenType; | ||
import com.github.nylle.javafixture.testobjects.TestEnum; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.util.Map; | ||
|
||
import static com.github.nylle.javafixture.Configuration.configure; | ||
import static com.github.nylle.javafixture.CustomizationContext.noContext; | ||
import static com.github.nylle.javafixture.Fixture.fixture; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatCode; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
class EnumSpecimenTest { | ||
|
||
@Test | ||
void typeIsRequired() { | ||
assertThatThrownBy(() -> new EnumSpecimen<>(null, new Context(configure()))) | ||
assertThatThrownBy(() -> new EnumSpecimen<>(null )) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessageContaining("type: null"); | ||
} | ||
|
||
@Test | ||
void onlyEnumTypes() { | ||
assertThatThrownBy(() -> new EnumSpecimen<>(SpecimenType.fromClass(Object.class), new Context(configure()))) | ||
assertThatThrownBy(() -> new EnumSpecimen<>(SpecimenType.fromClass(Object.class) )) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessageContaining("type: " + Object.class.getName()); | ||
} | ||
|
||
@Test | ||
void contextIsRequired() { | ||
assertThatThrownBy(() -> new EnumSpecimen<>(SpecimenType.fromClass(TestEnum.class), null)) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessageContaining("context: null"); | ||
void contextIsNotRequired() { | ||
assertThatCode(() -> new EnumSpecimen<>(SpecimenType.fromClass(TestEnum.class) )) | ||
.doesNotThrowAnyException(); | ||
} | ||
|
||
@Test | ||
void createEnum() { | ||
var sut = new EnumSpecimen<>(SpecimenType.fromClass(TestEnum.class), new Context(configure())); | ||
var sut = new EnumSpecimen<>(SpecimenType.fromClass(TestEnum.class) ); | ||
|
||
var actual = sut.create(noContext(), new Annotation[0]); | ||
|
||
assertThat(actual).isInstanceOf(TestEnum.class); | ||
assertThat(actual.toString()).isIn("VALUE1", "VALUE2", "VALUE3"); | ||
} | ||
|
||
@Test | ||
void canBePredefined() { | ||
var expected = fixture().create(TestEnum.class); | ||
|
||
var context = new Context(Configuration.configure(), Map.of(SpecimenType.fromClass(TestEnum.class), expected)); | ||
|
||
var sut = new EnumSpecimen<>(SpecimenType.fromClass(TestEnum.class), context); | ||
|
||
var actual = sut.create(noContext(), new Annotation[0]); | ||
|
||
assertThat(actual).isSameAs(expected); | ||
} | ||
} |
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