Skip to content

Commit

Permalink
Oops, forgot header & formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim203 committed Jul 13, 2023
1 parent 0afeb91 commit d5579fc
Showing 1 changed file with 77 additions and 53 deletions.
130 changes: 77 additions & 53 deletions core/src/test/java/net/kyori/moonshine/NestedMoonshineTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* moonshine - A localisation library for Java.
* Copyright (C) Mariell Hoversholm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.kyori.moonshine;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -13,70 +30,77 @@
import org.junit.jupiter.api.Test;

class NestedMoonshineTest {
@Test
void simpleNestedMoonshine() throws UnscannableMethodException {
SimpleNestedMoonshineRoot root = moonshineWith(SimpleNestedMoonshineRoot.class, (receiver, messageKey) -> {
if ("test".equals(messageKey)) {
@Test
void simpleNestedMoonshine() throws UnscannableMethodException {
final SimpleNestedMoonshineRoot root =
this.moonshineWith(
SimpleNestedMoonshineRoot.class,
(receiver, messageKey) -> {
if ("test".equals(messageKey)) {
return "ok";
}
return null;
});
assertEquals("ok", root.child().test());
}
}
return null;
});
assertEquals("ok", root.child().test());
}

@Test
void complexNestedMoonshine() throws UnscannableMethodException {
ComplexNestedMoonshineRoot root = moonshineWith(ComplexNestedMoonshineRoot.class, (receiver, messageKey) -> {
if ("complex.child.child-test".equals(messageKey)) {
@Test
void complexNestedMoonshine() throws UnscannableMethodException {
final ComplexNestedMoonshineRoot root =
this.moonshineWith(
ComplexNestedMoonshineRoot.class,
(receiver, messageKey) -> {
if ("complex.child.child-test".equals(messageKey)) {
return "ok";
}
if ("complex.child.child-oke-ok.done".equals(messageKey)) {
}
if ("complex.child.child-oke-ok.done".equals(messageKey)) {
return "yes";
}
return null;
});
assertEquals("ok", root.child().test());
assertEquals("yes", root.child().oke().done());
}
}
return null;
});
assertEquals("ok", root.child().test());
assertEquals("yes", root.child().oke().done());
}

private <T> T moonshineWith(Class<T> type, IMessageSource<Unit, ?> sourced) throws UnscannableMethodException {
return Moonshine.<T, Unit>builder(TypeToken.get(type))
.receiverLocatorResolver((method, proxy) -> (method1, proxy1, arguments) -> null, 1)
.sourced(sourced)
.rendered((receiver, intermediateMessage, resolvedPlaceholders, method, owner) -> intermediateMessage)
.sent((receiver, renderedMessage) -> {})
.resolvingWithStrategy(new StandardPlaceholderResolverStrategy<>(new StandardSupertypeThenInterfaceSupertypeStrategy(false)))
.create();
}
private <T> T moonshineWith(final Class<T> type, final IMessageSource<Unit, ?> sourced)
throws UnscannableMethodException {
return Moonshine.<T, Unit>builder(TypeToken.get(type))
.receiverLocatorResolver((method, proxy) -> (method1, proxy1, arguments) -> null, 1)
.sourced(sourced)
.rendered((receiver, intermediateMessage, resolvedPlaceholders, method, owner) -> intermediateMessage)
.sent((receiver, renderedMessage) -> {})
.resolvingWithStrategy(new StandardPlaceholderResolverStrategy<>(new StandardSupertypeThenInterfaceSupertypeStrategy(false)))
.create();
}

interface SimpleNestedMoonshineRoot {
SimpleNestedMoonshineChild child();
interface SimpleNestedMoonshineRoot {
SimpleNestedMoonshineChild child();

@MessageSection
interface SimpleNestedMoonshineChild {
@Message("test")
String test();
}
@MessageSection
interface SimpleNestedMoonshineChild {
@Message("test")
String test();
}
}

@MessageSection("complex")
interface ComplexNestedMoonshineRoot {
@Message("child")
ComplexNestedMoonshineChild child();
@MessageSection("complex")
interface ComplexNestedMoonshineRoot {
@Message("child")
ComplexNestedMoonshineChild child();

@MessageSection(value = "child", delimiter = '-')
interface ComplexNestedMoonshineChild {
@Message("test")
String test();
@MessageSection(value = "child", delimiter = '-')
interface ComplexNestedMoonshineChild {
@Message("test")
String test();

@Message("oke")
ComplexNestedMoonshineChildChild oke();
@Message("oke")
ComplexNestedMoonshineChildChild oke();

@MessageSection("ok")
interface ComplexNestedMoonshineChildChild {
@Message("done")
String done();
}
}
@MessageSection("ok")
interface ComplexNestedMoonshineChildChild {
@Message("done")
String done();
}
}
}
}

0 comments on commit d5579fc

Please sign in to comment.