• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

trydofor / professional-wings / #140

08 Feb 2025 09:13AM UTC coverage: 63.606% (-0.08%) from 63.687%
#140

push

web-flow
Merge pull request #316 from trydofor/develop

release of 3.3.140

242 of 343 new or added lines in 58 files covered. (70.55%)

55 existing lines in 6 files now uncovered.

12926 of 20322 relevant lines covered (63.61%)

0.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.75
/wings/silencer/src/main/java/pro/fessional/wings/silencer/message/MessageSourceHelper.java
1
package pro.fessional.wings.silencer.message;
2

3
import org.jetbrains.annotations.NotNull;
4
import org.springframework.context.HierarchicalMessageSource;
5
import org.springframework.context.MessageSource;
6
import org.springframework.context.MessageSourceResolvable;
7
import org.springframework.context.NoSuchMessageException;
8
import pro.fessional.mirana.i18n.I18nAware;
9
import pro.fessional.mirana.i18n.I18nAware.I18nSource;
10

11
import java.util.Locale;
12

13
/**
14
 * @author trydofor
15
 * @since 2023-11-24
16
 */
17
public class MessageSourceHelper {
18

19
    public static final MessageSource Dummy = new MessageSource() {
1✔
20
        @Override
21
        public String getMessage(@NotNull String code, Object[] args, String defaultMessage, @NotNull Locale locale) {
22
            throw new IllegalStateException("should bind before using");
×
23
        }
24

25
        @Override
26
        @NotNull
27
        public String getMessage(@NotNull String code, Object[] args, @NotNull Locale locale) throws NoSuchMessageException {
UNCOV
28
            throw new IllegalStateException("should bind before using");
×
29
        }
30

31
        @Override
32
        @NotNull
33
        public String getMessage(@NotNull MessageSourceResolvable resolvable, @NotNull Locale locale) throws NoSuchMessageException {
UNCOV
34
            throw new IllegalStateException("should bind before using");
×
35
        }
36
    };
37

38
    public static final CombinableMessageSource Combine = new CombinableMessageSource();
1✔
39

40
    protected static volatile MessageSource Primary = Dummy;
1✔
41
    protected static volatile I18nSource i18nSource = Dummy::getMessage;
1✔
42
    protected static volatile boolean hasPrimary = false;
1✔
43
    protected static volatile boolean hasCombine = false;
1✔
44

NEW
45
    public MessageSourceHelper() {
×
NEW
46
    }
×
47

48
    protected MessageSourceHelper(@NotNull MessageSource primary) {
1✔
49
        synchronized (MessageSourceHelper.class) {
1✔
50
            if (primary instanceof HierarchicalMessageSource hierarchy) {
1✔
51
                MessageSource parent = hierarchy.getParentMessageSource();
1✔
52
                if (parent != null) {
1✔
53
                    Combine.setParentMessageSource(parent);
×
54
                }
55
                hierarchy.setParentMessageSource(Combine);
1✔
56
                hasCombine = true;
1✔
57
            }
58

59
            Primary = primary;
1✔
60
            i18nSource = primary::getMessage;
1✔
61
            hasPrimary = true;
1✔
62
        }
1✔
63
    }
1✔
64

65
    public static MessageSource Primary() {
NEW
66
        return Primary;
×
67
    }
68

69
    public static boolean hasPrimary() {
70
        return hasPrimary;
1✔
71
    }
72

73
    public static boolean hasCombine() {
74
        return hasCombine;
1✔
75
    }
76

77
    public static I18nSource i18nSource() {
78
        return i18nSource;
1✔
79
    }
80

81
    public static String getMessage(@NotNull String code, Object[] args, String defaultMessage, @NotNull Locale locale) {
NEW
82
        return Primary.getMessage(code, args, defaultMessage, locale);
×
83
    }
84

85
    @NotNull
86
    public static String getMessage(@NotNull String code, Object[] args, @NotNull Locale locale) throws NoSuchMessageException {
87
        return Primary.getMessage(code, args, locale);
1✔
88
    }
89

90
    @NotNull
91
    public static String getMessage(@NotNull MessageSourceResolvable resolvable, @NotNull Locale locale) throws NoSuchMessageException {
NEW
92
        return Primary.getMessage(resolvable, locale);
×
93
    }
94

95
    @NotNull
96
    public static String getMessage(@NotNull I18nAware i18nAware, @NotNull Locale locale) throws NoSuchMessageException {
NEW
97
        return i18nAware.toString(locale, i18nSource);
×
98
    }
99
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc