From 390fca17dbff49e7030ed4f86c91fa277fa8af78 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Thu, 19 May 2016 17:53:54 -0400 Subject: [PATCH] Add test for invalid context names Signed-off-by: Alexandre Montplaisir --- .../agent/context/ContextRegistrationIT.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/lttng-ust-java-tests-common/src/test/java/org/lttng/ust/agent/context/ContextRegistrationIT.java b/lttng-ust-java-tests-common/src/test/java/org/lttng/ust/agent/context/ContextRegistrationIT.java index 8455374..10327b0 100644 --- a/lttng-ust-java-tests-common/src/test/java/org/lttng/ust/agent/context/ContextRegistrationIT.java +++ b/lttng-ust-java-tests-common/src/test/java/org/lttng/ust/agent/context/ContextRegistrationIT.java @@ -19,6 +19,9 @@ package org.lttng.ust.agent.context; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.IOException; @@ -55,14 +58,32 @@ public class ContextRegistrationIT { */ @Test public void testRegistration() { - final String retrieverName = "test-retriever"; + final String retrieverName = "test.retriever"; final IContextInfoRetriever emptyRetriever = (key -> null); - mgr.registerContextInfoRetriever(retrieverName, emptyRetriever); + boolean ret = mgr.registerContextInfoRetriever(retrieverName, emptyRetriever); + assertTrue(ret); IContextInfoRetriever retriever2 = mgr.getContextInfoRetriever(retrieverName); assertEquals(emptyRetriever, retriever2); mgr.unregisterContextInfoRetriever(retrieverName); } + + /** + * Test registration of retrievers with invalid names. + */ + @Test + public void testRegistrationInvalid() { + String[] invalidNames = new String[] { "test.rétriever", "with space", "1numberfirst" }; + for (String retrieverName : invalidNames) { + final IContextInfoRetriever emptyRetriever = (key -> null); + + boolean ret = mgr.registerContextInfoRetriever(retrieverName, emptyRetriever); + assertFalse(ret); + + IContextInfoRetriever retriever = mgr.getContextInfoRetriever(retrieverName); + assertNull(retriever); + } + } } -- 2.34.1