BenjaminPerryRoss commented on a change in pull request #7405: URL: https://github.com/apache/geode/pull/7405#discussion_r817033858
########## File path: extensions/geode-modules-test/src/main/java/org/apache/geode/modules/session/catalina/AbstractDeltaSessionIntegrationTest.java ########## @@ -107,4 +115,79 @@ public void serializedAttributesNotLeakedWhenSessionInvalidated() throws IOExcep verifyNoMoreInteractions(listener); assertThat(event.getValue().getValue()).isEqualTo(value1); } + + @Test + public void setNewAttributeWithNullValueInvokesRemove() { + final HttpSessionAttributeListener listener = mock(HttpSessionAttributeListener.class); + when(context.getApplicationEventListeners()).thenReturn(new Object[] {listener}); + when(manager.isBackingCacheAvailable()).thenReturn(true); + + final DeltaSessionT session = spy(newSession(manager)); + session.setId(KEY, false); + session.setValid(true); + session.setOwner(manager); + + final String name = "attribute"; + final Object nullValue = null; + + session.setAttribute(name, nullValue); + assertThat(session.getAttributes().size()).isEqualTo(0); + + // Mockito.inOrder + verify(session).queueAttributeEvent(any(DeltaSessionDestroyAttributeEvent.class), anyBoolean()); + verify(session, times(0)).queueAttributeEvent(any(DeltaSessionUpdateAttributeEvent.class), + anyBoolean()); + verify(session).removeAttribute(eq(name)); + } + + @Test + public void setExistingAttributeWithNullValueInvokesRemove() { + final HttpSessionAttributeListener listener = mock(HttpSessionAttributeListener.class); + when(context.getApplicationEventListeners()).thenReturn(new Object[] {listener}); + when(manager.isBackingCacheAvailable()).thenReturn(true); + + final DeltaSessionT session = spy(newSession(manager)); + session.setId(KEY, false); + session.setValid(true); + session.setOwner(manager); + + final String name = "attribute"; + final Object value = "value"; + final Object nullValue = null; + + session.setAttribute(name, value); + assertThat(session.getAttributes().size()).isEqualTo(1); + + session.setAttribute(name, nullValue); + assertThat(session.getAttributes().size()).isEqualTo(0); + + + InOrder inOrder = Mockito.inOrder(session); + inOrder.verify(session).queueAttributeEvent(any(DeltaSessionUpdateAttributeEvent.class), + anyBoolean()); + inOrder.verify(session).removeAttribute(eq(name)); + inOrder.verify(session).queueAttributeEvent(any(DeltaSessionDestroyAttributeEvent.class), + anyBoolean()); + } + + @Test + public void getAttributeWithNullValueReturnsNull() throws IOException, ClassNotFoundException { Review comment: I wrote up a test case for null name and it still returned null in all the cases I tried. Still just in case there are situations where it might not (not sure if maybe specific states of the underlying region could cause this to have different behavior or not) I went ahead and added an if(name == null) check at the beginning of the getAttribute method to ensure that this case will always return null. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@geode.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org