Skip to content

Commit

Permalink
Add TransUnitInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
alaugks committed Sep 24, 2024
1 parent 992f8d1 commit 7968257
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import io.github.alaugks.spring.messagesource.catalog.catalog.Catalog;
import io.github.alaugks.spring.messagesource.catalog.catalog.CatalogCache;
import io.github.alaugks.spring.messagesource.catalog.catalog.CatalogInterface;
import io.github.alaugks.spring.messagesource.catalog.records.TransUnit;
import io.github.alaugks.spring.messagesource.catalog.records.TransUnitInterface;

import org.springframework.context.support.AbstractMessageSource;
import org.springframework.util.Assert;
Expand All @@ -20,7 +20,7 @@ private CatalogMessageSourceBuilder(CatalogInterface catalog) {
this.catalog = catalog;
}

public static Builder builder(List<TransUnit> transUnits, Locale defaultLocale) {
public static Builder builder(List<TransUnitInterface> transUnits, Locale defaultLocale) {
Assert.notNull(transUnits, "Argument transUnits must not be null");

return builder(new TransUnitsCatalog(transUnits), defaultLocale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
import java.util.List;

import io.github.alaugks.spring.messagesource.catalog.catalog.AbstractCatalog;
import io.github.alaugks.spring.messagesource.catalog.records.TransUnit;
import io.github.alaugks.spring.messagesource.catalog.records.TransUnitInterface;

public class TransUnitsCatalog extends AbstractCatalog {

List<TransUnit> transUnits;
List<TransUnitInterface> transUnits;

public TransUnitsCatalog(List<TransUnit> transUnits) {
public TransUnitsCatalog(List<TransUnitInterface> transUnits) {
this.transUnits = transUnits;
}

@Override
public List<TransUnit> getTransUnits() {
public List<TransUnitInterface> getTransUnits() {
return this.transUnits;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.Locale;
import java.util.Optional;

import io.github.alaugks.spring.messagesource.catalog.records.TransUnit;
import io.github.alaugks.spring.messagesource.catalog.records.TransUnitInterface;

public abstract class AbstractCatalog implements CatalogInterface {

Expand All @@ -16,7 +16,7 @@ public CatalogInterface nextCatalog(CatalogInterface catalog) {
return catalog;
}

public List<TransUnit> getTransUnits() {
public List<TransUnitInterface> getTransUnits() {
if (this.nextCatalog == null) {
return new ArrayList<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import java.util.List;
import java.util.Locale;

import io.github.alaugks.spring.messagesource.catalog.records.TransUnit;
import io.github.alaugks.spring.messagesource.catalog.records.TransUnitInterface;

public interface CatalogInterface {

CatalogInterface nextCatalog(CatalogInterface handler);

List<TransUnit> getTransUnits();
List<TransUnitInterface> getTransUnits();

String resolveCode(Locale locale, String code);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.Locale;

public record TransUnit(Locale locale, String code, String value, String domain) {
public record TransUnit(Locale locale, String code, String value, String domain) implements TransUnitInterface {

public TransUnit(Locale locale, String code, String value) {
this(locale, code, value, null);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.alaugks.spring.messagesource.catalog.records;

import java.util.Locale;

public interface TransUnitInterface {
Locale locale();

String code();

String value();

String domain();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import io.github.alaugks.spring.messagesource.catalog.catalog.CatalogInterface;
import io.github.alaugks.spring.messagesource.catalog.records.TransUnit;
import io.github.alaugks.spring.messagesource.catalog.records.TransUnitInterface;
import io.github.alaugks.spring.messagesource.catalog.records.TranslationFile;
import io.github.alaugks.spring.messagesource.catalog.ressources.ResourcesLoader;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -166,7 +167,7 @@ private static Stream<Arguments> dataProvider_examples() {
}

private static CatalogInterface createTransUnitListFromMessagesPropertiesFiles() throws IOException {
List<TransUnit> transUnits = new ArrayList<>();
List<TransUnitInterface> transUnits = new ArrayList<>();

var resourcesLoader = new ResourcesLoader(
Locale.forLanguageTag("en"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
import java.util.Locale;

import io.github.alaugks.spring.messagesource.catalog.records.TransUnit;
import io.github.alaugks.spring.messagesource.catalog.records.TransUnitInterface;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;

import static org.junit.jupiter.api.Assertions.assertEquals;

@SuppressWarnings({"java:S4144"})
@TestMethodOrder(OrderAnnotation.class)
class CatalogMessageSourceBuilderTest {

public final Locale locale = Locale.forLanguageTag("en");

@Test
void test_builder_withList() {
List<TransUnit> transUnits = List.of(
List<TransUnitInterface> transUnits = List.of(
new TransUnit(this.locale, "key", "messages_value")
);

Expand All @@ -32,7 +32,7 @@ void test_builder_withList() {

@Test
void test_builder_withCatalogInterface() {
List<TransUnit> transUnits = List.of(
List<TransUnitInterface> transUnits = List.of(
new TransUnit(this.locale, "key", "messages_value")
);

Expand All @@ -47,7 +47,7 @@ void test_builder_withCatalogInterface() {

@Test
void test_withSetDefaultDomain() {
List<TransUnit> transUnits = List.of(
List<TransUnitInterface> transUnits = List.of(
new TransUnit(this.locale, "key", "messages_value"),
new TransUnit(this.locale, "key", "foo_value", "foo")
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import io.github.alaugks.spring.messagesource.catalog.TransUnitsCatalog;
import io.github.alaugks.spring.messagesource.catalog.records.TransUnit;
import io.github.alaugks.spring.messagesource.catalog.records.TransUnitInterface;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -19,7 +20,7 @@ class CatalogTest {
@BeforeEach
void BeforeEach() {

List<TransUnit> transUnits = new ArrayList<>();
List<TransUnitInterface> transUnits = new ArrayList<>();

// Domain messages
transUnits.add(new TransUnit(Locale.forLanguageTag("en"), "key_1", "value_en_1"));
Expand Down

0 comments on commit 7968257

Please sign in to comment.