Skip to content

Commit c79910f

Browse files
committed
test: Add whenLocaleIsEnUS_thenErrorCountShouldMatch()
1 parent 3fbea37 commit c79910f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

hivemq-edge/src/test/java/com/hivemq/common/i18n/OpenAPIHttpErrorTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,20 @@
1616

1717
package com.hivemq.common.i18n;
1818

19+
import org.apache.commons.io.IOUtils;
1920
import org.junit.jupiter.api.AfterEach;
2021
import org.junit.jupiter.api.BeforeEach;
2122
import org.junit.jupiter.api.Test;
2223

24+
import java.io.IOException;
25+
import java.io.StringReader;
26+
import java.nio.charset.StandardCharsets;
27+
import java.util.Arrays;
28+
import java.util.List;
2329
import java.util.Locale;
2430
import java.util.Map;
31+
import java.util.Properties;
32+
import java.util.Set;
2533

2634
import static org.assertj.core.api.Assertions.assertThat;
2735

@@ -36,6 +44,25 @@ public void tearDown() {
3644
LocaleContext.setLocale(LocaleContext.DEFAULT_LOCALE);
3745
}
3846

47+
@Test
48+
public void whenLocaleIsEnUS_thenErrorCountShouldMatch() throws IOException {
49+
final List<OpenAPIHttpError> errors = Arrays.asList(OpenAPIHttpError.values());
50+
assertThat(errors.size()).isGreaterThan(0);
51+
final Properties properties = new Properties();
52+
try (final StringReader stringReader = new StringReader(IOUtils.resourceToString(errors.get(0)
53+
.getResourceName(), StandardCharsets.UTF_8))) {
54+
properties.load(stringReader);
55+
}
56+
assertThat(properties.size()).isEqualTo(errors.size());
57+
final Set<Object> keySet = properties.keySet();
58+
errors.forEach(error -> assertThat(keySet.contains(error.getKey())).as(error.getKey() + " is not found.")
59+
.isTrue());
60+
properties.values().forEach(template -> {
61+
assertThat(template).isInstanceOf(String.class);
62+
assertThat((String) template).isNotBlank();
63+
});
64+
}
65+
3966
@Test
4067
public void whenLocaleIsEnUS_thenHttpError400ShouldWork() {
4168
assertThat(OpenAPIHttpError.HTTP_ERROR_400_INVALID_QUERY_PARAMETER_TITLE.get()).isEqualTo(

0 commit comments

Comments
 (0)