diff --git a/mutters-core/src/main/java/com/rabidgremlin/mutters/core/session/Session.java b/mutters-core/src/main/java/com/rabidgremlin/mutters/core/session/Session.java index eb7fa3de..98bf08f8 100644 --- a/mutters-core/src/main/java/com/rabidgremlin/mutters/core/session/Session.java +++ b/mutters-core/src/main/java/com/rabidgremlin/mutters/core/session/Session.java @@ -3,6 +3,7 @@ import java.io.Serializable; import java.util.HashMap; +import java.util.Set; /** * This class represents a user's session with the bot. It maintains the any @@ -108,6 +109,26 @@ public void resetAll() longTermAttributes = new HashMap<>(); } + /** + * Returns the set of all attribute keys. + * + * @return Set of attribute keys. + */ + public Set getAttributeKeys() + { + return attributes.keySet(); + } + + /** + * Returns the set of all long term attribute keys. + * + * @return Set of long term attribute keys. + */ + public Set getLongTermAttributeKeys() + { + return longTermAttributes.keySet(); + } + /* * (non-Javadoc) * diff --git a/mutters-core/src/test/java/com/rabidgremlin/mutters/core/session/TestSession.java b/mutters-core/src/test/java/com/rabidgremlin/mutters/core/session/TestSession.java index a24a3556..534c728b 100644 --- a/mutters-core/src/test/java/com/rabidgremlin/mutters/core/session/TestSession.java +++ b/mutters-core/src/test/java/com/rabidgremlin/mutters/core/session/TestSession.java @@ -2,9 +2,12 @@ package com.rabidgremlin.mutters.core.session; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.nullValue; import static org.junit.Assert.assertThat; +import java.util.Set; + import org.junit.Test; public class TestSession @@ -60,4 +63,36 @@ public void testResetAll() assertThat(session.getLongTermAttribute("bob"), is(nullValue())); assertThat(session.getLongTermAttribute("bobLT"), is(nullValue())); } + + public void testGettingAttributeKeys() + { + Session session = new Session(); + session.setAttribute("bob", "alice"); + + // check attribute keys are as expected + Set attributeKeys = session.getAttributeKeys(); + assertThat(attributeKeys, is(not(nullValue()))); + assertThat(attributeKeys.size(), is(1)); + assertThat(attributeKeys.contains("bob"), is(true)); + + // make sure nothing has leaked into long term attributes + assertThat(session.getLongTermAttributeKeys(), is(not(nullValue()))); + assertThat(session.getLongTermAttributeKeys().size(), is(1)); + } + + public void testGettingLongTermAttributeKeys() + { + Session session = new Session(); + session.setLongTermAttribute("smith", "jones"); + + // check long term attribute keys are as expected + Set attributeKeys = session.getLongTermAttributeKeys(); + assertThat(attributeKeys, is(not(nullValue()))); + assertThat(attributeKeys.size(), is(1)); + assertThat(attributeKeys.contains("smith"), is(true)); + + // make sure nothing has leaked into long term attributes + assertThat(session.getAttributeKeys(), is(not(nullValue()))); + assertThat(session.getAttributeKeys().size(), is(1)); + } }