Skip to content

Commit

Permalink
Added ability to get attribute keys from session.
Browse files Browse the repository at this point in the history
  • Loading branch information
rabidgremlin committed Apr 16, 2020
1 parent 72bed6d commit 5fc1359
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -108,6 +109,26 @@ public void resetAll()
longTermAttributes = new HashMap<>();
}

/**
* Returns the set of all attribute keys.
*
* @return Set of attribute keys.
*/
public Set<String> getAttributeKeys()
{
return attributes.keySet();
}

/**
* Returns the set of all long term attribute keys.
*
* @return Set of long term attribute keys.
*/
public Set<String> getLongTermAttributeKeys()
{
return longTermAttributes.keySet();
}

/*
* (non-Javadoc)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String> 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<String> 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));
}
}

0 comments on commit 5fc1359

Please sign in to comment.