Skip to content

Commit

Permalink
Changed the exception's message. Added unit test.
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Kryukov <[email protected]>
  • Loading branch information
dk2k committed Sep 19, 2024
1 parent 34d23d1 commit 10a87e2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static <R extends Reader<?>> void registerReader(final byte ordinal, fina

public static void registerClassAlias(final Class<?> classInstance, final Class<?> classGeneric) {
if (WRITER_CUSTOM_CLASS_MAP.putIfAbsent(classInstance, classGeneric) != null) {
throw new IllegalArgumentException("Streamable custom class already registered [" + classInstance + "]");
throw new IllegalArgumentException("Streamable custom class already registered [" + classInstance.getName() + "]");
}
}

Expand All @@ -96,7 +96,7 @@ public static <W extends Writer<?>> W getWriter(final Class<?> clazz) {
}

/**
* Returns the ristered reader keyed by the unique ordinal
* Returns the registered reader keyed by the unique ordinal
*/
@SuppressWarnings("unchecked")
public static <R extends Reader<?>> R getReader(final byte b) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.opensearch.core.common.io.stream;

import org.junit.Assert;
import org.opensearch.test.OpenSearchTestCase;

import java.util.concurrent.atomic.AtomicInteger;

public class WriteableTests extends OpenSearchTestCase {

public void testRegisterClassAlias() {
Writeable.WriteableRegistry.registerClassAlias(StringBuilder.class, AtomicInteger.class);
try {
Writeable.WriteableRegistry.registerClassAlias(StringBuilder.class, AtomicInteger.class);
Assert.fail("expected exception not thrown");
} catch (IllegalArgumentException illegalArgumentException) {
Assert.assertEquals("Streamable custom class already registered [java.lang.StringBuilder]", illegalArgumentException.getMessage());
}
}
}

0 comments on commit 10a87e2

Please sign in to comment.