Skip to content

Commit 1628a27

Browse files
Collect assertKeyStrictly into one location
This is done to ensure coverage of all registering locations. We purposefully omit `computeIfAbsent` as this does _not_ register a new DataLoader if there is an existing key.
1 parent af3ebf4 commit 1628a27

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

src/main/java/org/dataloader/DataLoaderRegistry.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ protected DataLoaderRegistry(
8585
* @param existingDL the existing data loader
8686
* @return a new {@link DataLoader} or the same one if there is nothing to change
8787
*/
88-
private static DataLoader<?, ?> nameAndInstrumentDL(String key, @Nullable DataLoaderInstrumentation registryInstrumentation, DataLoader<?, ?> existingDL) {
88+
private DataLoader<?, ?> nameAndInstrumentDL(String key, @Nullable DataLoaderInstrumentation registryInstrumentation, DataLoader<?, ?> existingDL) {
89+
if (strictMode) {
90+
assertKeyStrictly(key);
91+
}
8992
existingDL = checkAndSetName(key, existingDL);
9093

9194
if (registryInstrumentation == null) {
@@ -153,9 +156,6 @@ private static DataLoaderOptions setInInstrumentation(DataLoaderOptions options,
153156
*/
154157
public DataLoaderRegistry register(DataLoader<?, ?> dataLoader) {
155158
String name = Assertions.nonNull(dataLoader.getName(), () -> "The DataLoader must have a non null name");
156-
if (strictMode) {
157-
assertKeyStrictly(name);
158-
}
159159
dataLoaders.put(name, nameAndInstrumentDL(name, instrumentation, dataLoader));
160160
return this;
161161
}
@@ -172,9 +172,6 @@ public DataLoaderRegistry register(DataLoader<?, ?> dataLoader) {
172172
* @return this registry
173173
*/
174174
public DataLoaderRegistry register(String key, DataLoader<?, ?> dataLoader) {
175-
if (strictMode) {
176-
assertKeyStrictly(key);
177-
}
178175
dataLoaders.put(key, nameAndInstrumentDL(key, instrumentation, dataLoader));
179176
return this;
180177
}
@@ -191,9 +188,6 @@ public DataLoaderRegistry register(String key, DataLoader<?, ?> dataLoader) {
191188
* @return the data loader instance that was registered
192189
*/
193190
public <K, V> DataLoader<K, V> registerAndGet(String key, DataLoader<?, ?> dataLoader) {
194-
if (strictMode) {
195-
assertKeyStrictly(key);
196-
}
197191
dataLoaders.put(key, nameAndInstrumentDL(key, instrumentation, dataLoader));
198192
return Objects.requireNonNull(getDataLoader(key));
199193
}

0 commit comments

Comments
 (0)