From 97037a89c898d513e4352a94000dcbc08ecb8e87 Mon Sep 17 00:00:00 2001 From: Mattias Arthursson Date: Thu, 1 Mar 2007 18:46:30 +0000 Subject: [PATCH] Unit test for ThreadLocalAuthenticationSource --- .../ThreadLocalAuthenticationSourceTest.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 sandbox/src/test/java/org/springframework/ldap/authentication/ThreadLocalAuthenticationSourceTest.java diff --git a/sandbox/src/test/java/org/springframework/ldap/authentication/ThreadLocalAuthenticationSourceTest.java b/sandbox/src/test/java/org/springframework/ldap/authentication/ThreadLocalAuthenticationSourceTest.java new file mode 100644 index 00000000..ab092983 --- /dev/null +++ b/sandbox/src/test/java/org/springframework/ldap/authentication/ThreadLocalAuthenticationSourceTest.java @@ -0,0 +1,41 @@ +package org.springframework.ldap.authentication; + +import junit.framework.TestCase; + +public class ThreadLocalAuthenticationSourceTest extends TestCase { + + private ThreadLocalAuthenticationSource tested; + + protected void setUp() throws Exception { + ThreadLocalAuthenticationHolder.setPrincipal(null); + ThreadLocalAuthenticationHolder.setCredentials(null); + + tested = new ThreadLocalAuthenticationSource(); + } + + public void testGetPrincipal() { + ThreadLocalAuthenticationHolder.setPrincipal("cn=john doe"); + String result = tested.getPrincipal(); + + assertEquals("cn=john doe", result); + } + + public void testGetPrincipal_NoDataBound() { + String result = tested.getPrincipal(); + + assertNull("Should be null", result); + } + + public void testGetCredentials() { + ThreadLocalAuthenticationHolder.setCredentials("secret"); + String result = tested.getCredentials(); + + assertEquals("secret", result); + } + + public void testGetCredentials_NoDataBound() { + String result = tested.getCredentials(); + + assertNull("Should be null", result); + } +}