-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It's not needed. Make it a record and validate the state properly. Add more validations for Ingredient.
- Loading branch information
1 parent
6db0078
commit e7b6412
Showing
37 changed files
with
755 additions
and
836 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
18 changes: 8 additions & 10 deletions
18
...tocrafting-api/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/Pattern.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,20 +1,18 @@ | ||
package com.refinedmods.refinedstorage.api.autocrafting; | ||
|
||
import com.refinedmods.refinedstorage.api.core.CoreValidations; | ||
import com.refinedmods.refinedstorage.api.resource.ResourceAmount; | ||
import com.refinedmods.refinedstorage.api.resource.ResourceKey; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
@API(status = API.Status.STABLE, since = "2.0.0-milestone.4.6") | ||
public interface Pattern { | ||
Set<ResourceKey> getInputResources(); | ||
|
||
Set<ResourceKey> getOutputResources(); | ||
|
||
List<Ingredient> getIngredients(); | ||
|
||
List<ResourceAmount> getOutputs(); | ||
public record Pattern(List<Ingredient> ingredients, List<ResourceAmount> outputs) { | ||
public Pattern(final List<Ingredient> ingredients, final List<ResourceAmount> outputs) { | ||
CoreValidations.validateNotEmpty(ingredients, "Ingredients cannot be empty"); | ||
CoreValidations.validateNotEmpty(outputs, "Outputs cannot be empty"); | ||
this.ingredients = List.copyOf(ingredients); | ||
this.outputs = List.copyOf(outputs); | ||
} | ||
} |
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
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
79 changes: 79 additions & 0 deletions
79
...ing-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/IngredientTest.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,79 @@ | ||
package com.refinedmods.refinedstorage.api.autocrafting; | ||
|
||
import com.refinedmods.refinedstorage.api.resource.ResourceKey; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.assertj.core.api.ThrowableAssert; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import static com.refinedmods.refinedstorage.api.autocrafting.ResourceFixtures.A; | ||
import static com.refinedmods.refinedstorage.api.autocrafting.ResourceFixtures.B; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
class IngredientTest { | ||
@Test | ||
void testIngredient() { | ||
// Act | ||
final Ingredient sut = new Ingredient(1, List.of(A, B)); | ||
|
||
// Assert | ||
assertThat(sut.size()).isEqualTo(2); | ||
assertThat(sut.getAmount()).isEqualTo(1); | ||
assertThat(sut.get(0)).isEqualTo(A); | ||
assertThat(sut.get(1)).isEqualTo(B); | ||
assertThat(sut.getAll()).containsExactly(A, B); | ||
} | ||
|
||
@Test | ||
void shouldCopyIngredients() { | ||
// Arrange | ||
final List<ResourceKey> outputs = new ArrayList<>(); | ||
outputs.add(A); | ||
|
||
// Act | ||
final Ingredient sut = new Ingredient(1, outputs); | ||
outputs.add(B); | ||
|
||
// Assert | ||
assertThat(sut.size()).isEqualTo(1); | ||
assertThat(sut.get(0)).isEqualTo(A); | ||
assertThat(sut.getAll()).containsExactly(A); | ||
} | ||
|
||
@Test | ||
void shouldNotBeAbleToModifyIngredients() { | ||
// Arrange | ||
final Ingredient sut = new Ingredient(1, List.of(A)); | ||
final List<ResourceKey> items = sut.getAll(); | ||
|
||
// Act | ||
final ThrowableAssert.ThrowingCallable action = () -> items.add(B); | ||
|
||
// Assert | ||
assertThatThrownBy(action).isInstanceOf(UnsupportedOperationException.class); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(longs = {0, -1}) | ||
void shouldNotCreateIngredientWithInvalidAmount(final long amount) { | ||
// Arrange | ||
final ThrowableAssert.ThrowingCallable action = () -> new Ingredient(amount, List.of(A, B)); | ||
|
||
// Assert | ||
assertThatThrownBy(action).isInstanceOf(IllegalArgumentException.class); | ||
} | ||
|
||
@Test | ||
void shouldNotCreateIngredientWithEmptyInputs() { | ||
// Act | ||
final ThrowableAssert.ThrowingCallable action = () -> new Ingredient(1, List.of()); | ||
|
||
// Assert | ||
assertThatThrownBy(action).isInstanceOf(IllegalArgumentException.class); | ||
} | ||
} |
49 changes: 0 additions & 49 deletions
49
...afting-api/src/test/java/com/refinedmods/refinedstorage/api/autocrafting/PatternImpl.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.