|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the "Elastic License |
| 4 | + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side |
| 5 | + * Public License v 1"; you may not use this file except in compliance with, at |
| 6 | + * your election, the "Elastic License 2.0", the "GNU Affero General Public |
| 7 | + * License v3.0 only", or the "Server Side Public License, v 1". |
| 8 | + */ |
| 9 | + |
| 10 | +package org.elasticsearch.entitlement.qa.common; |
| 11 | + |
| 12 | +import java.text.BreakIterator; |
| 13 | +import java.text.Collator; |
| 14 | +import java.text.DateFormat; |
| 15 | +import java.text.DateFormatSymbols; |
| 16 | +import java.text.DecimalFormatSymbols; |
| 17 | +import java.text.NumberFormat; |
| 18 | +import java.text.spi.BreakIteratorProvider; |
| 19 | +import java.text.spi.CollatorProvider; |
| 20 | +import java.text.spi.DateFormatProvider; |
| 21 | +import java.text.spi.DateFormatSymbolsProvider; |
| 22 | +import java.text.spi.DecimalFormatSymbolsProvider; |
| 23 | +import java.text.spi.NumberFormatProvider; |
| 24 | +import java.util.Locale; |
| 25 | +import java.util.Map; |
| 26 | +import java.util.spi.CalendarDataProvider; |
| 27 | +import java.util.spi.CalendarNameProvider; |
| 28 | +import java.util.spi.CurrencyNameProvider; |
| 29 | +import java.util.spi.LocaleNameProvider; |
| 30 | +import java.util.spi.LocaleServiceProvider; |
| 31 | +import java.util.spi.TimeZoneNameProvider; |
| 32 | + |
| 33 | +/** |
| 34 | + * A collection of concrete subclasses that we can instantiate but that don't actually work. |
| 35 | + * <p> |
| 36 | + * A bit like Mockito but way more painful. |
| 37 | + */ |
| 38 | +class DummyImplementations { |
| 39 | + |
| 40 | + static class DummyLocaleServiceProvider extends LocaleServiceProvider { |
| 41 | + |
| 42 | + @Override |
| 43 | + public Locale[] getAvailableLocales() { |
| 44 | + throw unexpected(); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + static class DummyBreakIteratorProvider extends BreakIteratorProvider { |
| 49 | + |
| 50 | + @Override |
| 51 | + public BreakIterator getWordInstance(Locale locale) { |
| 52 | + throw unexpected(); |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public BreakIterator getLineInstance(Locale locale) { |
| 57 | + throw unexpected(); |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + public BreakIterator getCharacterInstance(Locale locale) { |
| 62 | + throw unexpected(); |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + public BreakIterator getSentenceInstance(Locale locale) { |
| 67 | + throw unexpected(); |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + public Locale[] getAvailableLocales() { |
| 72 | + throw unexpected(); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + static class DummyCollatorProvider extends CollatorProvider { |
| 77 | + |
| 78 | + @Override |
| 79 | + public Collator getInstance(Locale locale) { |
| 80 | + throw unexpected(); |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + public Locale[] getAvailableLocales() { |
| 85 | + throw unexpected(); |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + static class DummyDateFormatProvider extends DateFormatProvider { |
| 90 | + |
| 91 | + @Override |
| 92 | + public DateFormat getTimeInstance(int style, Locale locale) { |
| 93 | + throw unexpected(); |
| 94 | + } |
| 95 | + |
| 96 | + @Override |
| 97 | + public DateFormat getDateInstance(int style, Locale locale) { |
| 98 | + throw unexpected(); |
| 99 | + } |
| 100 | + |
| 101 | + @Override |
| 102 | + public DateFormat getDateTimeInstance(int dateStyle, int timeStyle, Locale locale) { |
| 103 | + throw unexpected(); |
| 104 | + } |
| 105 | + |
| 106 | + @Override |
| 107 | + public Locale[] getAvailableLocales() { |
| 108 | + throw unexpected(); |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + static class DummyDateFormatSymbolsProvider extends DateFormatSymbolsProvider { |
| 113 | + |
| 114 | + @Override |
| 115 | + public DateFormatSymbols getInstance(Locale locale) { |
| 116 | + throw unexpected(); |
| 117 | + } |
| 118 | + |
| 119 | + @Override |
| 120 | + public Locale[] getAvailableLocales() { |
| 121 | + throw unexpected(); |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | + static class DummyDecimalFormatSymbolsProvider extends DecimalFormatSymbolsProvider { |
| 126 | + |
| 127 | + @Override |
| 128 | + public DecimalFormatSymbols getInstance(Locale locale) { |
| 129 | + throw unexpected(); |
| 130 | + } |
| 131 | + |
| 132 | + @Override |
| 133 | + public Locale[] getAvailableLocales() { |
| 134 | + throw unexpected(); |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + static class DummyNumberFormatProvider extends NumberFormatProvider { |
| 139 | + |
| 140 | + @Override |
| 141 | + public NumberFormat getCurrencyInstance(Locale locale) { |
| 142 | + throw unexpected(); |
| 143 | + } |
| 144 | + |
| 145 | + @Override |
| 146 | + public NumberFormat getIntegerInstance(Locale locale) { |
| 147 | + throw unexpected(); |
| 148 | + } |
| 149 | + |
| 150 | + @Override |
| 151 | + public NumberFormat getNumberInstance(Locale locale) { |
| 152 | + throw unexpected(); |
| 153 | + } |
| 154 | + |
| 155 | + @Override |
| 156 | + public NumberFormat getPercentInstance(Locale locale) { |
| 157 | + throw unexpected(); |
| 158 | + } |
| 159 | + |
| 160 | + @Override |
| 161 | + public Locale[] getAvailableLocales() { |
| 162 | + throw unexpected(); |
| 163 | + } |
| 164 | + } |
| 165 | + |
| 166 | + static class DummyCalendarDataProvider extends CalendarDataProvider { |
| 167 | + |
| 168 | + @Override |
| 169 | + public int getFirstDayOfWeek(Locale locale) { |
| 170 | + throw unexpected(); |
| 171 | + } |
| 172 | + |
| 173 | + @Override |
| 174 | + public int getMinimalDaysInFirstWeek(Locale locale) { |
| 175 | + throw unexpected(); |
| 176 | + } |
| 177 | + |
| 178 | + @Override |
| 179 | + public Locale[] getAvailableLocales() { |
| 180 | + throw unexpected(); |
| 181 | + } |
| 182 | + } |
| 183 | + |
| 184 | + static class DummyCalendarNameProvider extends CalendarNameProvider { |
| 185 | + |
| 186 | + @Override |
| 187 | + public String getDisplayName(String calendarType, int field, int value, int style, Locale locale) { |
| 188 | + throw unexpected(); |
| 189 | + } |
| 190 | + |
| 191 | + @Override |
| 192 | + public Map<String, Integer> getDisplayNames(String calendarType, int field, int style, Locale locale) { |
| 193 | + throw unexpected(); |
| 194 | + } |
| 195 | + |
| 196 | + @Override |
| 197 | + public Locale[] getAvailableLocales() { |
| 198 | + throw unexpected(); |
| 199 | + } |
| 200 | + } |
| 201 | + |
| 202 | + static class DummyCurrencyNameProvider extends CurrencyNameProvider { |
| 203 | + |
| 204 | + @Override |
| 205 | + public String getSymbol(String currencyCode, Locale locale) { |
| 206 | + throw unexpected(); |
| 207 | + } |
| 208 | + |
| 209 | + @Override |
| 210 | + public Locale[] getAvailableLocales() { |
| 211 | + throw unexpected(); |
| 212 | + } |
| 213 | + } |
| 214 | + |
| 215 | + static class DummyLocaleNameProvider extends LocaleNameProvider { |
| 216 | + |
| 217 | + @Override |
| 218 | + public String getDisplayLanguage(String languageCode, Locale locale) { |
| 219 | + throw unexpected(); |
| 220 | + } |
| 221 | + |
| 222 | + @Override |
| 223 | + public String getDisplayCountry(String countryCode, Locale locale) { |
| 224 | + throw unexpected(); |
| 225 | + } |
| 226 | + |
| 227 | + @Override |
| 228 | + public String getDisplayVariant(String variant, Locale locale) { |
| 229 | + throw unexpected(); |
| 230 | + } |
| 231 | + |
| 232 | + @Override |
| 233 | + public Locale[] getAvailableLocales() { |
| 234 | + throw unexpected(); |
| 235 | + } |
| 236 | + } |
| 237 | + |
| 238 | + static class DummyTimeZoneNameProvider extends TimeZoneNameProvider { |
| 239 | + |
| 240 | + @Override |
| 241 | + public String getDisplayName(String ID, boolean daylight, int style, Locale locale) { |
| 242 | + throw unexpected(); |
| 243 | + } |
| 244 | + |
| 245 | + @Override |
| 246 | + public Locale[] getAvailableLocales() { |
| 247 | + throw unexpected(); |
| 248 | + } |
| 249 | + } |
| 250 | + |
| 251 | + private static RuntimeException unexpected() { |
| 252 | + return new IllegalStateException("This method isn't supposed to be called"); |
| 253 | + } |
| 254 | + |
| 255 | +} |
0 commit comments