public void testAppropriateSessionState() {
StanzaBuilder stanzaBuilder = new StanzaBuilder("starttls", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_TLS);
Stanza starttlsStanza = stanzaBuilder.build();
TestSessionContext sessionContext = this.sessionContext;
sessionContext.setServerToServer();
sessionContext.setSessionState(SessionState.INITIATED);
Stanza responseStanza = executeStartTLSHandler(starttlsStanza, sessionContext);
XMLElementVerifier verifier = responseStanza.getVerifier();
assertTrue("session state to low failure", verifier.nameEquals("failure"));
assertFalse("tls init", sessionContext.isSwitchToTLSCalled());
sessionContext.setSessionState(SessionState.ENCRYPTION_STARTED);
responseStanza = executeStartTLSHandler(starttlsStanza, sessionContext);
verifier = responseStanza.getVerifier();
assertTrue("session state too high failure", verifier.nameEquals("failure"));
assertFalse("tls init", sessionContext.isSwitchToTLSCalled());
sessionContext.setSessionState(SessionState.STARTED);
responseStanza = executeStartTLSHandler(starttlsStanza, sessionContext);
verifier = responseStanza.getVerifier();
assertTrue("session state ready", verifier.nameEquals("proceed"));
assertEquals("session stat is encryption started", SessionState.ENCRYPTION_STARTED, sessionStateHolder.getState());
assertTrue("tls init", sessionContext.isSwitchToTLSCalled());
}