33 | * The main idea of this library is to use a set of simple runtime exceptions to
34 | * speedup development and make it more professional in the same time. Those
35 | * exceptions should always take the Exception ID (Eid for short) object on
36 | * construction. The Eid object should be generated by developer while writing
37 | * code and committed in the constructor of an exception. This eid object will
38 | * then be reported when that exception is being displayed or logged.
39 | *
40 | * This approach simplifies the management of exceptions in the application and
41 | * allows developers to focus on functionality and code quality, rather than
42 | * coming up with the correct statement for the exception.
43 | *
44 | * This error number is perfect to be displayed on the error "500" page for your
45 | * application as a bug reference. It's good idea, because it is static, so wil
46 | * l not change in subsequent invocations, but it also do not disclose the
47 | * actual reason why bug occurred.
48 | *
49 | * This approach is best to use with tools and IDE plugins like:
50 | *
60 | * We are deeply sorry. A fatal error occurred.
61 | * The reference number is: 20150721:100554
62 | *
63 | * Wait a couple of minutes, and try again. If the
64 | * same error number persists, call IT support.
65 | *
66 | *
67 | * That error page is easy to implement, because all those exceptions implement
68 | * {@link EidContainer} interface.
69 | *
70 | * Usage example:
71 | *
72 | * throw new EidIllegalStateException("20150721:100554", cause);
73 | *
74 | * Example log:
75 | *
76 | * pl.wavesoftware.eid.exceptions.EidIllegalStateException: [20150721:100554]<g0qrwx> => Zipfile in invalid format
77 | * at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
78 | * at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
79 | *
80 | * Caused by: java.util.zip.DataFormatException: Zipfile in invalid format
81 | * at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
82 | * at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
83 | * ... 62 more
84 | *
85 | *
86 | * Eid number contains also additional unique ID to distinguish each single
87 | * exception from others with same Eid.
88 | *
89 | *
Caution
90 | *
91 | * Those classes shouldn't be used in any public API or library - those should
92 | * have proper checked exceptions build in design. It's designed to be used for
93 | * in-house development of end user applications which will report bugs in
94 | * standardized error pages or post them to issue tracker.
95 | *
96 | * Remember! You should never catch a runtime exception, in place other then
97 | * appropriate error page.
98 | *
99 | *
Notice
100 | *
101 | * Check out {@code EidPreconditions} class for ease of use utility checks.
102 | *
103 | * You can tweak behavior of Eid with {@link Configurator}.
104 | *
105 | * @author Krzysztof Suszynski
106 | * @see EidContainer
107 | * @see Configurator
108 | * @since 2.0.0
109 | */
110 | public class DefaultEid implements Eid {
111 |
112 | private static final long serialVersionUID = 20181029193034L;
113 |
114 | private transient String id;
115 | @Nullable
116 | private transient String ref;
117 | private final SerializableSupplier uniqueId = MODULE
118 | .getBinding()
119 | .getFactories()
120 | .getLazyFactory()
121 | .lazy(new Supplier() {
122 | @Override
123 | public String get() {
124 | return MODULE.getBinding()
125 | .getConfigurationSystem()
126 | .getConfiguration()
127 | .getIdGenerator()
128 | .generateUniqId();
129 | }
130 | });
131 |
132 | /**
133 | * Constructor a single value of exception ID.
134 | *
135 | * @param id the exception id, should be uniquely generated by developer
136 | */
137 | public DefaultEid(CharSequence id) {
138 | this.id = validate(id).toString();
139 | this.ref = null;
140 | }
141 |
142 | /**
143 | * Constructor with two values an exception ID and reference of some sort.
144 | * The second reference can be used to hold reference from external system.
145 | *
146 | * @param id the exception id, should be uniquely generated by developer
147 | * @param ref a reference from external system
148 | */
149 | public DefaultEid(CharSequence id, CharSequence ref) {
150 | this.id = validate(id).toString();
151 | this.ref = ref.toString();
152 | }
153 |
154 | /**
155 | * A static factory method for Eid object that takes a single value of
156 | * exception ID.
157 | *
158 | * @param id the exception id, should be uniquely generated by developer
159 | * @return a created Eid object
160 | */
161 | public static Eid eid(String id) {
162 | return new DefaultEid(id);
163 | }
164 |
165 | @Override
166 | public String getId() {
167 | return id;
168 | }
169 |
170 | @Override
171 | @Nullable
172 | public String getRef() {
173 | return ref;
174 | }
175 |
176 | @Override
177 | public boolean hasRef() {
178 | return getRef() != null;
179 | }
180 |
181 | @Override
182 | public String getUnique() {
183 | return uniqueId.get();
184 | }
185 |
186 | @Override
187 | public EidMessage message(
188 | CharSequence messageTemplate,
189 | Object... templateArguments
190 | ) {
191 | return MODULE.getBinding()
192 | .getFactories()
193 | .getMessageFactory()
194 | .create(
195 | this,
196 | messageTemplate,
197 | templateArguments
198 | );
199 | }
200 |
201 | @Override
202 | public String toString() {
203 | return MODULE.getBinding()
204 | .getConfigurationSystem()
205 | .getConfiguration()
206 | .getFormatter()
207 | .format(this);
208 | }
209 |
210 | /*
211 | Suppress warnings id here for null check. Users can pass null event if it's
212 | forbidden.
213 | */
214 | @SuppressWarnings({"ConstantConditions", "squid:S2583"})
215 | private static CharSequence validate(CharSequence id) {
216 | if (id == null) {
217 | throw new IllegalArgumentException("Exception ID can't be null");
218 | }
219 | if (isInvalid(id)) {
220 | throw new IllegalArgumentException(
221 | "Invalid ID given as an Exception ID: " + id
222 | );
223 | }
224 | return id;
225 | }
226 |
227 | private static boolean isInvalid(CharSequence id) {
228 | Validator validator = getValidator();
229 | return validator != null && !validator.isValid(id);
230 | }
231 |
232 | @Nullable
233 | private static Validator getValidator() {
234 | return MODULE.getBinding()
235 | .getConfigurationSystem()
236 | .getConfiguration()
237 | .getValidator();
238 | }
239 | }
240 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/api/Binding.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.api;
18 |
19 | /**
20 | * A binding of Eid library. This interface can be used to completely
21 | * replace original binding with your custom implementation.
22 | *
23 | *
To replace implementation use {@link java.util.ServiceLoader} like:
24 | *
25 | *
META-INF/services/pl.wavesoftware.eid.api.Binding
26 | *
27 | * In that file, place a fully qualified class name of your class that implements
28 | * {@link Binding} interface. It should be called first time you reference an
29 | * {@link Eid}, or and of the eid exceptions, or utility preconditions class.
30 | *
31 | *
Usually it's way easier to just reconfigure existing configuration using
32 | * {@link Configurator} interface.
33 | *
34 | * @author Krzysztof Suszynski
35 | * @see Configurator
36 | * @see java.util.ServiceLoader
37 | * @since 2.0.0
38 | */
39 | public interface Binding {
40 |
41 | /**
42 | * Gets a configuration system
43 | *
44 | * @return a configuration system
45 | */
46 | ConfigurationSystem getConfigurationSystem();
47 |
48 | /**
49 | * Get bound Eid factories to be used to perform various Eid
50 | * related operations.
51 | *
52 | * @return a factories for various Eid related things.
53 | */
54 | EidFactories getFactories();
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/api/Configuration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.api;
18 |
19 | import javax.annotation.Nullable;
20 | import java.util.Locale;
21 | import java.util.TimeZone;
22 |
23 | /**
24 | * Represents a configuration of Eid library. To reconfigure use
25 | * {@link Configurator} interface.
26 | *
27 | * @author Krzysztof Suszynski
28 | * @since 2.0.0
29 | * @see Configurator
30 | */
31 | public interface Configuration {
32 | /**
33 | * Gets a Eid formatter
34 | *
35 | * @return a formatter of Eid
36 | */
37 | Formatter getFormatter();
38 |
39 | /**
40 | * Gets a Eid unique ID generator
41 | *
42 | * @return unique ID generator
43 | */
44 | UniqueIdGenerator getIdGenerator();
45 |
46 | /**
47 | * Gets a Eid validator if set. Returns null if validator wasn't configured.
48 | *
49 | * @return an Eid validator, or null
50 | */
51 | @Nullable
52 | Validator getValidator();
53 |
54 | /**
55 | * Gets a locale to be used when formatting texts. Returns null if locale
56 | * isn't set.
57 | *
58 | * @return a locale to be used when formatting texts, or null
59 | */
60 | @Nullable
61 | Locale getLocale();
62 |
63 | /**
64 | * Gets a time zone to be used when formatting texts. Returns null if time
65 | * zone isn't set.
66 | *
67 | * @return a time zone to be used when formatting texts, or null
68 | */
69 | @Nullable
70 | TimeZone getTimeZone();
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/api/ConfigurationBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.api;
18 |
19 | import javax.annotation.Nullable;
20 | import java.util.Locale;
21 | import java.util.TimeZone;
22 |
23 | /**
24 | * Use {@link Configurator} to configure Eid settings.
25 | *
26 | * @author Krzysztof Suszynski
27 | * @see Configurator
28 | * @since 2.0.0
29 | */
30 | public interface ConfigurationBuilder {
31 |
32 | /**
33 | * Configures a unique ID generator used by Eid objects to generate unique
34 | * part of Eid number.
35 | *
36 | * @param generator a generator of unique ID
37 | * @return a self reference for ease of use
38 | */
39 | ConfigurationBuilder uniqueIdGenerator(UniqueIdGenerator generator);
40 |
41 | /**
42 | * Configures a formatter to be used by Eid numbers.
43 | *
44 | * @param formatter a formatter to be used by Eid formatting and displaying
45 | * @return a self reference for ease of use
46 | */
47 | ConfigurationBuilder formatter(Formatter formatter);
48 |
49 | /**
50 | * Sets a locale to be used when formatting texts. If not set default system
51 | * locale will be used (platform specific). See {@link Locale#getDefault()}.
52 | *
53 | * @param locale a locale to be used, if {@code null} was given default
54 | * locale will be used
55 | * @return a self reference for ease of use
56 | * @see Locale#getDefault()
57 | */
58 | ConfigurationBuilder locale(@Nullable Locale locale);
59 |
60 | /**
61 | * Sets a time zone to be used when formatting texts. If not set, default
62 | * system time zone will be used (platform specific). See
63 | * {@link TimeZone#getDefault()}.
64 | *
65 | * @param zone a time zone to be used, if {@code null} was given default
66 | * time zone will be used
67 | * @return a self reference for ease of use
68 | * @see TimeZone#getDefault()
69 | */
70 | ConfigurationBuilder timezone(@Nullable TimeZone zone);
71 |
72 | /**
73 | * Configures a validator that will be called on each Eid number. By
74 | * default, there is no validator configured for maximum speed. Using this
75 | * validator you can enforce a standardization of Eid numbers.
76 | *
77 | * @param validator a validator to be used, if {@code null} was given
78 | * validator will not be used.
79 | * @return a self reference for ease of use
80 | */
81 | ConfigurationBuilder validator(@Nullable Validator validator);
82 |
83 | /**
84 | * Gets an object that is a future configuration, to be used to cross
85 | * configure elements of the configuration.
86 | *
87 | * It might throw exceptions if configuration isn't completed so use it
88 | * only if configuration is done.
89 | *
90 | * @return a future configuration
91 | */
92 | Configuration getFutureConfiguration();
93 | }
94 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/api/ConfigurationSystem.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.api;
18 |
19 | /**
20 | * A configuration provider interface.
21 | *
22 | * @author Krzysztof Suszynski
23 | * @since 2.0.0
24 | */
25 | public interface ConfigurationSystem {
26 | /**
27 | * Get a configuration object
28 | *
29 | * @return a configuration object
30 | */
31 | Configuration getConfiguration();
32 |
33 | /**
34 | * Configures an Eid library programmatically. Note, that method returns a
35 | * configurator that can be used to restore configuration to the state
36 | * before you invoke this configuration method.
37 | *
38 | * @param configurator a configurator to use to configure Eid library
39 | * @return a reference to a configurator that can be used to restore
40 | * previous configuration
41 | */
42 | Configurator configure(Configurator configurator);
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/api/Configurator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.api;
18 |
19 | import java.util.ServiceLoader;
20 |
21 | /**
22 | * You can use this interface with Java's {@link ServiceLoader} class.
23 | *
24 | * To do that, create on your classpath, a file:
25 | *
26 | *
27 | * In that file, place a fully qualified class name of your class that implements
28 | * {@link Configurator} interface. It should be called first time you
29 | * reference an {@link Eid}, or and of the eid exceptions, or utility
30 | * preconditions class.
31 | *
32 | * @author Krzysztof Suszynski
33 | * @since 2.0.0
34 | * @see ServiceLoader
35 | */
36 | public interface Configurator {
37 |
38 | /**
39 | * Configures an Eid configuration.
40 | *
41 | * @param configuration a configuration to be configured
42 | */
43 | void configure(ConfigurationBuilder configuration);
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/api/Eid.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.api;
18 |
19 | import javax.annotation.Nullable;
20 | import java.io.Serializable;
21 |
22 | /**
23 | *
The Idea
24 | *
25 | * The main idea of this library is to use a set of simple runtime exceptions to
26 | * speedup development and make it more professional in the same time. Those
27 | * exceptions should always take the Exception ID (Eid for short) object on
28 | * construction. The Eid object should be generated by developer while writing
29 | * code and committed in the constructor of an exception. This eid object will
30 | * then be reported when that exception is being displayed or logged.
31 | *
32 | * This approach simplifies the management of exceptions in the application and
33 | * allows developers to focus on functionality and code quality, rather than
34 | * coming up with the correct statement for the exception.
35 | *
36 | * This error number is perfect to be displayed on the error "500" page for your
37 | * application as a bug reference. It's good idea, because it is static, so wil
38 | * l not change in subsequent invocations, but it also do not disclose the
39 | * actual reason why bug occurred.
40 | *
41 | * This approach is best to use with tools and IDE plugins like:
42 | *
52 | * We are deeply sorry. A fatal error occurred.
53 | * The reference number is: 20150721:100554
54 | *
55 | * Wait a couple of minutes, and try again. If the
56 | * same error number persists, call IT support.
57 | *
58 | *
59 | * That error page is easy to implement, because all those exceptions implement
60 | * {@link EidContainer} interface.
61 | *
62 | * Usage example:
63 | *
64 | * throw new EidIllegalStateException("20150721:100554", cause);
65 | *
66 | * Example log:
67 | *
68 | * pl.wavesoftware.eid.exceptions.EidIllegalStateException: [20150721:100554]<g0qrwx> => Zipfile in invalid format
69 | * at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
70 | * at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
71 | *
72 | * Caused by: java.util.zip.DataFormatException: Zipfile in invalid format
73 | * at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
74 | * at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
75 | * ... 62 more
76 | *
77 | *
78 | * Eid number contains also additional unique ID to distinguish each single
79 | * exception from others with same Eid.
80 | *
81 | *
Caution
82 | *
83 | * Those classes shouldn't be used in any public API or library - those should
84 | * have proper checked exceptions build in design. It's designed to be used for
85 | * in-house development of end user applications which will report bugs in
86 | * standardized error pages or post them to issue tracker.
87 | *
88 | * Remember! You should never catch a runtime exception, in place other then
89 | * appropriate error page.
90 | *
91 | *
Notice
92 | *
93 | * Check out {@code EidPreconditions} class for ease of use utility checks.
94 | *
95 | * You can tweak behavior of Eid with {@link Configurator}.
96 | *
97 | * @author Krzysztof Suszynski
98 | * @see EidContainer
99 | * @see Configurator
100 | * @since 2.0.0
101 | */
102 | public interface Eid extends Serializable {
103 | /**
104 | * Getter for constant Exception ID
105 | *
106 | * @return ID of exception
107 | */
108 | String getId();
109 |
110 | /**
111 | * Get an external reference passed to Exception ID
112 | *
113 | * @return an external reference, or null if not set
114 | */
115 | @Nullable
116 | String getRef();
117 |
118 | /**
119 | * Do this Exception ID has an external reference number?
120 | *
121 | * @return true, if has an external reference
122 | */
123 | boolean hasRef();
124 |
125 | /**
126 | * Gets unique generated string for this instance of Eid
127 | *
128 | * @return a unique string
129 | */
130 | String getUnique();
131 |
132 | /**
133 | * Creates a message object from this Eid, with given message template and
134 | * template arguments. Message template and arguments will be interpolated
135 | * using {@link java.text.MessageFormat#format(String, Object...)} method.
136 | *
137 | * @param messageTemplate a message format
138 | * @param templateArguments a message format arguments that will be
139 | * interpolated to format string
140 | * @return a message object
141 | */
142 | EidMessage message(
143 | CharSequence messageTemplate,
144 | Object... templateArguments
145 | );
146 | }
147 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/api/EidContainer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package pl.wavesoftware.eid.api;
17 |
18 | /**
19 | * Indicate that object contains a {@link Eid} object
20 | *
21 | * @author Krzysztof Suszynski
22 | * @see Eid
23 | */
24 | public interface EidContainer {
25 |
26 | /**
27 | * Retrieves a Eid object
28 | *
29 | * @return Eid object
30 | */
31 | Eid getEid();
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/api/EidFactories.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.api;
18 |
19 | /**
20 | * Represents an Eid library bound factories.
21 | *
22 | * @author Krzysztof Suszynski
23 | * @since 2.0.0
24 | */
25 | public interface EidFactories {
26 |
27 | /**
28 | * Gets an Eid message factory.
29 | *
30 | * @return a factory for Eid messages.
31 | */
32 | EidMessageFactory getMessageFactory();
33 |
34 | /**
35 | * Gets a factory for lazy objects.
36 | *
37 | * @return a lazy objects factory.
38 | */
39 | LazyFactory getLazyFactory();
40 |
41 | /**
42 | * Gets a Eid object factory.
43 | *
44 | * @return a factory for Eid objects
45 | */
46 | EidFactory getEidFactory();
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/api/EidFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.api;
18 |
19 | /**
20 | * An Eid object factory
21 | *
22 | * @author Krzysztof Suszynski
23 | * @since 2.0.0
24 | */
25 | public interface EidFactory {
26 | /**
27 | * Constructs a single value of exception ID.
28 | *
29 | * @param id the exception id, should be uniquely generated by developer
30 | * @return a created Eid object
31 | */
32 | Eid create(CharSequence id);
33 |
34 | /**
35 | * Constructs with two values an exception ID and reference of some sort.
36 | * The second reference can be used to hold reference from external system.
37 | *
38 | * @param id the exception id, should be uniquely generated by developer
39 | * @param ref a reference from external system
40 | * @return a created Eid object
41 | */
42 | Eid create(CharSequence id, CharSequence ref);
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/api/EidMessage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.api;
18 |
19 | /**
20 | * The Eid message represents a message that contains a user given message
21 | * with arguments, as well as Eid object.
22 | *
23 | * @author Krzysztof Suszynski
24 | * @since 2.0.0
25 | */
26 | public interface EidMessage extends CharSequence, EidContainer {
27 |
28 | /**
29 | * Get a formatted message
30 | *
31 | * @return a formatted message
32 | */
33 | CharSequence getFormattedMessage();
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/api/EidMessageFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.api;
18 |
19 | /**
20 | * Represents a factory for Eid messages.
21 | *
22 | * @author Krzysztof Suszynski
23 | * @since 2.0.0
24 | */
25 | public interface EidMessageFactory {
26 | /**
27 | * Create a Exception ID message, from Eid, message template and
28 | * template arguments.
29 | *
30 | * @param eid an Exception ID object
31 | * @param messageTemplate message template in form accepted by
32 | * {@link java.text.MessageFormat#format(String, Object...)}
33 | * @param templateArguments a template arguments to be used to interpolate
34 | * into message
35 | * @return a create message with Eid number
36 | */
37 | EidMessage create(
38 | Eid eid,
39 | CharSequence messageTemplate,
40 | Object[] templateArguments
41 | );
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/api/Formatter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.api;
18 |
19 | /**
20 | * Represents a formatter that will be used to display an Eid number in logs
21 | * or screen.
22 | *
23 | * @author Krzysztof Suszynski
24 | * @since 2.0.0
25 | */
26 | public interface Formatter {
27 | /**
28 | * Formats an Eid number to string
29 | *
30 | * @param eid an eid number
31 | * @return a string with formatted Eid number
32 | */
33 | String format(Eid eid);
34 |
35 | /**
36 | * Formats an Eid paired with a message.
37 | *
38 | * @param eid an eid number to format
39 | * @param message a message to be pair to eid
40 | * @return a string with formatted eid and message
41 | */
42 | String format(Eid eid, String message);
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/api/LazyFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.api;
18 |
19 | import java.io.Serializable;
20 |
21 | /**
22 | * A factory for a lazy objects.
23 | *
24 | * @author Krzysztof Suszynski
25 | * @since 2.0.0
26 | */
27 | public interface LazyFactory {
28 | /**
29 | * Creates a lazy supplier of a given supplier of serializable value
30 | *
31 | * @param supplier a supplier of serializable value
32 | * @param a serializable type
33 | * @return a lazy, serializable, supplier
34 | */
35 | SerializableSupplier lazy(Supplier supplier);
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/api/ReturnTypesAreNonnullByDefault.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.api;
18 |
19 | import javax.annotation.Nonnull;
20 | import javax.annotation.meta.TypeQualifierDefault;
21 | import java.lang.annotation.ElementType;
22 | import java.lang.annotation.Retention;
23 | import java.lang.annotation.RetentionPolicy;
24 |
25 | /**
26 | * This annotation can be applied to a package, class or method to indicate that
27 | * the method return types in that element are nonnull by default unless
28 | * there is:
29 | *
30 | *
An explicit nullness annotation
31 | *
The method overrides a method in a superclass (in which case the
32 | * annotation of the corresponding parameter in the superclass applies)
33 | *
there is a default parameter annotation applied to a more tightly
34 | * nested element.
35 | *
36 | *
37 | * @author Krzysztof Suszynski
38 | * @since 2016-03-26
39 | */
40 | @Nonnull
41 | @TypeQualifierDefault(ElementType.METHOD)
42 | @Retention(RetentionPolicy.RUNTIME)
43 | public @interface ReturnTypesAreNonnullByDefault {
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/api/SerializableSupplier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.api;
18 |
19 | import java.io.Serializable;
20 |
21 | /**
22 | * A serializable supplier.
23 | *
24 | * @author Krzysztof Suszynski
25 | * @since 2.0.0
26 | * @param a type of this supplier, must be serializable
27 | */
28 | public interface SerializableSupplier
29 | extends Supplier, Serializable {
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/api/Supplier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.api;
18 |
19 | /**
20 | * A supplier, inspired by Java 8 type of the same name.
21 | *
22 | * @author Krzysztof Suszynski
23 | * @since 2.0.0
24 | * @param a type of object that this supplier provides
25 | */
26 | public interface Supplier {
27 | /**
28 | * Gets an object
29 | *
30 | * @return an object
31 | */
32 | T get();
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/api/UniqueIdGenerator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.api;
18 |
19 | /**
20 | * It is used to generate unique ID for each EID object. It's mustn't be secure
21 | * because it just indicate EID object while logging.
22 | *
23 | * @author Krzysztof Suszynski
24 | * @since 1.0.0
25 | */
26 | public interface UniqueIdGenerator {
27 |
28 | /**
29 | * Generates a unique string ID
30 | *
31 | * @return a generated unique ID
32 | */
33 | String generateUniqId();
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/api/Validator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.api;
18 |
19 | /**
20 | * Implementing this validator and configuring it can help you assure that every
21 | * Eid in your project, conform to your rules.
22 | *
23 | * Keep in mind that validation adds a little bit of cost, to every Eid creation,
24 | * even if that particular Eid don't turn up to be used.
25 | *
26 | * To use your {@code Validator}, use {@link Configurator}.
27 | *
28 | * @author Krzysztof Suszynski
29 | * @since 2.0.0
30 | * @see Configurator
31 | */
32 | public interface Validator {
33 | /**
34 | * Checks an ID that will be used as an Exception ID.
35 | *
36 | * @param id an id to check
37 | * @return true, if given ID is valid
38 | */
39 | boolean isValid(CharSequence id);
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/api/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * @author Krzysztof Suszynski
19 | * @since 2018-10-31
20 | */
21 | @ParametersAreNonnullByDefault
22 | @ReturnTypesAreNonnullByDefault
23 | package pl.wavesoftware.eid.api;
24 |
25 | import javax.annotation.ParametersAreNonnullByDefault;
26 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/exceptions/EidIllegalStateException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package pl.wavesoftware.eid.exceptions;
17 |
18 | import pl.wavesoftware.eid.api.Eid;
19 | import pl.wavesoftware.eid.api.EidMessage;
20 |
21 | import javax.annotation.Nullable;
22 |
23 | /**
24 | * This exception is Eid version of Java's {@link IllegalStateException} that
25 | * holds an {@link Eid} object. It can be used to process it in application
26 | * central error handler.
27 | *
28 | * Caution! This class shouldn't be used in any public API or
29 | * library. It is designed to be used for in-house development of end user
30 | * applications which will report bugs in standardized error pages or post them
31 | * to issue tracker.
32 | *
33 | * @see IllegalStateException
34 | * @see EidRuntimeException
35 | * @author Krzysztof Suszynski
36 | * @since 0.1.0
37 | */
38 | public class EidIllegalStateException extends EidRuntimeException {
39 |
40 | private static final long serialVersionUID = -9876432123423443L;
41 |
42 | /**
43 | * Constructs a new runtime exception with the specified Exception ID as
44 | * it's detail message, that's {@code new Eid(eid).toString()}.
45 | *
46 | * The cause is not initialized, and may subsequently be initialized by
47 | * a call to {@link #initCause}.
48 | *
49 | * @param eid an exception ID as character sequence
50 | */
51 | public EidIllegalStateException(CharSequence eid) {
52 | super(eid);
53 | }
54 |
55 | /**
56 | * Constructs a new runtime exception with the specified Exception ID and
57 | * detail message.
58 | *
59 | * The cause is not initialized, and may subsequently be initialized by a
60 | * call to {@link #initCause}.
61 | *
62 | * @param eid an exception ID as character sequence
63 | * @param message the detail message. The detail message is saved for
64 | * later retrieval by the {@link #getMessage()} method.
65 | */
66 | public EidIllegalStateException(CharSequence eid, String message) {
67 | super(eid, message);
68 | }
69 |
70 | /**
71 | * Constructs a new runtime exception with the specified Eid message.
72 | *
73 | * The cause is not initialized, and may subsequently be initialized by a
74 | * call to {@link #initCause}.
75 | *
76 | * @param message the Eid message. The detail message is saved for
77 | * later retrieval by the {@link #getMessage()} method.
78 | */
79 | public EidIllegalStateException(EidMessage message) {
80 | super(message);
81 | }
82 |
83 | /**
84 | * Constructs a new runtime exception with the specified Exception ID,
85 | * detail message and cause.
86 | *
87 | *
88 | * Note that the detail message associated with cause is
89 | * not automatically incorporated in this runtime exception's
90 | * detail message.
91 | *
92 | * @param eid an exception ID as character sequence
93 | * @param message the detail message (which is saved for later retrieval
94 | * by the {@link #getMessage()} method).
95 | * @param cause the cause (which is saved for later retrieval by the
96 | * {@link #getCause()} method). (A null value is
97 | * permitted, and indicates that the cause is nonexistent or
98 | */
99 | public EidIllegalStateException(
100 | CharSequence eid, String message, @Nullable Throwable cause
101 | ) {
102 | super(eid, message, cause);
103 | }
104 |
105 | /**
106 | * Constructs a new runtime exception with the specified Exception ID,
107 | * detail message and cause.
108 | *
109 | *
110 | * Note that the detail message associated with cause is
111 | * not automatically incorporated in this runtime exception's
112 | * detail message.
113 | *
114 | * @param message the Eid message (which is saved for later retrieval
115 | * by the {@link #getMessage()} method).
116 | * @param cause the cause (which is saved for later retrieval by the
117 | * {@link #getCause()} method). (A null value is
118 | * permitted, and indicates that the cause is nonexistent or
119 | */
120 | public EidIllegalStateException(
121 | EidMessage message, @Nullable Throwable cause
122 | ) {
123 | super(message, cause);
124 | }
125 |
126 | /**
127 | * Constructs a new runtime exception with the specified Exception ID and
128 | * cause.
129 | *
130 | * A detail message of eid.toString() + (cause==null ? "" : cause.toString())
131 | * (which typically contains the class and detail message of
132 | * cause).
133 | *
134 | * This constructor is useful for runtime exceptions that are little more
135 | * than wrappers for other throwables.
136 | *
137 | * @param eid an exception ID as character sequence
138 | * @param cause the cause (which is saved for later retrieval by the
139 | * {@link #getCause()} method). (A null value is
140 | * permitted, and indicates that the cause is nonexistent or
141 | */
142 | public EidIllegalStateException(
143 | CharSequence eid, @Nullable Throwable cause
144 | ) {
145 | super(eid, cause);
146 | }
147 |
148 | /**
149 | * Constructs a new runtime exception with the specified Exception ID as
150 | * it's detail message, that's {@code eid.toString()}.
151 | *
152 | * The cause is not initialized, and may subsequently be initialized by
153 | * a call to {@link #initCause}.
154 | *
155 | * @param id an exception ID
156 | */
157 | public EidIllegalStateException(Eid id) {
158 | super(id);
159 | }
160 |
161 | /**
162 | * Constructs a new runtime exception with the specified Exception ID and
163 | * detail message.
164 | *
165 | * The cause is not initialized, and may subsequently be initialized by a
166 | * call to {@link #initCause}.
167 | *
168 | * @param id an exception ID
169 | * @param message the detail message. The detail message is saved for
170 | * later retrieval by the {@link #getMessage()} method.
171 | */
172 | public EidIllegalStateException(Eid id, String message) {
173 | super(id, message);
174 | }
175 |
176 | /**
177 | * Constructs a new runtime exception with the specified Exception ID,
178 | * detail message and cause.
179 | *
180 | *
181 | * Note that the detail message associated with cause is
182 | * not automatically incorporated in this runtime exception's
183 | * detail message.
184 | *
185 | * @param id an exception ID
186 | * @param message the detail message (which is saved for later retrieval
187 | * by the {@link #getMessage()} method).
188 | * @param cause the cause (which is saved for later retrieval by the
189 | * {@link #getCause()} method). (A null value is
190 | * permitted, and indicates that the cause is nonexistent or
191 | */
192 | public EidIllegalStateException(
193 | Eid id, String message, @Nullable Throwable cause
194 | ) {
195 | super(id, message, cause);
196 | }
197 |
198 | /**
199 | * Constructs a new runtime exception with the specified Exception ID and
200 | * cause.
201 | *
202 | * A detail message of eid.toString() + (cause==null ? "" : cause.toString())
203 | * (which typically contains the class and detail message of
204 | * cause).
205 | *
206 | * This constructor is useful for runtime exceptions that are little more
207 | * than wrappers for other throwables.
208 | *
209 | * @param id an exception ID
210 | * @param cause the cause (which is saved for later retrieval by the
211 | * {@link #getCause()} method). (A null value is
212 | * permitted, and indicates that the cause is nonexistent or
213 | */
214 | public EidIllegalStateException(Eid id, @Nullable Throwable cause) {
215 | super(id, cause);
216 | }
217 |
218 | }
219 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/exceptions/EidNullPointerException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package pl.wavesoftware.eid.exceptions;
17 |
18 | import pl.wavesoftware.eid.api.Eid;
19 | import pl.wavesoftware.eid.api.EidMessage;
20 |
21 | import javax.annotation.Nullable;
22 |
23 | /**
24 | * This exception is Eid version of Java's {@link NullPointerException} that
25 | * holds an {@link Eid} object. It can be used to process it in application
26 | * central error handler.
27 | *
28 | * Caution! This class shouldn't be used in any public API or
29 | * library. It is designed to be used for in-house development of end user
30 | * applications which will report bugs in standardized error pages or post them
31 | * to issue tracker.
32 | *
33 | * @see NullPointerException
34 | * @see EidRuntimeException
35 | * @author Krzysztof Suszynski
36 | * @since 0.1.0
37 | */
38 | public class EidNullPointerException extends EidRuntimeException {
39 |
40 | private static final long serialVersionUID = -9876432123423469L;
41 |
42 | /**
43 | * Constructs a new runtime exception with the specified Exception ID as
44 | * it's detail message, that's {@code new Eid(eid).toString()}.
45 | *
46 | * The cause is not initialized, and may subsequently be initialized by
47 | * a call to {@link #initCause}.
48 | *
49 | * @param eid an exception ID as character sequence
50 | */
51 | public EidNullPointerException(CharSequence eid) {
52 | super(eid);
53 | }
54 |
55 | /**
56 | * Constructs a new runtime exception with the specified Exception ID and
57 | * detail message.
58 | *
59 | * The cause is not initialized, and may subsequently be initialized by a
60 | * call to {@link #initCause}.
61 | *
62 | * @param eid an exception ID as character sequence
63 | * @param message the detail message. The detail message is saved for
64 | * later retrieval by the {@link #getMessage()} method.
65 | */
66 | public EidNullPointerException(CharSequence eid, String message) {
67 | super(eid, message);
68 | }
69 |
70 | /**
71 | * Constructs a new runtime exception with the specified Eid message.
72 | *
73 | * The cause is not initialized, and may subsequently be initialized by a
74 | * call to {@link #initCause}.
75 | *
76 | * @param message the Eid message. The detail message is saved for
77 | * later retrieval by the {@link #getMessage()} method.
78 | */
79 | public EidNullPointerException(EidMessage message) {
80 | super(message);
81 | }
82 |
83 | /**
84 | * Constructs a new runtime exception with the specified Exception ID,
85 | * detail message and cause.
86 | *
87 | *
88 | * Note that the detail message associated with cause is
89 | * not automatically incorporated in this runtime exception's
90 | * detail message.
91 | *
92 | * @param eid an exception ID as character sequence
93 | * @param message the detail message (which is saved for later retrieval
94 | * by the {@link #getMessage()} method).
95 | * @param cause the cause (which is saved for later retrieval by the
96 | * {@link #getCause()} method). (A null value is
97 | * permitted, and indicates that the cause is nonexistent or
98 | */
99 | public EidNullPointerException(
100 | CharSequence eid, String message, @Nullable Throwable cause
101 | ) {
102 | super(eid, message, cause);
103 | }
104 |
105 | /**
106 | * Constructs a new runtime exception with the specified Exception ID,
107 | * detail message and cause.
108 | *
109 | *
110 | * Note that the detail message associated with cause is
111 | * not automatically incorporated in this runtime exception's
112 | * detail message.
113 | *
114 | * @param message the Eid message (which is saved for later retrieval
115 | * by the {@link #getMessage()} method).
116 | * @param cause the cause (which is saved for later retrieval by the
117 | * {@link #getCause()} method). (A null value is
118 | * permitted, and indicates that the cause is nonexistent or
119 | */
120 | public EidNullPointerException(
121 | EidMessage message, @Nullable Throwable cause
122 | ) {
123 | super(message, cause);
124 | }
125 |
126 | /**
127 | * Constructs a new runtime exception with the specified Exception ID and
128 | * cause.
129 | *
130 | * A detail message of eid.toString() + (cause==null ? "" : cause.toString())
131 | * (which typically contains the class and detail message of
132 | * cause).
133 | *
134 | * This constructor is useful for runtime exceptions that are little more
135 | * than wrappers for other throwables.
136 | *
137 | * @param eid an exception ID as character sequence
138 | * @param cause the cause (which is saved for later retrieval by the
139 | * {@link #getCause()} method). (A null value is
140 | * permitted, and indicates that the cause is nonexistent or
141 | */
142 | public EidNullPointerException(
143 | CharSequence eid, @Nullable Throwable cause
144 | ) {
145 | super(eid, cause);
146 | }
147 |
148 | /**
149 | * Constructs a new runtime exception with the specified Exception ID as
150 | * it's detail message, that's {@code eid.toString()}.
151 | *
152 | * The cause is not initialized, and may subsequently be initialized by
153 | * a call to {@link #initCause}.
154 | *
155 | * @param id an exception ID
156 | */
157 | public EidNullPointerException(Eid id) {
158 | super(id);
159 | }
160 |
161 | /**
162 | * Constructs a new runtime exception with the specified Exception ID and
163 | * detail message.
164 | *
165 | * The cause is not initialized, and may subsequently be initialized by a
166 | * call to {@link #initCause}.
167 | *
168 | * @param id an exception ID
169 | * @param message the detail message. The detail message is saved for
170 | * later retrieval by the {@link #getMessage()} method.
171 | */
172 | public EidNullPointerException(Eid id, String message) {
173 | super(id, message);
174 | }
175 |
176 | /**
177 | * Constructs a new runtime exception with the specified Exception ID,
178 | * detail message and cause.
179 | *
180 | *
181 | * Note that the detail message associated with cause is
182 | * not automatically incorporated in this runtime exception's
183 | * detail message.
184 | *
185 | * @param id an exception ID
186 | * @param message the detail message (which is saved for later retrieval
187 | * by the {@link #getMessage()} method).
188 | * @param cause the cause (which is saved for later retrieval by the
189 | * {@link #getCause()} method). (A null value is
190 | * permitted, and indicates that the cause is nonexistent or
191 | */
192 | public EidNullPointerException(
193 | Eid id, String message, @Nullable Throwable cause
194 | ) {
195 | super(id, message, cause);
196 | }
197 |
198 | /**
199 | * Constructs a new runtime exception with the specified Exception ID and
200 | * cause.
201 | *
202 | * A detail message of eid.toString() + (cause==null ? "" : cause.toString())
203 | * (which typically contains the class and detail message of
204 | * cause).
205 | *
206 | * This constructor is useful for runtime exceptions that are little more
207 | * than wrappers for other throwables.
208 | *
209 | * @param id an exception ID
210 | * @param cause the cause (which is saved for later retrieval by the
211 | * {@link #getCause()} method). (A null value is
212 | * permitted, and indicates that the cause is nonexistent or
213 | */
214 | public EidNullPointerException(Eid id, @Nullable Throwable cause) {
215 | super(id, cause);
216 | }
217 |
218 | }
219 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/exceptions/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * @author Krzysztof Suszynski
19 | * @since 29.03.16
20 | */
21 | @javax.annotation.ParametersAreNonnullByDefault
22 | @ReturnTypesAreNonnullByDefault
23 | package pl.wavesoftware.eid.exceptions;
24 |
25 | import pl.wavesoftware.eid.api.ReturnTypesAreNonnullByDefault;
26 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/impl/BindingImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.impl;
18 |
19 | import pl.wavesoftware.eid.api.Binding;
20 | import pl.wavesoftware.eid.api.ConfigurationSystem;
21 | import pl.wavesoftware.eid.api.EidFactories;
22 |
23 | /**
24 | * An internal implementation. Do not use manually.
25 | *
26 | * A default binding implementation.
27 | *
28 | * @author Krzysztof Suszynski
29 | * @since 2.0.0
30 | */
31 | public final class BindingImpl implements Binding {
32 |
33 | private final ConfigurationSystem system = new ConfigurationSystemImpl();
34 | private final EidFactories factories = new EidFactoriesImpl(this);
35 |
36 | @Override
37 | public ConfigurationSystem getConfigurationSystem() {
38 | return system;
39 | }
40 |
41 | @Override
42 | public EidFactories getFactories() {
43 | return factories;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/impl/ConfigurationImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.impl;
18 |
19 | import pl.wavesoftware.eid.api.Configuration;
20 | import pl.wavesoftware.eid.api.ConfigurationBuilder;
21 | import pl.wavesoftware.eid.api.Formatter;
22 | import pl.wavesoftware.eid.api.UniqueIdGenerator;
23 | import pl.wavesoftware.eid.api.Validator;
24 |
25 | import javax.annotation.Nullable;
26 | import java.util.Locale;
27 | import java.util.TimeZone;
28 |
29 | import static pl.wavesoftware.eid.impl.InternalChecks.checkNotNull;
30 |
31 | /**
32 | * @author Krzysztof Suszynski
33 | * @since 2.0.0
34 | */
35 | final class ConfigurationImpl implements MutableConfiguration {
36 |
37 | private Formatter formatter;
38 | private UniqueIdGenerator generator;
39 | @Nullable
40 | private Validator validator;
41 | @Nullable
42 | private Locale locale;
43 | @Nullable
44 | private TimeZone zone;
45 |
46 | ConfigurationImpl() {
47 | // nothing here
48 | }
49 |
50 | ConfigurationImpl(MutableConfiguration settings) {
51 | checkNotNull(settings, "20181218:002046");
52 | this.formatter = settings.getFormatter();
53 | this.generator = settings.getIdGenerator();
54 | this.validator = settings.getValidator();
55 | this.locale = settings.getLocale();
56 | this.zone = settings.getTimeZone();
57 | }
58 |
59 | @Override
60 | public ConfigurationBuilder uniqueIdGenerator(UniqueIdGenerator generator) {
61 | this.generator = checkNotNull(generator, "20181218:002002");
62 | return this;
63 | }
64 |
65 | @Override
66 | public ConfigurationBuilder formatter(Formatter formatter) {
67 | this.formatter = checkNotNull(formatter, "20181218:002018");
68 | return this;
69 | }
70 |
71 | @Override
72 | public ConfigurationBuilder locale(@Nullable Locale locale) {
73 | this.locale = locale;
74 | return this;
75 | }
76 |
77 | @Override
78 | public ConfigurationBuilder timezone(@Nullable TimeZone zone) {
79 | this.zone = zone;
80 | return this;
81 | }
82 |
83 | @Override
84 | public ConfigurationBuilder validator(@Nullable Validator validator) {
85 | this.validator = validator;
86 | return this;
87 | }
88 |
89 | @Override
90 | public Configuration getFutureConfiguration() {
91 | return this;
92 | }
93 |
94 | @Override
95 | public Formatter getFormatter() {
96 | return formatter;
97 | }
98 |
99 | @Override
100 | public UniqueIdGenerator getIdGenerator() {
101 | return generator;
102 | }
103 |
104 | @Nullable
105 | @Override
106 | public Validator getValidator() {
107 | return validator;
108 | }
109 |
110 | @Nullable
111 | @Override
112 | public Locale getLocale() {
113 | return locale;
114 | }
115 |
116 | @Nullable
117 | @Override
118 | public TimeZone getTimeZone() {
119 | return zone;
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/impl/ConfigurationSystemImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.impl;
18 |
19 | import pl.wavesoftware.eid.api.Configuration;
20 | import pl.wavesoftware.eid.api.ConfigurationBuilder;
21 | import pl.wavesoftware.eid.api.ConfigurationSystem;
22 | import pl.wavesoftware.eid.api.Configurator;
23 | import pl.wavesoftware.eid.api.Supplier;
24 |
25 | import java.util.ServiceLoader;
26 |
27 | /**
28 | * @author Krzysztof Suszynski
29 | * @since 2018-10-29
30 | */
31 | final class ConfigurationSystemImpl implements ConfigurationSystem {
32 |
33 | private Lazy configuration =
34 | Lazy.of(new MutableConfigurationSupplier());
35 |
36 | ConfigurationSystemImpl() {
37 | // nothing here
38 | }
39 |
40 | @Override
41 | public Configuration getConfiguration() {
42 | return configuration.get();
43 | }
44 |
45 | @Override
46 | public Configurator configure(Configurator configurator) {
47 | MutableConfiguration configured = configuration.get();
48 | MutableConfiguration mutable = new ConfigurationImpl(configured);
49 | configurator.configure(mutable);
50 | configuration = Lazy.of(mutable);
51 | return new RestoreConfigurator(configured);
52 | }
53 |
54 | private static final class MutableConfigurationSupplier
55 | implements Supplier {
56 |
57 | @Override
58 | public MutableConfiguration get() {
59 | return loadConfiguration();
60 | }
61 |
62 | private static MutableConfiguration loadConfiguration() {
63 | MutableConfiguration mutableConfiguration = new ConfigurationImpl();
64 | new DefaultConfigurator().configure(mutableConfiguration);
65 | ServiceLoader configurators =
66 | ServiceLoader.load(Configurator.class);
67 |
68 | for (Configurator configurator : configurators) {
69 | configurator.configure(mutableConfiguration);
70 | }
71 | return mutableConfiguration;
72 | }
73 | }
74 |
75 | private static final class RestoreConfigurator
76 | implements Configurator {
77 | private final MutableConfiguration configuration;
78 |
79 | RestoreConfigurator(MutableConfiguration configuration) {
80 | this.configuration = configuration;
81 | }
82 |
83 | /*
84 | Suppress is for forcing nullable values to non null methods
85 | for copy constructor.
86 | */
87 | @SuppressWarnings("ConstantConditions")
88 | @Override
89 | public void configure(ConfigurationBuilder builder) {
90 | builder.formatter(configuration.getFormatter())
91 | .uniqueIdGenerator(configuration.getIdGenerator())
92 | .validator(configuration.getValidator())
93 | .locale(configuration.getLocale());
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/impl/DefaultConfigurator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.impl;
18 |
19 | import pl.wavesoftware.eid.api.Configurator;
20 | import pl.wavesoftware.eid.api.ConfigurationBuilder;
21 |
22 | /**
23 | * @author Krzysztof Suszynski
24 | * @since 2.0.0
25 | */
26 | final class DefaultConfigurator implements Configurator {
27 | @Override
28 | public void configure(ConfigurationBuilder configuration) {
29 | configuration
30 | .formatter(new DefaultFormatter(configuration.getFutureConfiguration()))
31 | .uniqueIdGenerator(new DefaultUniqueIdGenerator());
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/impl/DefaultEidMessage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.impl;
18 |
19 | import pl.wavesoftware.eid.api.Configuration;
20 | import pl.wavesoftware.eid.api.Eid;
21 | import pl.wavesoftware.eid.api.EidMessage;
22 |
23 | import java.io.Serializable;
24 |
25 | /**
26 | * @author Krzysztof Suszynski
27 | * @since 2.0.0
28 | */
29 | final class DefaultEidMessage implements EidMessage, Serializable {
30 | private static final long serialVersionUID = 20181029192322L;
31 |
32 | private final EidTextRepresentation represntation;
33 |
34 | DefaultEidMessage(
35 | Eid eid,
36 | Configuration configuration,
37 | CharSequence messageFormat,
38 | Object[] arguments
39 | ) {
40 | this.represntation = new EidTextRepresentation(
41 | eid,
42 | new TextMessage(configuration, messageFormat, arguments),
43 | configuration
44 | );
45 | }
46 |
47 | @Override
48 | public int length() {
49 | return represntation.get().length();
50 | }
51 |
52 | @Override
53 | public char charAt(int index) {
54 | return represntation.get().charAt(index);
55 | }
56 |
57 | @Override
58 | public CharSequence subSequence(int start, int end) {
59 | return represntation.get().subSequence(start, end);
60 | }
61 |
62 | @Override
63 | public Eid getEid() {
64 | return represntation.getEid();
65 | }
66 |
67 | @Override
68 | public String toString() {
69 | return represntation.get();
70 | }
71 |
72 | @Override
73 | public CharSequence getFormattedMessage() {
74 | return represntation.getTextMessage().get();
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/impl/DefaultFormatter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.impl;
18 |
19 | import pl.wavesoftware.eid.api.Configuration;
20 | import pl.wavesoftware.eid.api.Eid;
21 | import pl.wavesoftware.eid.api.Formatter;
22 |
23 | import javax.annotation.Nullable;
24 | import java.util.Locale;
25 |
26 | /**
27 | * @author Krzysztof Suszynski
28 | * @since 2.0.0
29 | */
30 | final class DefaultFormatter implements Formatter {
31 |
32 | private static final String FORMAT = "[%s]<%s>";
33 | private static final String REF_FORMAT = "[%s|%s]<%s>";
34 | private static final String MSG_FORMAT = "%s => %s";
35 |
36 | private final Configuration configuration;
37 |
38 | DefaultFormatter(Configuration configuration) {
39 | this.configuration = configuration;
40 | }
41 |
42 | @Override
43 | public String format(Eid eid) {
44 | String fmt;
45 | Object[] params;
46 | if (eid.getRef() == null) {
47 | fmt = FORMAT;
48 | params = new Object[]{
49 | eid.getId(),
50 | eid.getUnique()
51 | };
52 | } else {
53 | fmt = REF_FORMAT;
54 | params = new Object[]{
55 | eid.getId(),
56 | eid.getRef(),
57 | eid.getUnique()
58 | };
59 | }
60 | java.util.Formatter formatter = getStringFormatter()
61 | .format(fmt, params);
62 | return formatter.toString();
63 | }
64 |
65 | @Override
66 | public String format(Eid eid, String message) {
67 | return getStringFormatter()
68 | .format(
69 | MSG_FORMAT,
70 | format(eid),
71 | message
72 | ).toString();
73 | }
74 |
75 | private java.util.Formatter getStringFormatter() {
76 | @Nullable
77 | Locale locale = configuration.getLocale();
78 | if (locale != null) {
79 | return new java.util.Formatter(locale);
80 | } else {
81 | return new java.util.Formatter();
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/impl/DefaultUniqueIdGenerator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.impl;
18 |
19 | import pl.wavesoftware.eid.api.UniqueIdGenerator;
20 |
21 | import java.util.Random;
22 |
23 | /**
24 | * @author Krzysztof Suszynski
25 | */
26 | final class DefaultUniqueIdGenerator implements UniqueIdGenerator {
27 |
28 | private static final int BASE36 = 36;
29 | private static final int MIN = 60466176;
30 |
31 | private final Random random;
32 |
33 | DefaultUniqueIdGenerator() {
34 | this.random = getUnsecuredFastRandom();
35 | }
36 |
37 | @Override
38 | public String generateUniqId() {
39 | int calc = random.nextInt(Integer.MAX_VALUE - MIN) + MIN;
40 | return Integer.toString(calc, BASE36);
41 | }
42 |
43 | /*
44 | Using random for speed, security of generating random unique id is
45 | not important.
46 | */
47 | @SuppressWarnings("squid:S2245")
48 | private static Random getUnsecuredFastRandom() {
49 | return new Random(System.currentTimeMillis());
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/impl/EidFactoriesImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.impl;
18 |
19 | import pl.wavesoftware.eid.api.Binding;
20 | import pl.wavesoftware.eid.api.EidFactories;
21 | import pl.wavesoftware.eid.api.EidFactory;
22 | import pl.wavesoftware.eid.api.EidMessageFactory;
23 | import pl.wavesoftware.eid.api.LazyFactory;
24 |
25 | /**
26 | * @author Krzysztof Suszynski
27 | * @since 2018-12-17
28 | */
29 | final class EidFactoriesImpl implements EidFactories {
30 | private final EidMessageFactory eidMessageFactory;
31 | private final LazyFactory lazyFactory;
32 | private final EidFactory eidFactory;
33 |
34 | EidFactoriesImpl(Binding binding) {
35 | eidMessageFactory = new EidMessageFactoryImpl(binding);
36 | lazyFactory = new LazyFactoryImpl();
37 | eidFactory = new EidFactoryImpl();
38 | }
39 |
40 | @Override
41 | public EidMessageFactory getMessageFactory() {
42 | return eidMessageFactory;
43 | }
44 |
45 | @Override
46 | public LazyFactory getLazyFactory() {
47 | return lazyFactory;
48 | }
49 |
50 | @Override
51 | public EidFactory getEidFactory() {
52 | return eidFactory;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/impl/EidFactoryImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.impl;
18 |
19 | import pl.wavesoftware.eid.DefaultEid;
20 | import pl.wavesoftware.eid.api.EidFactory;
21 | import pl.wavesoftware.eid.api.Eid;
22 |
23 | /**
24 | * @author Krzysztof Suszynski
25 | * @since 2018-12-17
26 | */
27 | final class EidFactoryImpl implements EidFactory {
28 | @Override
29 | public Eid create(CharSequence id) {
30 | return new DefaultEid(id);
31 | }
32 |
33 | @Override
34 | public Eid create(CharSequence id, CharSequence ref) {
35 | return new DefaultEid(id, ref);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/impl/EidMessageFactoryImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.impl;
18 |
19 | import pl.wavesoftware.eid.api.Binding;
20 | import pl.wavesoftware.eid.api.Eid;
21 | import pl.wavesoftware.eid.api.EidMessage;
22 | import pl.wavesoftware.eid.api.EidMessageFactory;
23 |
24 | /**
25 | * @author Krzysztof Suszynski
26 | * @since 2018-12-17
27 | */
28 | final class EidMessageFactoryImpl implements EidMessageFactory {
29 | private final Binding binding;
30 |
31 | EidMessageFactoryImpl(Binding binding) {
32 | this.binding = binding;
33 | }
34 |
35 | @Override
36 | public EidMessage create(
37 | Eid eid,
38 | CharSequence messageTemplate,
39 | Object[] templateArguments
40 | ) {
41 | return new DefaultEidMessage(
42 | eid,
43 | binding.getConfigurationSystem().getConfiguration(),
44 | messageTemplate,
45 | templateArguments
46 | );
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/impl/EidTextRepresentation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.impl;
18 |
19 | import pl.wavesoftware.eid.api.Configuration;
20 | import pl.wavesoftware.eid.api.EidContainer;
21 | import pl.wavesoftware.eid.api.Eid;
22 | import pl.wavesoftware.eid.api.Supplier;
23 |
24 | import java.io.Serializable;
25 |
26 | /**
27 | * @author Krzysztof Suszynski
28 | * @since 2.0.0
29 | */
30 | final class EidTextRepresentation implements EidContainer, Serializable {
31 | private static final long serialVersionUID = 20181029231519L;
32 |
33 | private final Eid eid;
34 | private final TextMessage textMessage;
35 | private final SerializableLazy actual;
36 |
37 | EidTextRepresentation(
38 | final Eid eid,
39 | final TextMessage textMessage,
40 | final Configuration configuration
41 | ) {
42 | this.eid = eid;
43 | this.textMessage = textMessage;
44 | this.actual = SerializableLazy.serializableOf(new Supplier() {
45 | @Override
46 | public String get() {
47 | return configuration.getFormatter()
48 | .format(eid, textMessage.get());
49 | }
50 | });
51 | }
52 |
53 | @Override
54 | public Eid getEid() {
55 | return eid;
56 | }
57 |
58 | TextMessage getTextMessage() {
59 | return textMessage;
60 | }
61 |
62 | String get() {
63 | return actual.get();
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/impl/InternalChecks.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.impl;
18 |
19 | import javax.annotation.Nullable;
20 |
21 | /**
22 | * @author Krzysztof Suszynski
23 | * @since 2.0.0
24 | */
25 | final class InternalChecks {
26 | private InternalChecks() {
27 | // nothing here
28 | }
29 |
30 | @SuppressWarnings("squid:S1695")
31 | static T checkNotNull(@Nullable T value, String message) {
32 | if (value == null) {
33 | throw new IllegalArgumentException(message);
34 | }
35 | return value;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/impl/Lazy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.impl;
18 |
19 | import pl.wavesoftware.eid.api.Supplier;
20 |
21 | import static pl.wavesoftware.eid.impl.InternalChecks.checkNotNull;
22 |
23 |
24 | /**
25 | * @author Krzysztof Suszynski
26 | * @since 2.0.0
27 | */
28 | class Lazy implements Supplier {
29 | private volatile Supplier supplier;
30 | private T value;
31 |
32 | Lazy(Supplier supplier) {
33 | this.supplier = checkNotNull(supplier, "20181124:004511");
34 | }
35 |
36 | protected Lazy() {
37 | // nothing
38 | }
39 |
40 | private Lazy(T value) {
41 | this.value = value;
42 | }
43 |
44 | static Lazy of(Supplier supplier) {
45 | return new Lazy(supplier);
46 | }
47 |
48 | static Lazy of(R value) {
49 | return new Lazy(value);
50 | }
51 |
52 | @Override
53 | public T get() {
54 | if (supplier != null) {
55 | synchronized (this) {
56 | if (supplier != null) {
57 | T calculated = supplier.get();
58 | supplier = null;
59 | value = calculated;
60 | }
61 | }
62 | }
63 | return value;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/impl/LazyFactoryImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.impl;
18 |
19 | import pl.wavesoftware.eid.api.LazyFactory;
20 | import pl.wavesoftware.eid.api.SerializableSupplier;
21 | import pl.wavesoftware.eid.api.Supplier;
22 |
23 | import java.io.Serializable;
24 |
25 | /**
26 | * @author Krzysztof Suszynski
27 | * @since 2018-12-17
28 | */
29 | final class LazyFactoryImpl implements LazyFactory {
30 | @Override
31 | public SerializableSupplier lazy(Supplier supplier) {
32 | return SerializableLazy.serializableOf(supplier);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/impl/MessageSupplier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.impl;
18 |
19 | import pl.wavesoftware.eid.api.Configuration;
20 | import pl.wavesoftware.eid.api.Supplier;
21 |
22 | import javax.annotation.Nullable;
23 | import java.text.MessageFormat;
24 | import java.text.SimpleDateFormat;
25 | import java.util.Locale;
26 | import java.util.TimeZone;
27 |
28 | /**
29 | * @author Krzysztof Suszynski
30 | * @since 2.0.0
31 | */
32 | final class MessageSupplier
33 | implements Supplier {
34 |
35 | private final Configuration configuration;
36 | private final CharSequence messageFormat;
37 | private final Object[] arguments;
38 |
39 | MessageSupplier(
40 | Configuration configuration,
41 | CharSequence messageFormat,
42 | Object[] arguments
43 | ) {
44 | this.configuration = configuration;
45 | this.messageFormat = messageFormat;
46 | this.arguments = arguments.clone();
47 | }
48 |
49 | @Override
50 | public String get() {
51 | return getFormatter().format(arguments);
52 | }
53 |
54 | private MessageFormat getFormatter() {
55 | @Nullable
56 | Locale locale = configuration.getLocale();
57 | MessageFormat format;
58 | if (locale == null) {
59 | format = new MessageFormat(messageFormat.toString());
60 | } else {
61 | format = new MessageFormat(messageFormat.toString(), locale);
62 | }
63 | return ensureTimeZone(format);
64 | }
65 |
66 | private MessageFormat ensureTimeZone(MessageFormat messageFormat) {
67 | @Nullable
68 | TimeZone zone = configuration.getTimeZone();
69 | if (zone != null) {
70 | Object[] formats = messageFormat.getFormats();
71 | for (Object format : formats) {
72 | if (format instanceof SimpleDateFormat) {
73 | ((SimpleDateFormat) format).setTimeZone(zone);
74 | }
75 | }
76 | }
77 | return messageFormat;
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/impl/MutableConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.impl;
18 |
19 | import pl.wavesoftware.eid.api.ConfigurationBuilder;
20 | import pl.wavesoftware.eid.api.Configuration;
21 |
22 | /**
23 | * @author Krzysztof Suszynski
24 | * @since 2.0.0
25 | */
26 | interface MutableConfiguration
27 | extends Configuration, ConfigurationBuilder {
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/impl/SerializableLazy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.impl;
18 |
19 | import pl.wavesoftware.eid.api.SerializableSupplier;
20 | import pl.wavesoftware.eid.api.Supplier;
21 |
22 | import java.io.IOException;
23 | import java.io.ObjectOutputStream;
24 | import java.io.Serializable;
25 |
26 | /**
27 | * @author Krzysztof Suszynski
28 | * @since 2018-11-24
29 | */
30 | final class SerializableLazy
31 | extends Lazy
32 | implements SerializableSupplier {
33 |
34 | private static final long serialVersionUID = 20181124011908L;
35 | private volatile T serializable;
36 |
37 | private SerializableLazy(Supplier supplier) {
38 | super(supplier);
39 | }
40 |
41 | static SerializableLazy serializableOf(Supplier supplier) {
42 | return new SerializableLazy(supplier);
43 | }
44 |
45 | @Override
46 | public T get() {
47 | if (serializable == null) {
48 | synchronized (this) {
49 | if (serializable == null) {
50 | serializable = super.get();
51 | }
52 | }
53 | }
54 | return serializable;
55 | }
56 |
57 | /**
58 | * Ensures that the value is evaluated before serialization.
59 | *
60 | * @param stream An object serialization stream.
61 | * @throws java.io.IOException If an error occurs writing to the stream.
62 | */
63 | private void writeObject(ObjectOutputStream stream) throws IOException {
64 | // evaluates the values if it isn't evaluated yet!
65 | get();
66 | stream.defaultWriteObject();
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/impl/TextMessage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.impl;
18 |
19 | import pl.wavesoftware.eid.api.Configuration;
20 |
21 | import java.io.Serializable;
22 |
23 | /**
24 | * @author Krzysztof Suszynski
25 | * @since 2.0.0
26 | */
27 | final class TextMessage implements Serializable {
28 | private static final long serialVersionUID = 20181029231527L;
29 |
30 | private final SerializableLazy message;
31 |
32 | TextMessage(
33 | Configuration configuration,
34 | CharSequence messageFormat,
35 | Object[] arguments
36 | ) {
37 | message = SerializableLazy.serializableOf(new MessageSupplier(
38 | configuration, messageFormat, arguments
39 | ));
40 | }
41 |
42 | String get() {
43 | return message.get();
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/impl/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * @author Krzysztof Suszynski
19 | * @since 2.0.0
20 | */
21 | @ReturnTypesAreNonnullByDefault
22 | @ParametersAreNonnullByDefault
23 | package pl.wavesoftware.eid.impl;
24 |
25 | import pl.wavesoftware.eid.api.ReturnTypesAreNonnullByDefault;
26 |
27 | import javax.annotation.ParametersAreNonnullByDefault;
28 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * @author Krzysztof Suszynski
19 | * @since 2018-10-25
20 | */
21 | @ReturnTypesAreNonnullByDefault
22 | @ParametersAreNonnullByDefault
23 | package pl.wavesoftware.eid;
24 |
25 | import pl.wavesoftware.eid.api.ReturnTypesAreNonnullByDefault;
26 |
27 | import javax.annotation.ParametersAreNonnullByDefault;
28 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/system/BindingChooser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.system;
18 |
19 | import pl.wavesoftware.eid.api.Binding;
20 | import pl.wavesoftware.eid.impl.BindingImpl;
21 |
22 | import java.io.Serializable;
23 |
24 | /**
25 | * @author Krzysztof Suszynski
26 | * @since 2.0.0
27 | */
28 | final class BindingChooser implements Serializable {
29 | private static final long serialVersionUID = 20181218003610L;
30 |
31 | Binding chooseImplementation(Iterable bindings) {
32 | Binding best = null;
33 | for (Binding bond : bindings) {
34 | if (best == null || !isCoreImplementation(bond)) {
35 | best = bond;
36 | }
37 | }
38 | assert best != null : "20181106:000523";
39 | return best;
40 | }
41 |
42 | private static boolean isCoreImplementation(Binding bond) {
43 | return bond.getClass() == BindingImpl.class;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/system/EidModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.system;
18 |
19 | import pl.wavesoftware.eid.api.Binding;
20 |
21 | import java.util.ServiceLoader;
22 |
23 | /**
24 | * Represents a EID library module, and it's configuration binding.
25 | *
26 | * Utilizing {@link #getBinding()} method it is possible to reconfigure this
27 | * module to perform differently then the default behavior.
28 | *
29 | * @author Krzysztof Suszynski
30 | * @since 2.0.0
31 | */
32 | public enum EidModule {
33 | MODULE;
34 |
35 | private final Binding binding;
36 |
37 | EidModule() {
38 | ServiceLoader loader = ServiceLoader.load(Binding.class);
39 | BindingChooser chooser = new BindingChooser();
40 | binding = chooser.chooseImplementation(loader);
41 | }
42 |
43 | /**
44 | * Provides a binding to Eid library. It can be used to reconfigure
45 | * configuration programmatically.
46 | *
47 | * @return a binding interface
48 | */
49 | public Binding getBinding() {
50 | return binding;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/system/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * @author Krzysztof Suszynski
19 | * @since 2.0.0
20 | */
21 | @ParametersAreNonnullByDefault
22 | @ReturnTypesAreNonnullByDefault
23 | package pl.wavesoftware.eid.system;
24 |
25 | import pl.wavesoftware.eid.api.ReturnTypesAreNonnullByDefault;
26 |
27 | import javax.annotation.ParametersAreNonnullByDefault;
28 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/utils/EidExecutions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.utils;
18 |
19 | import pl.wavesoftware.eid.api.Eid;
20 | import pl.wavesoftware.eid.exceptions.EidRuntimeException;
21 |
22 | import static pl.wavesoftware.eid.utils.EidUtil.ensureEid;
23 |
24 | /**
25 | *
Functional try to execute blocks
26 | * Using functional blocks to handle operations, that are intended to operate
27 | * properly, simplify the code and makes it more readable. It's also good way to
28 | * deal with untested, uncovered {@code catch} blocks. It's easy and gives
29 | * developers nice way of dealing with countless operations that suppose to work
30 | * as intended.
31 | *
42 | *
43 | * @author Krzysztof Suszynski
44 | * @since 2.0.0
45 | */
46 | public final class EidExecutions {
47 |
48 | private EidExecutions() {
49 | // nothing here
50 | }
51 |
52 | /**
53 | * Tries to execute code in given unsafe supplier code block, and if
54 | * exception is thrown, it will gets rethrown as a {@link EidRuntimeException}
55 | * with eid given as a argument. This is because this exception is
56 | * treated as a software bug!
57 | *
68 | *
69 | * @param return type
70 | * @param supplier unsafe supplier code to be executed within a try-catch
71 | * block
72 | * @param eid unique developer identifier from date for ex.:
73 | * "20150716:123200"
74 | * @return A block of code return type, if exception is not thrown
75 | * @throws EidRuntimeException if code block thrown any exception, which
76 | * in that case is wrapped in EidRuntimeException
77 | */
78 | public static R tryToExecute(
79 | final UnsafeSupplier supplier,
80 | final Eid eid
81 | ) {
82 | try {
83 | return supplier.get();
84 | } catch (Exception throwable) {
85 | throw new EidRuntimeException(ensureEid(eid), throwable);
86 | }
87 | }
88 |
89 | /**
90 | * Tries to execute code in given unsafe procedure code block, and if
91 | * exception is thrown, it will gets rethrown as a {@link EidRuntimeException}
92 | * with eid given as a argument. This is because this exception is treated
93 | * as a software bug!
94 | *
104 | *
105 | * @param procedure unsafe procedure code to be executed within a try-catch
106 | * block
107 | * @param eid unique developer identifier from date for ex.:
108 | * "20150716:123200"
109 | * @throws EidRuntimeException if code block thrown any exception, which in
110 | * that case is wrapped in EidRuntimeException
111 | */
112 | public static void tryToExecute(
113 | final UnsafeProcedure procedure,
114 | final Eid eid
115 | ) {
116 | try {
117 | procedure.execute();
118 | } catch (Exception throwable) {
119 | throw new EidRuntimeException(ensureEid(eid), throwable);
120 | }
121 | }
122 |
123 | /**
124 | * For more info in JavaDoc see {@link
125 | * EidExecutions#tryToExecute(UnsafeSupplier, Eid)}
126 | *
127 | * Please, note that for performance reasons, Eid is not evaluated until
128 | * it's needed. If you are using {@code Validator},
129 | * please use {@link #tryToExecute(UnsafeSupplier, Eid)} instead.
130 | *
131 | * @param return type
132 | * @param supplier unsafe supplier code to be executed within a try-catch
133 | * block
134 | * @param eid unique developer identifier from date for ex.:
135 | * "20150716:123200"
136 | * @return A block of code return type, if exception is not thrown
137 | * @throws EidRuntimeException if code block thrown any exception, which in
138 | * that case is wrapped in EidRuntimeException
139 | * @see EidExecutions#tryToExecute(UnsafeSupplier, Eid)
140 | */
141 | public static R tryToExecute(
142 | final UnsafeSupplier supplier,
143 | final String eid
144 | ) {
145 | try {
146 | return supplier.get();
147 | } catch (Exception throwable) {
148 | throw new EidRuntimeException(ensureEid(eid), throwable);
149 | }
150 | }
151 |
152 | /**
153 | * For more info in JavaDoc see {@link
154 | * EidExecutions#tryToExecute(UnsafeProcedure, Eid)}
155 | *
156 | * Please, note that for performance reasons, Eid is not evaluated until
157 | * it's needed. If you are using {@code Validator},
158 | * please use {@link #tryToExecute(UnsafeProcedure, Eid)} instead.
159 | *
160 | * @param procedure unsafe procedure code to be executed within a try-catch
161 | * block
162 | * @param eid unique developer identifier from date for ex.:
163 | * "20150716:123200"
164 | * @throws EidRuntimeException if code block thrown any exception, which in
165 | * that case is wrapped in EidRuntimeException
166 | * @see EidExecutions#tryToExecute(UnsafeProcedure, Eid)
167 | */
168 | public static void tryToExecute(
169 | final UnsafeProcedure procedure,
170 | final String eid
171 | ) {
172 | try {
173 | procedure.execute();
174 | } catch (Exception throwable) {
175 | throw new EidRuntimeException(ensureEid(eid), throwable);
176 | }
177 | }
178 | }
179 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/utils/EidUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.utils;
18 |
19 | import pl.wavesoftware.eid.api.Eid;
20 | import pl.wavesoftware.eid.system.EidModule;
21 |
22 | import javax.annotation.Nullable;
23 |
24 | /**
25 | * @author Krzysztof Suszynski
26 | * @since 2018-10-29
27 | */
28 | final class EidUtil {
29 | private EidUtil() {
30 | // nothing here
31 | }
32 |
33 | static Eid ensureEid(@Nullable Eid eid) {
34 | if (eid == null) {
35 | return EidModule.MODULE
36 | .getBinding()
37 | .getFactories()
38 | .getEidFactory()
39 | .create("20160329:132823", "EID-NULL");
40 | }
41 | return eid;
42 | }
43 |
44 | static Eid ensureEid(@Nullable String eid) {
45 | if (eid == null) {
46 | return EidModule.MODULE
47 | .getBinding()
48 | .getFactories()
49 | .getEidFactory()
50 | .create("20160329:133052", "EID-NULL");
51 | }
52 | return EidModule.MODULE
53 | .getBinding()
54 | .getFactories()
55 | .getEidFactory()
56 | .create(eid);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/utils/UnsafeProcedure.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.utils;
18 |
19 | import pl.wavesoftware.eid.api.Eid;
20 |
21 | /**
22 | * This unsafe procedure can be used to execute a code block that can throw
23 | * some checked Exception, that you would like not to process, because they
24 | * are unrecoverable bugs.
25 | *
26 | * To be used with
27 | * {@link EidExecutions#tryToExecute(UnsafeProcedure, Eid)} or
28 | * {@link EidExecutions#tryToExecute(UnsafeProcedure, String)} methods.
29 | */
30 | public interface UnsafeProcedure {
31 | /**
32 | * Executes a procedure code that can throw a checked exception to be cough
33 | *
34 | * @throws Exception this exception should be set to concrete one ex. IOException
35 | */
36 | @SuppressWarnings("squid:S00112")
37 | void execute() throws Exception;
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/utils/UnsafeSupplier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.utils;
18 |
19 | import pl.wavesoftware.eid.api.Eid;
20 |
21 | /**
22 | * This unsafe supplier can be used to execute a code block that needs to
23 | * return some value and can throw some checked Exception, that you would like
24 | * not to process, because they are unrecoverable bugs.
25 | *
26 | * To be used with
27 | * {@link EidExecutions#tryToExecute(UnsafeSupplier, Eid)} or
28 | * {@link EidExecutions#tryToExecute(UnsafeSupplier, String)} methods
29 | *
30 | * @param a return type from unsafe supplier
31 | */
32 | public interface UnsafeSupplier {
33 | /**
34 | * Executes a supplier function that can throw a checked exception to be cough
35 | *
36 | * @return a return value from unsafe supplier function
37 | * @throws Exception this exception should be set to concrete one ex. IOException
38 | */
39 | @SuppressWarnings("squid:S00112")
40 | T get() throws Exception;
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/pl/wavesoftware/eid/utils/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * @author Krzysztof Suszynski
19 | * @since 2016-03-26
20 | */
21 | @javax.annotation.ParametersAreNonnullByDefault
22 | @ReturnTypesAreNonnullByDefault
23 | package pl.wavesoftware.eid.utils;
24 |
25 | import pl.wavesoftware.eid.api.ReturnTypesAreNonnullByDefault;
26 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/services/pl.wavesoftware.eid.api.Binding:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (c) 2018 Wave Software
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
17 | pl.wavesoftware.eid.impl.BindingImpl
18 |
--------------------------------------------------------------------------------
/src/test/groovy/verify-sonar-issues.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | import groovy.json.JsonSlurper
18 |
19 | String skip = properties.getAt('sonar.skip')
20 | if (skip == 'true') {
21 | log.info('sonar.skip = true: Skipping Sonar issues file analysis.')
22 | return
23 | }
24 | String issueFile = properties.getAt('sonar.issues.file')
25 | filepath = new File(issueFile)
26 | log.info('Sonar Issues file: ' + filepath)
27 | JsonSlurper slurper = new JsonSlurper()
28 | String contents = filepath.getText('UTF-8')
29 | def json = slurper.parseText(contents)
30 |
31 | def major = 0
32 | def critical = 0
33 | def blocker = 0
34 | def report = []
35 |
36 | json.issues.each {
37 | issue = it
38 | if (issue.isNew && issue.status == "OPEN") {
39 | switch (issue.severity) {
40 | case 'MAJOR':
41 | major++
42 | report << issue
43 | break
44 | case 'CRITICAL':
45 | critical++
46 | report << issue
47 | break
48 | case 'BLOCKER':
49 | blocker++
50 | report << issue
51 | break
52 | }
53 | }
54 | }
55 | red = major + critical + blocker
56 | if (red > 0) {
57 | msg = 'There are ' + red + ' new issue(s) that have severity of MAJOR or above (BLOCKER or CRITICAL)!'
58 | log.error(msg)
59 | log.error('')
60 | if (blocker) {
61 | log.error('Blocker: +' + blocker)
62 | }
63 | if (critical) {
64 | log.error('Critical: +' + critical)
65 | }
66 | if (major) {
67 | log.error('Major: +' + major)
68 | }
69 | fail(msg)
70 | } else {
71 | log.info('No new issues have been found')
72 | }
73 |
--------------------------------------------------------------------------------
/src/test/java/pl/wavesoftware/eid/ConfigurationContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid;
18 |
19 | import pl.wavesoftware.eid.api.Configurator;
20 | import pl.wavesoftware.eid.system.EidModule;
21 |
22 | import java.io.Closeable;
23 |
24 | /**
25 | * @author Krzysztof Suszynski
26 | * @since 2018-12-18
27 | */
28 | final class ConfigurationContext implements Closeable {
29 |
30 | private final Configurator saved;
31 |
32 | ConfigurationContext(Configurator configurator) {
33 | this.saved = EidModule.MODULE
34 | .getBinding()
35 | .getConfigurationSystem()
36 | .configure(configurator);
37 | }
38 |
39 | @Override
40 | public void close() {
41 | EidModule.MODULE
42 | .getBinding()
43 | .getConfigurationSystem()
44 | .configure(saved);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/test/java/pl/wavesoftware/eid/ConfiguratorRule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid;
18 |
19 | import org.junit.rules.TestRule;
20 | import org.junit.runner.Description;
21 | import org.junit.runners.model.Statement;
22 | import pl.wavesoftware.eid.api.Configurator;
23 |
24 | /**
25 | * @author Krzysztof Suszynski
26 | * @since 2018-12-17
27 | */
28 | public class ConfiguratorRule implements TestRule {
29 |
30 | private final Configurator configurator;
31 |
32 | public ConfiguratorRule(Configurator configurator) {
33 | this.configurator = configurator;
34 | }
35 |
36 | @Override
37 | public Statement apply(final Statement base, Description description) {
38 | return new Statement() {
39 | @Override
40 | public void evaluate() throws Throwable {
41 | ConfigurationContext context =
42 | new ConfigurationContext(configurator);
43 | try {
44 | base.evaluate();
45 | } finally {
46 | context.close();
47 | }
48 | }
49 | };
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/test/java/pl/wavesoftware/eid/ConstantUniqueIdRule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid;
18 |
19 | import pl.wavesoftware.eid.api.ConfigurationBuilder;
20 | import pl.wavesoftware.eid.api.Configurator;
21 | import pl.wavesoftware.eid.api.UniqueIdGenerator;
22 |
23 | /**
24 | * @author Krzysztof Suszynski
25 | * @since 2.0.0
26 | */
27 | public final class ConstantUniqueIdRule extends ConfiguratorRule {
28 |
29 | public ConstantUniqueIdRule(final String constantId) {
30 | super(new Configurator() {
31 | @Override
32 | public void configure(ConfigurationBuilder configuration) {
33 | configuration.uniqueIdGenerator(new UniqueIdGenerator() {
34 | @Override
35 | public String generateUniqId() {
36 | return constantId;
37 | }
38 | });
39 | }
40 | });
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/test/java/pl/wavesoftware/eid/DisableValidatorState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid;
18 |
19 | import org.openjdk.jmh.annotations.Scope;
20 | import org.openjdk.jmh.annotations.Setup;
21 | import org.openjdk.jmh.annotations.State;
22 | import org.openjdk.jmh.annotations.TearDown;
23 | import org.slf4j.Logger;
24 | import org.slf4j.LoggerFactory;
25 | import pl.wavesoftware.eid.api.ConfigurationBuilder;
26 | import pl.wavesoftware.eid.api.Configurator;
27 |
28 | /**
29 | * @author Krzysztof Suszynski
30 | * @since 2018-12-18
31 | */
32 | @State(Scope.Benchmark)
33 | public class DisableValidatorState {
34 | private static final Logger LOGGER =
35 | LoggerFactory.getLogger(DisableValidatorState.class);
36 | private ConfigurationContext context;
37 |
38 | @Setup
39 | public void setup() {
40 | context =
41 | new ConfigurationContext(new Configurator() {
42 | @Override
43 | public void configure(ConfigurationBuilder configuration) {
44 | configuration.validator(null);
45 | LOGGER.debug("Disable validation of Eid numbers");
46 | }
47 | });
48 | }
49 |
50 | @TearDown
51 | public void tearDown() {
52 | context.close();
53 | LOGGER.debug("Restoring configuration context");
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/test/java/pl/wavesoftware/eid/EidIT.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid;
18 |
19 | import org.junit.ClassRule;
20 | import org.junit.Test;
21 | import org.junit.rules.RuleChain;
22 | import org.openjdk.jmh.annotations.Benchmark;
23 | import org.openjdk.jmh.annotations.Mode;
24 | import org.openjdk.jmh.infra.Blackhole;
25 | import org.openjdk.jmh.results.RunResult;
26 | import org.openjdk.jmh.runner.Runner;
27 | import org.openjdk.jmh.runner.options.Options;
28 | import org.openjdk.jmh.runner.options.OptionsBuilder;
29 | import org.openjdk.jmh.runner.options.TimeValue;
30 | import org.slf4j.Logger;
31 | import org.slf4j.LoggerFactory;
32 | import pl.wavesoftware.eid.exceptions.EidRuntimeException;
33 | import pl.wavesoftware.testing.JavaAgentSkip;
34 | import pl.wavesoftware.testing.JavaVersion;
35 | import pl.wavesoftware.testing.JmhCleaner;
36 | import pl.wavesoftware.testing.JvmArgs;
37 |
38 | import java.util.Collection;
39 | import java.util.Date;
40 | import java.util.concurrent.TimeUnit;
41 |
42 | import static org.assertj.core.api.Assertions.assertThat;
43 |
44 | /**
45 | * @author Krzysztof Suszynski
46 | * @since 2016-03-24
47 | */
48 | public class EidIT {
49 |
50 | private static final int PERCENT = 100;
51 | private static final int OPERATIONS = 1000;
52 | private static final Logger LOG = LoggerFactory.getLogger(EidIT.class);
53 | private static final double SPEED_THRESHOLD =
54 | JavaVersion.get().greaterOrEqual(JavaVersion.of(8))
55 | ? 0.9d
56 | : 0.5d;
57 |
58 | @ClassRule
59 | public static RuleChain chain = RuleChain
60 | .outerRule(new JmhCleaner(EidIT.class))
61 | .around(JavaAgentSkip.ifActive());
62 |
63 | @Test
64 | public void benchmark() throws Exception {
65 | Options opt = new OptionsBuilder()
66 | .include(this.getClass().getName() + ".*")
67 | .mode(Mode.Throughput)
68 | .timeUnit(TimeUnit.MILLISECONDS)
69 | .operationsPerInvocation(OPERATIONS)
70 | .warmupTime(TimeValue.seconds(1))
71 | .warmupIterations(2)
72 | .measurementTime(TimeValue.seconds(1))
73 | .measurementIterations(5)
74 | .threads(4)
75 | .forks(1)
76 | .shouldFailOnError(true)
77 | .shouldDoGC(true)
78 | .jvmArgs(JvmArgs.get())
79 | .build();
80 |
81 | Runner runner = new Runner(opt);
82 | Collection results = runner.run();
83 | assertThat(results).hasSize(2);
84 |
85 | RunResult control = getRunResultByName(results, "control");
86 | RunResult eid = getRunResultByName(results, "eid");
87 | assertThat(control).isNotNull();
88 | assertThat(eid).isNotNull();
89 |
90 | double controlScore = control.getAggregatedResult().getPrimaryResult().getScore();
91 | double eidScore = eid.getAggregatedResult().getPrimaryResult().getScore();
92 |
93 | String title = "method speed quotient to the control sample";
94 | String eidTitle = String.format("%s %s should be at least %.2f%%", "#eid()",
95 | title, SPEED_THRESHOLD * PERCENT);
96 |
97 | double eidTimes = eidScore / controlScore;
98 |
99 | LOG.info(String.format("Control sample method time per operation: %" +
100 | ".2f ops / msec", controlScore));
101 | LOG.info(String.format("#eid() method time per operation: %" +
102 | ".2f ops / msec", eidScore));
103 | LOG.info(String.format("%s and is %.2f%%", eidTitle, eidTimes * PERCENT));
104 |
105 | assertThat(eidTimes).as(eidTitle).isGreaterThanOrEqualTo(SPEED_THRESHOLD);
106 | }
107 |
108 | @Benchmark
109 | public void control(Blackhole bh) {
110 | for (int i = 0; i < OPERATIONS; i++) {
111 | bh.consume(new Date());
112 | }
113 | }
114 |
115 | @Benchmark
116 | public void eid(Blackhole bh, DisableValidatorState state) {
117 | for (int i = 0; i < OPERATIONS; i++) {
118 | bh.consume(new DefaultEid("20160330:144947"));
119 | }
120 | }
121 |
122 | private static RunResult getRunResultByName(Collection results, String name) {
123 | String fullName = String.format("%s.%s", EidIT.class.getName(), name);
124 | for (RunResult result : results) {
125 | if (result.getParams().getBenchmark().equals(fullName)) {
126 | return result;
127 | }
128 | }
129 | throw new EidRuntimeException("20160324:225412", "Invalid name: " + name);
130 | }
131 |
132 | }
133 |
--------------------------------------------------------------------------------
/src/test/java/pl/wavesoftware/eid/EidTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package pl.wavesoftware.eid;
17 |
18 | import org.junit.Rule;
19 | import org.junit.Test;
20 | import org.junit.rules.ExpectedException;
21 | import pl.wavesoftware.eid.api.Eid;
22 | import pl.wavesoftware.eid.api.EidMessage;
23 |
24 | import java.util.ArrayList;
25 | import java.util.Collection;
26 | import java.util.HashSet;
27 | import java.util.List;
28 | import java.util.Set;
29 | import java.util.concurrent.Callable;
30 | import java.util.concurrent.ExecutionException;
31 | import java.util.concurrent.ExecutorService;
32 | import java.util.concurrent.Executors;
33 | import java.util.concurrent.Future;
34 |
35 | import static org.assertj.core.api.Assertions.assertThat;
36 |
37 | /**
38 | * @author Krzysztof Suszynski
39 | * @since 2.0.0
40 | */
41 | public class EidTest {
42 |
43 | @Rule
44 | public final ExpectedException thrown = ExpectedException.none();
45 |
46 | @Test
47 | public void invalidNullEid() {
48 | // given
49 | String eid = null;
50 |
51 | // then
52 | thrown.expect(IllegalArgumentException.class);
53 | thrown.expectMessage("Exception ID can't be null");
54 |
55 | // when
56 | DefaultEid.eid(eid);
57 | }
58 |
59 | @Test
60 | public void invalidEid() {
61 | // given
62 | String eid = "1234";
63 |
64 | // then
65 | thrown.expect(IllegalArgumentException.class);
66 | thrown.expectMessage("Invalid ID given as an Exception ID: 1234");
67 |
68 | // when
69 | DefaultEid.eid(eid);
70 | }
71 |
72 | @Test
73 | public void testToString() {
74 | // given
75 | DefaultEid instance = new DefaultEid("20150718:012917");
76 | String expResult = "[20150718:012917]";
77 | // when
78 | String result = instance.toString();
79 | // then
80 | assertThat(result).contains(expResult);
81 | assertThat(result).matches("^\\[20150718:012917\\]<[a-zA-Z0-9_-]+>$");
82 | }
83 |
84 | @Test
85 | public void testToString_Ref() {
86 | // given
87 | DefaultEid instance = new DefaultEid("20150718:013056", "ORA-38101");
88 | String expResult = "[20150718:013056|ORA-38101]";
89 | // when
90 | String result = instance.toString();
91 | // then
92 | assertThat(result).contains(expResult);
93 | }
94 |
95 | @Test
96 | public void testGetId() {
97 | // given
98 | DefaultEid instance = new DefaultEid("20150718:013209");
99 | String expResult = "20150718:013209";
100 | // when
101 | String result = instance.getId();
102 | // then
103 | assertThat(result).isEqualTo(expResult);
104 | }
105 |
106 | @Test
107 | public void testGetRef() {
108 | // given
109 | DefaultEid instance = new DefaultEid("20150718:013314", "ORA-38105");
110 | String expResult = "ORA-38105";
111 | // when
112 | String result = instance.getRef();
113 | // then
114 | assertThat(result).isEqualTo(expResult);
115 | }
116 |
117 | @Test
118 | public void testGetRef_Null() {
119 | // given
120 | Eid instance = DefaultEid.eid("20150718:013236");
121 | // when
122 | String result = instance.getRef();
123 | // then
124 | assertThat(result).isNull();
125 | }
126 |
127 | @Test
128 | public void testGetUniq() {
129 | String id = "20150718:013443";
130 | DefaultEid instance = new DefaultEid(id);
131 | DefaultEid instance2 = new DefaultEid(id);
132 | String result = instance.getUnique();
133 | String result2 = instance2.getUnique();
134 | assertThat(result).isNotEmpty();
135 | assertThat(result).isNotEqualTo(result2);
136 | }
137 |
138 | @Test
139 | public void message() {
140 | // given
141 | String code = "20151117:192211";
142 | DefaultEid eid = new DefaultEid(code);
143 | int filesNumber = 18;
144 |
145 | // when
146 | EidMessage message = eid.message("Files: {0}", filesNumber);
147 |
148 | // then
149 | assertThat(message).contains("[20151117:192211]<", "> => Files: 18");
150 | }
151 |
152 | @Test
153 | public void raceTheSun() throws InterruptedException, ExecutionException {
154 | // given
155 | final DefaultEid eid = new DefaultEid("20181114:223748");
156 | ExecutorService executorService = Executors.newFixedThreadPool(4);
157 | Callable task = new Callable() {
158 | @Override
159 | public String call() {
160 | return eid.getUnique();
161 | }
162 | };
163 | Collection> tasks =
164 | new ArrayList>(20);
165 | for (int i = 0; i < 20; i++) {
166 | tasks.add(task);
167 | }
168 | executorService.invokeAll(tasks);
169 |
170 | // when
171 | List> executed = executorService.invokeAll(tasks);
172 |
173 | // then
174 | Set collected = new HashSet();
175 | for (Future future : executed) {
176 | collected.add(future.get());
177 | }
178 | assertThat(collected).hasSize(1);
179 | }
180 |
181 | }
182 |
--------------------------------------------------------------------------------
/src/test/java/pl/wavesoftware/eid/api/TestConfigurator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.api;
18 |
19 | import java.util.Locale;
20 | import java.util.TimeZone;
21 | import java.util.regex.Pattern;
22 |
23 | /**
24 | * @author Krzysztof Suszynski
25 | * @since 2.0.0
26 | */
27 | public final class TestConfigurator implements Configurator {
28 |
29 | @Override
30 | public void configure(ConfigurationBuilder configuration) {
31 | configuration
32 | .locale(Locale.ENGLISH)
33 | .timezone(TimeZone.getTimeZone("GMT"))
34 | .validator(new PseudoDateValidator());
35 | }
36 |
37 | private static final class PseudoDateValidator implements Validator {
38 | private final Pattern pattern = Pattern.compile("^\\d{8}:\\d{6}$");
39 |
40 | @Override
41 | public boolean isValid(CharSequence id) {
42 | return pattern.matcher(id).matches();
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/test/java/pl/wavesoftware/eid/exceptions/A.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.exceptions;
18 |
19 | /**
20 | * @author Krzysztof Suszynski
21 | * @since 2018-12-16
22 | */
23 | class A {
24 | @Override
25 | public String toString() {
26 | return "a";
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/test/java/pl/wavesoftware/eid/exceptions/AssertionsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.exceptions;
18 |
19 | import org.junit.Rule;
20 | import org.junit.Test;
21 | import org.junit.rules.ExpectedException;
22 | import pl.wavesoftware.eid.DefaultEid;
23 |
24 | /**
25 | * @author Krzysztof Suszyński
26 | * @since 21.07.15
27 | */
28 | public class AssertionsTest {
29 |
30 | @Rule
31 | public final ExpectedException thrown = ExpectedException.none();
32 |
33 | @Test
34 | public void testJdkAssertions() {
35 | // then
36 | thrown.expect(AssertionError.class);
37 |
38 | // when
39 | assert getTestNumber() < 3 : new DefaultEid("20150721:101958");
40 | }
41 |
42 | private int getTestNumber() {
43 | return 3 * 5;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/test/java/pl/wavesoftware/eid/exceptions/EidIllegalArgumentExceptionTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.exceptions;
18 |
19 | import org.junit.Rule;
20 | import org.junit.Test;
21 | import pl.wavesoftware.eid.ConstantUniqueIdRule;
22 | import pl.wavesoftware.eid.DefaultEid;
23 | import pl.wavesoftware.eid.api.Eid;
24 | import pl.wavesoftware.eid.api.EidMessage;
25 |
26 | import java.io.IOException;
27 |
28 | import static org.assertj.core.api.Assertions.assertThat;
29 |
30 | /**
31 | * @author Krzysztof Suszynski
32 | * @since 2.0.0
33 | */
34 | public class EidIllegalArgumentExceptionTest {
35 |
36 | @Rule
37 | public ConstantUniqueIdRule uniqueIdRule = new ConstantUniqueIdRule(
38 | "d3m0"
39 | );
40 |
41 | @Test
42 | public void constructOfCharSequence() {
43 | // given
44 | String eid = "20181215:000127";
45 |
46 | // when
47 | EidRuntimeException ex = new EidIllegalArgumentException(eid);
48 |
49 | // then
50 | assertThat(ex).hasNoCause()
51 | .hasMessage("[20181215:000127]");
52 | }
53 |
54 | @Test
55 | public void constructOfCharSequenceAndMessage() {
56 | // given
57 | String eid = "20181215:000410";
58 | String message = "This is message";
59 |
60 | // when
61 | EidRuntimeException ex = new EidIllegalArgumentException(eid, message);
62 |
63 | // then
64 | assertThat(ex).hasNoCause()
65 | .hasMessage("[20181215:000410] => This is message");
66 | }
67 |
68 | @Test
69 | public void constructOfEidMessage() {
70 | // given
71 | DefaultEid eid = new DefaultEid("20181216:175048");
72 | EidMessage message = eid.message(
73 | "This is {0} message", new A()
74 | );
75 |
76 | // when
77 | EidRuntimeException ex = new EidIllegalArgumentException(message);
78 |
79 | // then
80 | assertThat(ex)
81 | .hasNoCause()
82 | .hasMessage("[20181216:175048] => This is a message");
83 | }
84 |
85 | @Test
86 | public void constructOfCharSequenceAndMessageAndCause() {
87 | // given
88 | String eid = "20181215:001337";
89 | String message = "This is message";
90 | Throwable cause = getCause();
91 |
92 | // when
93 | EidRuntimeException ex = new EidIllegalArgumentException(
94 | eid, message, cause
95 | );
96 |
97 | // then
98 | assertThat(ex)
99 | .hasCauseInstanceOf(IOException.class)
100 | .hasMessage("[20181215:001337] => This is message");
101 | }
102 |
103 | @Test
104 | public void constructOfEidMessageAndCause() {
105 | // given
106 | DefaultEid eid = new DefaultEid("20181215:000410");
107 | EidMessage message = eid.message(
108 | "This is {0} message", new A()
109 | );
110 | Throwable cause = getCause();
111 |
112 | // when
113 | EidRuntimeException ex = new EidIllegalArgumentException(message, cause);
114 |
115 | // then
116 | assertThat(ex)
117 | .hasCauseInstanceOf(IOException.class)
118 | .hasMessage("[20181215:000410] => This is a message");
119 | }
120 |
121 | @Test
122 | public void constructOfCharSequenceAndCause() {
123 | // given
124 | String eid = "20181216:175040";
125 | Throwable cause = getCause();
126 |
127 | // when
128 | EidRuntimeException ex = new EidIllegalArgumentException(eid, cause);
129 |
130 | // then
131 | assertThat(ex)
132 | .hasCauseInstanceOf(IOException.class)
133 | .hasMessage("[20181216:175040] => A cause");
134 | }
135 |
136 | @Test
137 | public void constructOfEid() {
138 | // given
139 | Eid eid = DefaultEid.eid("20181216:180054");
140 |
141 | // when
142 | EidRuntimeException ex = new EidIllegalArgumentException(eid);
143 |
144 | // then
145 | assertThat(ex)
146 | .hasNoCause()
147 | .hasMessage("[20181216:180054]");
148 | }
149 |
150 | @Test
151 | public void constructOfEidAndMessage() {
152 | // given
153 | Eid eid = DefaultEid.eid("20181216:180212");
154 | String message = "A simple message";
155 |
156 | // when
157 | EidRuntimeException ex = new EidIllegalArgumentException(eid, message);
158 |
159 | // then
160 | assertThat(ex)
161 | .hasNoCause()
162 | .hasMessage("[20181216:180212] => A simple message");
163 | }
164 |
165 | @Test
166 | public void constructOfEidAndMessageAndCause() {
167 | // given
168 | Eid eid = DefaultEid.eid("20181216:180355");
169 | String message = "A simple message";
170 | Throwable cause = getCause();
171 |
172 | // when
173 | EidRuntimeException ex = new EidIllegalArgumentException(
174 | eid, message, cause
175 | );
176 |
177 | // then
178 | assertThat(ex)
179 | .hasCauseInstanceOf(IOException.class)
180 | .hasMessage("[20181216:180355] => A simple message");
181 | }
182 |
183 | @Test
184 | public void constructOfEidAndCause() {
185 | // given
186 | Eid eid = DefaultEid.eid("20181216:191804");
187 | Throwable cause = getCause();
188 |
189 | // when
190 | EidRuntimeException ex = new EidIllegalArgumentException(
191 | eid, cause
192 | );
193 |
194 | // then
195 | assertThat(ex)
196 | .hasCauseInstanceOf(IOException.class)
197 | .hasMessage("[20181216:191804] => A cause");
198 | }
199 |
200 | private static IOException getCause() {
201 | return new IOException("A cause");
202 | }
203 |
204 | }
205 |
--------------------------------------------------------------------------------
/src/test/java/pl/wavesoftware/eid/exceptions/EidIllegalStateExceptionTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.exceptions;
18 |
19 | import org.junit.Rule;
20 | import org.junit.Test;
21 | import pl.wavesoftware.eid.ConstantUniqueIdRule;
22 | import pl.wavesoftware.eid.DefaultEid;
23 | import pl.wavesoftware.eid.api.Eid;
24 | import pl.wavesoftware.eid.api.EidMessage;
25 |
26 | import java.io.IOException;
27 |
28 | import static org.assertj.core.api.Assertions.assertThat;
29 |
30 | /**
31 | * @author Krzysztof Suszynski
32 | * @since 2018-12-16
33 | */
34 | public class EidIllegalStateExceptionTest {
35 | @Rule
36 | public ConstantUniqueIdRule uniqueIdRule = new ConstantUniqueIdRule(
37 | "e9b1"
38 | );
39 |
40 | @Test
41 | public void constructOfCharSequence() {
42 | // given
43 | String eid = "20181216:192816";
44 |
45 | // when
46 | EidRuntimeException ex = new EidIllegalStateException(eid);
47 |
48 | // then
49 | assertThat(ex).hasNoCause()
50 | .hasMessage("[20181216:192816]");
51 | }
52 |
53 | @Test
54 | public void constructOfCharSequenceAndMessage() {
55 | // given
56 | String eid = "20181216:192843";
57 | String message = "This is message";
58 |
59 | // when
60 | EidRuntimeException ex = new EidIllegalStateException(eid, message);
61 |
62 | // then
63 | assertThat(ex).hasNoCause()
64 | .hasMessage("[20181216:192843] => This is message");
65 | }
66 |
67 | @Test
68 | public void constructOfEidMessage() {
69 | // given
70 | DefaultEid eid = new DefaultEid("20181216:192906");
71 | EidMessage message = eid.message(
72 | "This is {0} message", new A()
73 | );
74 |
75 | // when
76 | EidRuntimeException ex = new EidIllegalStateException(message);
77 |
78 | // then
79 | assertThat(ex)
80 | .hasNoCause()
81 | .hasMessage("[20181216:192906] => This is a message");
82 | }
83 |
84 | @Test
85 | public void constructOfCharSequenceAndMessageAndCause() {
86 | // given
87 | String eid = "20181216:192917";
88 | String message = "This is message";
89 | Throwable cause = getCause();
90 |
91 | // when
92 | EidRuntimeException ex = new EidIllegalStateException(
93 | eid, message, cause
94 | );
95 |
96 | // then
97 | assertThat(ex)
98 | .hasCauseInstanceOf(IOException.class)
99 | .hasMessage("[20181216:192917] => This is message");
100 | }
101 |
102 | @Test
103 | public void constructOfEidMessageAndCause() {
104 | // given
105 | DefaultEid eid = new DefaultEid("20181216:192930");
106 | EidMessage message = eid.message(
107 | "This is {0} message", new A()
108 | );
109 | Throwable cause = getCause();
110 |
111 | // when
112 | EidRuntimeException ex = new EidIllegalStateException(message, cause);
113 |
114 | // then
115 | assertThat(ex)
116 | .hasCauseInstanceOf(IOException.class)
117 | .hasMessage("[20181216:192930] => This is a message");
118 | }
119 |
120 | @Test
121 | public void constructOfCharSequenceAndCause() {
122 | // given
123 | String eid = "20181216:192938";
124 | Throwable cause = getCause();
125 |
126 | // when
127 | EidRuntimeException ex = new EidIllegalStateException(eid, cause);
128 |
129 | // then
130 | assertThat(ex)
131 | .hasCauseInstanceOf(IOException.class)
132 | .hasMessage("[20181216:192938] => A cause");
133 | }
134 |
135 | @Test
136 | public void constructOfEid() {
137 | // given
138 | Eid eid = DefaultEid.eid("20181216:192947");
139 |
140 | // when
141 | EidRuntimeException ex = new EidIllegalStateException(eid);
142 |
143 | // then
144 | assertThat(ex)
145 | .hasNoCause()
146 | .hasMessage("[20181216:192947]");
147 | }
148 |
149 | @Test
150 | public void constructOfEidAndMessage() {
151 | // given
152 | Eid eid = DefaultEid.eid("20181216:192956");
153 | String message = "A simple message";
154 |
155 | // when
156 | EidRuntimeException ex = new EidIllegalStateException(eid, message);
157 |
158 | // then
159 | assertThat(ex)
160 | .hasNoCause()
161 | .hasMessage("[20181216:192956] => A simple message");
162 | }
163 |
164 | @Test
165 | public void constructOfEidAndMessageAndCause() {
166 | // given
167 | Eid eid = DefaultEid.eid("20181216:193003");
168 | String message = "A simple message";
169 | Throwable cause = getCause();
170 |
171 | // when
172 | EidRuntimeException ex = new EidIllegalStateException(
173 | eid, message, cause
174 | );
175 |
176 | // then
177 | assertThat(ex)
178 | .hasCauseInstanceOf(IOException.class)
179 | .hasMessage("[20181216:193003] => A simple message");
180 | }
181 |
182 | @Test
183 | public void constructOfEidAndCause() {
184 | // given
185 | Eid eid = DefaultEid.eid("20181216:193015");
186 | Throwable cause = getCause();
187 |
188 | // when
189 | EidRuntimeException ex = new EidIllegalStateException(
190 | eid, cause
191 | );
192 |
193 | // then
194 | assertThat(ex)
195 | .hasCauseInstanceOf(IOException.class)
196 | .hasMessage("[20181216:193015] => A cause");
197 | }
198 |
199 | private static Throwable getCause() {
200 | return new IOException("A cause");
201 | }
202 | }
203 |
--------------------------------------------------------------------------------
/src/test/java/pl/wavesoftware/eid/exceptions/EidIndexOutOfBoundsExceptionTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.exceptions;
18 |
19 | import org.hamcrest.CoreMatchers;
20 | import org.junit.Rule;
21 | import org.junit.Test;
22 | import org.junit.rules.ExpectedException;
23 | import pl.wavesoftware.eid.ConstantUniqueIdRule;
24 | import pl.wavesoftware.eid.DefaultEid;
25 | import pl.wavesoftware.eid.api.Eid;
26 |
27 | import static org.hamcrest.CoreMatchers.containsString;
28 | import static org.hamcrest.CoreMatchers.nullValue;
29 | import static org.junit.internal.matchers.ThrowableMessageMatcher.hasMessage;
30 |
31 | /**
32 | * @author Krzysztof Suszynski
33 | * @since 2015-11-19
34 | */
35 | public class EidIndexOutOfBoundsExceptionTest {
36 |
37 | @Rule
38 | public final ExpectedException thrown = ExpectedException.none();
39 |
40 | @Rule
41 | public final ConstantUniqueIdRule uniqueIdRule = new ConstantUniqueIdRule(
42 | "deadfa11"
43 | );
44 |
45 | private final String causeString = "Index seams to be invalid";
46 |
47 | @Test
48 | public void throwWithEidWithRefAndCause() {
49 | // given
50 | String eid = "20151119:103158";
51 | String ref = "MS+1233";
52 |
53 | // then
54 | thrown.expectCause(hasMessage(containsString(causeString)));
55 | thrown.expectCause(CoreMatchers.instanceOf(ArrayIndexOutOfBoundsException.class));
56 | thrown.expect(EidIndexOutOfBoundsException.class);
57 | thrown.expectMessage(
58 | "[20151119:103158|MS+1233] => " +
59 | "Index seams to be invalid"
60 | );
61 |
62 | // when
63 | throw new EidIndexOutOfBoundsException(new DefaultEid(eid, ref), getCause());
64 | }
65 |
66 | @Test
67 | public void throwWithEidWithRef() {
68 | // given
69 | String eid = "20151119:103217";
70 | String ref = "MS+1233";
71 |
72 | // then
73 | thrown.expect(EidIndexOutOfBoundsException.class);
74 | thrown.expectMessage("[20151119:103217|MS+1233]");
75 |
76 | // when
77 | throw new EidIndexOutOfBoundsException(new DefaultEid(eid, ref));
78 | }
79 |
80 | @Test
81 | public void throwWithStringAndCause() {
82 | // given
83 | String eid = "20151119:103232";
84 |
85 | // then
86 | thrown.expectCause(hasMessage(containsString(causeString)));
87 | thrown.expectCause(CoreMatchers.instanceOf(ArrayIndexOutOfBoundsException.class));
88 | thrown.expect(EidIndexOutOfBoundsException.class);
89 | thrown.expectMessage("[20151119:103232] => " +
90 | "Index seams to be invalid");
91 |
92 | // when
93 | throw new EidIndexOutOfBoundsException(eid, getCause());
94 | }
95 |
96 | @Test
97 | public void throwWithEidAndCause() {
98 | // given
99 | String eidNum = "20151119:103245";
100 | DefaultEid eid = new DefaultEid(eidNum);
101 |
102 | // then
103 | thrown.expectCause(hasMessage(containsString(causeString)));
104 | thrown.expectCause(CoreMatchers.instanceOf(
105 | ArrayIndexOutOfBoundsException.class
106 | ));
107 | thrown.expect(EidIndexOutOfBoundsException.class);
108 | thrown.expectMessage("[20151119:103245] => " +
109 | "Index seams to be invalid");
110 |
111 | // when
112 | throw new EidIndexOutOfBoundsException(eid, getCause());
113 | }
114 |
115 | @Test
116 | public void throwWithString() {
117 | // given
118 | String eid = "20181216:233656";
119 |
120 | // then
121 | thrown.expectCause(nullValue(Throwable.class));
122 | thrown.expect(EidIndexOutOfBoundsException.class);
123 | thrown.expectMessage("[20181216:233656]");
124 |
125 | // when
126 | throw new EidIndexOutOfBoundsException(eid);
127 | }
128 |
129 | @Test
130 | public void throwWithStringAndString() {
131 | // given
132 | String eid = "20181216:233958";
133 | String message = "This is a message";
134 |
135 | // then
136 | thrown.expectCause(nullValue(Throwable.class));
137 | thrown.expect(EidIndexOutOfBoundsException.class);
138 | thrown.expectMessage("[20181216:233958] => " +
139 | "This is a message");
140 |
141 | // when
142 | throw new EidIndexOutOfBoundsException(eid, message);
143 | }
144 |
145 | @Test
146 | public void throwWithEidMessage() {
147 | // given
148 | String eid = "20181216:235124";
149 | String message = "This is {0} message";
150 |
151 | // then
152 | thrown.expectCause(nullValue(Throwable.class));
153 | thrown.expect(EidIndexOutOfBoundsException.class);
154 | thrown.expectMessage("[20181216:235124] => " +
155 | "This is a message");
156 |
157 | // when
158 | throw new EidIndexOutOfBoundsException(
159 | DefaultEid.eid(eid).message(message, new A())
160 | );
161 | }
162 |
163 | @Test
164 | public void throwWithStringStringAndCause() {
165 | // given
166 | String eid = "20181216:235554";
167 | String message = "This is a message";
168 |
169 | // then
170 | thrown.expect(EidIndexOutOfBoundsException.class);
171 | thrown.expectMessage("[20181216:235554] => " +
172 | "This is a message");
173 | thrown.expectCause(CoreMatchers.instanceOf(
174 | ArrayIndexOutOfBoundsException.class
175 | ));
176 |
177 | // when
178 | throw new EidIndexOutOfBoundsException(
179 | eid, message, getCause()
180 | );
181 | }
182 |
183 | @Test
184 | public void throwWithEidMessageAndCause() {
185 | // given
186 | String eid = "20181216:235729";
187 | String message = "This is {0} message";
188 |
189 | // then
190 | thrown.expect(EidIndexOutOfBoundsException.class);
191 | thrown.expectMessage("[20181216:235729] => " +
192 | "This is a message");
193 | thrown.expectCause(CoreMatchers.instanceOf(
194 | ArrayIndexOutOfBoundsException.class
195 | ));
196 |
197 | // when
198 | throw new EidIndexOutOfBoundsException(
199 | DefaultEid.eid(eid).message(message, new A()), getCause()
200 | );
201 | }
202 |
203 | @Test
204 | public void throwWithEidAndMessage() {
205 | // given
206 | Eid eid = DefaultEid.eid("20181217:001519");
207 | String message = "This is a message";
208 |
209 | // then
210 | thrown.expect(EidIndexOutOfBoundsException.class);
211 | thrown.expectMessage("[20181217:001519] => " +
212 | "This is a message");
213 | thrown.expectCause(nullValue(Throwable.class));
214 |
215 | // when
216 | throw new EidIndexOutOfBoundsException(
217 | eid, message
218 | );
219 | }
220 |
221 | @Test
222 | public void throwWithEidAndMessageAndCause() {
223 | // given
224 | Eid eid = DefaultEid.eid("20181217:001727");
225 | String message = "This is a message";
226 |
227 | // then
228 | thrown.expect(EidIndexOutOfBoundsException.class);
229 | thrown.expectMessage("[20181217:001727] => " +
230 | "This is a message");
231 | thrown.expectCause(CoreMatchers.instanceOf(
232 | ArrayIndexOutOfBoundsException.class
233 | ));
234 |
235 | // when
236 | throw new EidIndexOutOfBoundsException(
237 | eid, message, getCause()
238 | );
239 | }
240 |
241 | private Throwable getCause() {
242 | return new ArrayIndexOutOfBoundsException(causeString);
243 | }
244 | }
245 |
--------------------------------------------------------------------------------
/src/test/java/pl/wavesoftware/eid/exceptions/EidNullPointerExceptionTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.exceptions;
18 |
19 | import org.hamcrest.CoreMatchers;
20 | import org.junit.Rule;
21 | import org.junit.Test;
22 | import org.junit.rules.ExpectedException;
23 | import pl.wavesoftware.eid.ConstantUniqueIdRule;
24 | import pl.wavesoftware.eid.DefaultEid;
25 | import pl.wavesoftware.eid.api.Eid;
26 | import pl.wavesoftware.eid.api.EidMessage;
27 |
28 | import static org.hamcrest.CoreMatchers.containsString;
29 | import static org.hamcrest.CoreMatchers.nullValue;
30 | import static org.junit.internal.matchers.ThrowableMessageMatcher.hasMessage;
31 |
32 | /**
33 | * @author Krzysztof Suszynski
34 | * @since 2015-11-19
35 | */
36 | public class EidNullPointerExceptionTest {
37 |
38 | private final String constUniq = "deadcafe";
39 | private final String causeString = "A cause";
40 |
41 | @Rule
42 | public ExpectedException thrown = ExpectedException.none();
43 | @Rule
44 | public ConstantUniqueIdRule uniqueIdRule =
45 | new ConstantUniqueIdRule(constUniq);
46 |
47 | @Test
48 | public void throwWithString() {
49 | // given
50 | String eid = "20181217:220721";
51 |
52 | // then
53 | thrown.expectCause(nullValue(Throwable.class));
54 | thrown.expect(EidNullPointerException.class);
55 | thrown.expectMessage("[20181217:220721]");
56 |
57 | // when
58 | throw new EidNullPointerException(eid);
59 | }
60 |
61 | @Test
62 | public void throwWithStringAndCause() {
63 | // given
64 | String eid = "20151119:101810";
65 |
66 | // then
67 | thrown.expectCause(hasMessage(containsString(causeString)));
68 | thrown.expectCause(CoreMatchers.instanceOf(
69 | UnsupportedOperationException.class
70 | ));
71 | thrown.expect(EidNullPointerException.class);
72 | thrown.expectMessage("[20151119:101810] => A cause");
73 |
74 | // when
75 | throw new EidNullPointerException(eid, getCause());
76 | }
77 |
78 | @Test
79 | public void throwWithEidAndCause() {
80 | // given
81 | String eidNum = "20151119:102150";
82 | DefaultEid eid = new DefaultEid(eidNum);
83 |
84 | // then
85 | thrown.expectCause(hasMessage(containsString(causeString)));
86 | thrown.expectCause(CoreMatchers.instanceOf(UnsupportedOperationException.class));
87 | thrown.expect(EidNullPointerException.class);
88 | thrown.expectMessage("[20151119:102150] => A cause");
89 |
90 | // when
91 | throw new EidNullPointerException(eid, getCause());
92 | }
93 |
94 | @Test
95 | public void throwWithEidAndNullCause() {
96 | // given
97 | String eidNum = "20181217:222651";
98 | DefaultEid eid = new DefaultEid(eidNum);
99 | Throwable cause = null;
100 |
101 | // then
102 | thrown.expectCause(nullValue(Throwable.class));
103 | thrown.expect(EidNullPointerException.class);
104 | thrown.expectMessage("[20181217:222651]");
105 |
106 | // when
107 | throw new EidNullPointerException(eid, cause);
108 | }
109 |
110 | @Test
111 | public void throwWithEidAndRefAndCause() {
112 | // given
113 | String eid = "20151119:100854";
114 | String ref = "PL-9584";
115 |
116 | // then
117 | thrown.expectCause(hasMessage(containsString(causeString)));
118 | thrown.expectCause(CoreMatchers.instanceOf(
119 | UnsupportedOperationException.class
120 | ));
121 | thrown.expect(EidNullPointerException.class);
122 | thrown.expectMessage("[20151119:100854|PL-9584] => A cause");
123 |
124 | // when
125 | throw new EidNullPointerException(new DefaultEid(eid, ref), getCause());
126 | }
127 |
128 | @Test
129 | public void throwWithEid() {
130 | // given
131 | String eid = "20151119:100854";
132 | String ref = "PL-9584";
133 |
134 | // then
135 | thrown.expect(EidNullPointerException.class);
136 | thrown.expectMessage("[20151119:100854|PL-9584]");
137 |
138 | // when
139 | throw new EidNullPointerException(new DefaultEid(eid, ref));
140 | }
141 |
142 | @Test
143 | public void throwWithEidMessageAndCause() {
144 | // given
145 | String eid = "20181217:220935";
146 | EidMessage message = DefaultEid.eid(eid)
147 | .message("This is {0} message", new A());
148 |
149 | // then
150 | thrown.expectCause(hasMessage(containsString(causeString)));
151 | thrown.expectCause(CoreMatchers.instanceOf(
152 | UnsupportedOperationException.class
153 | ));
154 | thrown.expect(EidNullPointerException.class);
155 | thrown.expectMessage(
156 | "[20181217:220935] => This is a message"
157 | );
158 |
159 | // when
160 | throw new EidNullPointerException(message, getCause());
161 | }
162 |
163 | @Test
164 | public void throwWithEidAndMessage() {
165 | // given
166 | Eid eid = DefaultEid.eid("20181217:221725");
167 | String message = "This is a message";
168 |
169 | // then
170 | thrown.expectCause(nullValue(Throwable.class));
171 | thrown.expect(EidNullPointerException.class);
172 | thrown.expectMessage(
173 | "[20181217:221725] => This is a message"
174 | );
175 |
176 | // when
177 | throw new EidNullPointerException(eid, message);
178 | }
179 |
180 | @Test
181 | public void throwWithEidAndMessageAndCause() {
182 | // given
183 | DefaultEid eid = new DefaultEid("20181217:221901");
184 | String message = "This is a message";
185 |
186 | // then
187 | thrown.expectCause(hasMessage(containsString(causeString)));
188 | thrown.expectCause(CoreMatchers.instanceOf(
189 | UnsupportedOperationException.class
190 | ));
191 | thrown.expect(EidNullPointerException.class);
192 | thrown.expectMessage(
193 | "[20181217:221901] => This is a message"
194 | );
195 |
196 | // when
197 | throw new EidNullPointerException(eid, message, getCause());
198 | }
199 |
200 | private Throwable getCause() {
201 | return new UnsupportedOperationException(causeString);
202 | }
203 | }
204 |
--------------------------------------------------------------------------------
/src/test/java/pl/wavesoftware/eid/exceptions/EidRuntimeExceptionTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package pl.wavesoftware.eid.exceptions;
18 |
19 | import org.hamcrest.CoreMatchers;
20 | import org.junit.Rule;
21 | import org.junit.Test;
22 | import org.junit.rules.ExpectedException;
23 |
24 | import javax.naming.NamingException;
25 | import java.util.UnknownFormatConversionException;
26 |
27 | import static org.hamcrest.CoreMatchers.containsString;
28 | import static org.hamcrest.CoreMatchers.is;
29 | import static org.junit.internal.matchers.ThrowableMessageMatcher.hasMessage;
30 |
31 | /**
32 | * @author Krzysztof Suszyński
33 | * @since 2015-10-07
34 | */
35 | public class EidRuntimeExceptionTest {
36 |
37 | @Rule
38 | public ExpectedException thrown = ExpectedException.none();
39 |
40 | @Test
41 | public void testGetMessage() {
42 | // then
43 | thrown.expect(EidRuntimeException.class);
44 | thrown.expectCause(CoreMatchers.instanceOf(NamingException.class));
45 | thrown.expectCause(hasMessage(is((String) null)));
46 | thrown.expectMessage(containsString("20151007:212217"));
47 | thrown.expectMessage(containsString(
48 | "javax.naming.NamingException [Root exception is java.util" +
49 | ".UnknownFormatConversionException: Conversion = Invalid for" +
50 | " unit test]"
51 | ));
52 |
53 | // given
54 | Throwable original = new UnknownFormatConversionException("Invalid for unit test");
55 | NamingException cause = new NamingException(null);
56 | cause.setRootCause(original);
57 | throw new EidRuntimeException("20151007:212217", cause);
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/test/java/pl/wavesoftware/eid/exceptions/ExceptionsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015 Wave Software
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package pl.wavesoftware.eid.exceptions;
17 |
18 | import org.assertj.core.util.Lists;
19 | import org.junit.Test;
20 | import org.junit.runner.RunWith;
21 | import org.junit.runners.Parameterized;
22 | import org.junit.runners.Parameterized.Parameters;
23 | import pl.wavesoftware.eid.DefaultEid;
24 | import pl.wavesoftware.eid.api.Eid;
25 |
26 | import java.lang.reflect.Constructor;
27 | import java.lang.reflect.InvocationTargetException;
28 | import java.util.Arrays;
29 | import java.util.List;
30 |
31 | import static org.assertj.core.api.Assertions.assertThat;
32 |
33 | /**
34 | *
35 | * @author Krzysztof Suszyński
36 | */
37 | @SuppressWarnings("unused")
38 | @RunWith(Parameterized.class)
39 | public class ExceptionsTest {
40 |
41 | @Parameters(name = "{index}: {0}({1})")
42 | public static Iterable