diff --git a/core-tiger/build.gradle b/core-tiger/build.gradle index ee4c24d0..98a7dfa9 100644 --- a/core-tiger/build.gradle +++ b/core-tiger/build.gradle @@ -4,5 +4,6 @@ dependencies { "org.springframework:spring-tx:$springVersion" testCompile "junit:junit:$junitVersion", - "org.easymock:easymock:2.5.1" -} \ No newline at end of file + "org.easymock:easymock:2.5.1", + "org.assertj:assertj-core:$assertjVersion" +} diff --git a/core-tiger/src/test/java/org/springframework/ldap/core/simple/ContextMapperCallbackHandlerWithControlsTest.java b/core-tiger/src/test/java/org/springframework/ldap/core/simple/ContextMapperCallbackHandlerWithControlsTest.java index 109131af..e0ce7c70 100644 --- a/core-tiger/src/test/java/org/springframework/ldap/core/simple/ContextMapperCallbackHandlerWithControlsTest.java +++ b/core-tiger/src/test/java/org/springframework/ldap/core/simple/ContextMapperCallbackHandlerWithControlsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,12 +28,12 @@ import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Unit tests for the {@link ContextMapperCallbackHandlerWithControlsTest} * class. - * + * * @author Ulrik Sandberg */ public class ContextMapperCallbackHandlerWithControlsTest { @@ -78,7 +78,7 @@ public class ContextMapperCallbackHandlerWithControlsTest { Object actualResult = tested.getObjectFromNameClassPair(expectedBinding); verify(mapperMock); - assertEquals(expectedResult, actualResult); + assertThat(actualResult).isEqualTo(expectedResult); } @Test @@ -93,7 +93,7 @@ public class ContextMapperCallbackHandlerWithControlsTest { Object actualResult = tested.getObjectFromNameClassPair(expectedBinding); verify(mapperMock); - assertEquals(expectedResult, actualResult); + assertThat(actualResult).isEqualTo(expectedResult); } @Test(expected = ObjectRetrievalException.class) diff --git a/core/build.gradle b/core/build.gradle index 2ffaddfe..b0a947e6 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -30,5 +30,6 @@ dependencies { "org.mockito:mockito-core:$mockitoVersion", "org.slf4j:slf4j-log4j12:$slf4jVersion", "org.springframework:spring-test:$springVersion", + "org.assertj:assertj-core:$assertjVersion", powerMockDependencies -} \ No newline at end of file +} diff --git a/core/src/itest-openldap/java/org/springframework/ldap/LdapTemplateLookupOpenLdapITest.java b/core/src/itest-openldap/java/org/springframework/ldap/LdapTemplateLookupOpenLdapITest.java index 47dd1da4..9af1eed4 100644 --- a/core/src/itest-openldap/java/org/springframework/ldap/LdapTemplateLookupOpenLdapITest.java +++ b/core/src/itest-openldap/java/org/springframework/ldap/LdapTemplateLookupOpenLdapITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,8 +49,8 @@ public class LdapTemplateLookupOpenLdapITest extends DirContextAdapter result = (DirContextAdapter) tested .lookup("cn=Some Person2, ou=company1,c=Sweden"); - assertEquals("Some Person2", result.getStringAttribute("cn")); - assertEquals("Person2", result.getStringAttribute("sn")); + assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person2"); + assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); assertEquals("Sweden, Company1, Some Person2", result .getStringAttribute("description")); } @@ -60,9 +60,9 @@ public class LdapTemplateLookupOpenLdapITest extends Person person = (Person) tested.lookup( "cn=Some Person2, ou=company1,c=Sweden", mapper); - assertEquals("Some Person2", person.getFullname()); - assertEquals("Person2", person.getLastname()); - assertEquals("Sweden, Company1, Some Person2", person.getDescription()); + assertThat(person.getFullname()).isEqualTo("Some Person2"); + assertThat(person.getLastname()).isEqualTo("Person2"); + assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2"); } public void testLookup_AttributesMapper_DistinguishedName() { @@ -70,9 +70,9 @@ public class LdapTemplateLookupOpenLdapITest extends Person person = (Person) tested.lookup(new DistinguishedName( "cn=Some Person2, ou=company1,c=Sweden"), mapper); - assertEquals("Some Person2", person.getFullname()); - assertEquals("Person2", person.getLastname()); - assertEquals("Sweden, Company1, Some Person2", person.getDescription()); + assertThat(person.getFullname()).isEqualTo("Some Person2"); + assertThat(person.getLastname()).isEqualTo("Person2"); + assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2"); } /** @@ -94,7 +94,7 @@ public class LdapTemplateLookupOpenLdapITest extends throws NamingException { Person person = new Person(); person.setFullname((String) attributes.get("cn").get()); - assertNull("sn should be null", attributes.get("sn")); + assertThat(attributes.get("sn")).as("sn should be null").isNull(); assertNull("description should be null", attributes .get("description")); return person; @@ -112,9 +112,9 @@ public class LdapTemplateLookupOpenLdapITest extends "cn=Some Person2, ou=company1,c=Sweden", new String[] { "cn" }, mapper); - assertEquals("Some Person2", person.getFullname()); - assertNull("lastName should not be set", person.getLastname()); - assertNull("description should not be set", person.getDescription()); + assertThat(person.getFullname()).isEqualTo("Some Person2"); + assertThat(person.getLastname()).as("lastName should not be set").isNull(); + assertThat(person.getDescription()).as("description should not be set").isNull(); } /** @@ -128,9 +128,9 @@ public class LdapTemplateLookupOpenLdapITest extends "cn=Some Person2, ou=company1,c=Sweden"), new String[] { "cn" }, mapper); - assertEquals("Some Person2", person.getFullname()); - assertNull("lastName should not be set", person.getLastname()); - assertNull("description should not be set", person.getDescription()); + assertThat(person.getFullname()).isEqualTo("Some Person2"); + assertThat(person.getLastname()).as("lastName should not be set").isNull(); + assertThat(person.getDescription()).as("description should not be set").isNull(); } /** @@ -142,9 +142,9 @@ public class LdapTemplateLookupOpenLdapITest extends Person person = (Person) tested.lookup( "cn=Some Person2, ou=company1,c=Sweden", mapper); - assertEquals("Some Person2", person.getFullname()); - assertEquals("Person2", person.getLastname()); - assertEquals("Sweden, Company1, Some Person2", person.getDescription()); + assertThat(person.getFullname()).isEqualTo("Some Person2"); + assertThat(person.getLastname()).isEqualTo("Person2"); + assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2"); } /** @@ -158,9 +158,9 @@ public class LdapTemplateLookupOpenLdapITest extends "cn=Some Person2, ou=company1,c=Sweden", new String[] { "cn" }, mapper); - assertEquals("Some Person2", person.getFullname()); - assertNull("lastName should not be set", person.getLastname()); - assertNull("description should not be set", person.getDescription()); + assertThat(person.getFullname()).isEqualTo("Some Person2"); + assertThat(person.getLastname()).as("lastName should not be set").isNull(); + assertThat(person.getDescription()).as("description should not be set").isNull(); } /** @@ -172,8 +172,8 @@ public class LdapTemplateLookupOpenLdapITest extends Person person = (Person) tested.lookup( "cn=Some Person+sn=Person, ou=company1,c=Norway", mapper); - assertEquals("Some Person", person.getFullname()); - assertEquals("Person", person.getLastname()); + assertThat(person.getFullname()).isEqualTo("Some Person"); + assertThat(person.getLastname()).isEqualTo("Person"); assertEquals("Norway, Company1, Some Person+Person", person .getDescription()); } @@ -186,8 +186,8 @@ public class LdapTemplateLookupOpenLdapITest extends DirContextAdapter result = (DirContextAdapter) tested .lookup("cn=Some Person+sn=Person, ou=company1,c=Norway"); - assertEquals("Some Person", result.getStringAttribute("cn")); - assertEquals("Person", result.getStringAttribute("sn")); + assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person"); + assertThat(result.getStringAttribute("sn")).isEqualTo("Person"); assertEquals("Norway, Company1, Some Person+Person", result .getStringAttribute("description")); } @@ -196,7 +196,7 @@ public class LdapTemplateLookupOpenLdapITest extends DirContextAdapter result = (DirContextAdapter) tested .lookup("cn=Some Person2, ou=company1,c=Sweden"); - assertEquals("cn=Some Person2, ou=company1, c=Sweden", result.getDn() + assertThat(result.getDn().isEqualTo("cn=Some Person2, ou=company1, c=Sweden") .toString()); assertEquals( "cn=Some Person2, ou=company1, c=Sweden, dc=jayway, dc=se", diff --git a/core/src/itest-openldap/java/org/springframework/ldap/control/LdapTemplatePagedSearchITest.java b/core/src/itest-openldap/java/org/springframework/ldap/control/LdapTemplatePagedSearchITest.java index 54ae24da..f8b66ac3 100644 --- a/core/src/itest-openldap/java/org/springframework/ldap/control/LdapTemplatePagedSearchITest.java +++ b/core/src/itest-openldap/java/org/springframework/ldap/control/LdapTemplatePagedSearchITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -90,31 +90,31 @@ public class LdapTemplatePagedSearchITest extends requestControl = new PagedResultsRequestControl(3); tested.search(searchExecutor, callbackHandler, requestControl); cookie = requestControl.getCookie(); - assertNotNull("Cookie should not be null yet", cookie.getCookie()); + assertThat(cookie.getCookie()).as("Cookie should not be null yet").isNotNull(); list = callbackHandler.getList(); - assertEquals(3, list.size()); + assertThat(list).hasSize(3); person = (Person) list.get(0); - assertEquals("Some Person", person.getFullname()); - assertEquals("+46 555-123456", person.getPhone()); + assertThat(person.getFullname()).isEqualTo("Some Person"); + assertThat(person.getPhone()).isEqualTo("+46 555-123456"); person = (Person) list.get(1); - assertEquals("Some Person2", person.getFullname()); - assertEquals("+46 555-654321", person.getPhone()); + assertThat(person.getFullname()).isEqualTo("Some Person2"); + assertThat(person.getPhone()).isEqualTo("+46 555-654321"); person = (Person) list.get(2); - assertEquals("Some Person3", person.getFullname()); - assertEquals("+46 555-123654", person.getPhone()); + assertThat(person.getFullname()).isEqualTo("Some Person3"); + assertThat(person.getPhone()).isEqualTo("+46 555-123654"); // Prepare for second and last search requestControl = new PagedResultsRequestControl(3, cookie); tested.search(searchExecutor, callbackHandler, requestControl); cookie = requestControl.getCookie(); - assertNull("Cookie should be null now", cookie.getCookie()); - assertEquals(5, list.size()); + assertThat(cookie.getCookie()).as("Cookie should be null now").isNull(); + assertThat(list).hasSize(5); person = (Person) list.get(3); - assertEquals("Some Person", person.getFullname()); - assertEquals("+46 555-456321", person.getPhone()); + assertThat(person.getFullname()).isEqualTo("Some Person"); + assertThat(person.getPhone()).isEqualTo("+46 555-456321"); person = (Person) list.get(4); - assertEquals("Some Person", person.getFullname()); - assertEquals("+45 555-654123", person.getPhone()); + assertThat(person.getFullname()).isEqualTo("Some Person"); + assertThat(person.getPhone()).isEqualTo("+45 555-654123"); } public void testSearch_PagedResult_ConvenienceMethod() { @@ -128,27 +128,27 @@ public class LdapTemplatePagedSearchITest extends tested.search(BASE, FILTER_STRING, searchControls, callbackHandler, requestControl); cookie = requestControl.getCookie(); - assertNotNull("Cookie should not be null yet", cookie.getCookie()); + assertThat(cookie.getCookie()).as("Cookie should not be null yet").isNotNull(); list = callbackHandler.getList(); - assertEquals(3, list.size()); + assertThat(list).hasSize(3); person = (Person) list.get(0); - assertEquals("Some Person", person.getFullname()); + assertThat(person.getFullname()).isEqualTo("Some Person"); person = (Person) list.get(1); - assertEquals("Some Person2", person.getFullname()); + assertThat(person.getFullname()).isEqualTo("Some Person2"); person = (Person) list.get(2); - assertEquals("Some Person3", person.getFullname()); + assertThat(person.getFullname()).isEqualTo("Some Person3"); // Prepare for second and last search requestControl = new PagedResultsRequestControl(3, cookie); tested.search(BASE, FILTER_STRING, searchControls, callbackHandler, requestControl); cookie = requestControl.getCookie(); - assertNull("Cookie should be null now", cookie.getCookie()); - assertEquals(5, list.size()); + assertThat(cookie.getCookie()).as("Cookie should be null now").isNull(); + assertThat(list).hasSize(5); person = (Person) list.get(3); - assertEquals("Some Person", person.getFullname()); + assertThat(person.getFullname()).isEqualTo("Some Person"); person = (Person) list.get(4); - assertEquals("Some Person", person.getFullname()); + assertThat(person.getFullname()).isEqualTo("Some Person"); } public void setTested(LdapTemplate tested) { diff --git a/core/src/itest-openldap/java/org/springframework/ldap/control/LdapTemplateSortedSearchITest.java b/core/src/itest-openldap/java/org/springframework/ldap/control/LdapTemplateSortedSearchITest.java index 4601abb5..a936cc0f 100644 --- a/core/src/itest-openldap/java/org/springframework/ldap/control/LdapTemplateSortedSearchITest.java +++ b/core/src/itest-openldap/java/org/springframework/ldap/control/LdapTemplateSortedSearchITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -84,7 +84,7 @@ public class LdapTemplateSortedSearchITest extends tested.search(searchExecutor, callbackHandler, requestControl); int resultCode = requestControl.getResultCode(); boolean sorted = requestControl.isSorted(); - assertTrue("Search result should have been sorted: " + resultCode, sorted); + assertThat("Search result should have been sorted: " + resultCode, sorted).isTrue(); List list = callbackHandler.getList(); assertSortedList(list); } @@ -98,26 +98,26 @@ public class LdapTemplateSortedSearchITest extends requestControl); int resultCode = requestControl.getResultCode(); boolean sorted = requestControl.isSorted(); - assertTrue("Search result should have been sorted: " + resultCode, sorted); + assertThat("Search result should have been sorted: " + resultCode, sorted).isTrue(); List list = callbackHandler.getList(); assertSortedList(list); } private void assertSortedList(List list) { Person person; - assertEquals(6, list.size()); + assertThat(list).hasSize(6); person = (Person) list.get(0); - assertEquals("Goran Milenkovic", person.getFullname()); + assertThat(person.getFullname()).isEqualTo("Goran Milenkovic"); person = (Person) list.get(1); - assertEquals("Goran Sundberg", person.getFullname()); + assertThat(person.getFullname()).isEqualTo("Goran Sundberg"); person = (Person) list.get(2); - assertEquals("Goran Westerberg", person.getFullname()); + assertThat(person.getFullname()).isEqualTo("Goran Westerberg"); person = (Person) list.get(3); - assertEquals("Gorana Milicevic", person.getFullname()); + assertThat(person.getFullname()).isEqualTo("Gorana Milicevic"); person = (Person) list.get(4); - assertEquals("Gordana Canic", person.getFullname()); + assertThat(person.getFullname()).isEqualTo("Gordana Canic"); person = (Person) list.get(5); - assertEquals("Gordana Russ", person.getFullname()); + assertThat(person.getFullname()).isEqualTo("Gordana Russ"); } public void setTested(LdapTemplate tested) { diff --git a/core/src/test/java/org/springframework/ldap/authentication/DefaultValuesAuthenticationSourceDecoratorTest.java b/core/src/test/java/org/springframework/ldap/authentication/DefaultValuesAuthenticationSourceDecoratorTest.java index 25ce8750..2b46fb56 100644 --- a/core/src/test/java/org/springframework/ldap/authentication/DefaultValuesAuthenticationSourceDecoratorTest.java +++ b/core/src/test/java/org/springframework/ldap/authentication/DefaultValuesAuthenticationSourceDecoratorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,8 @@ import org.junit.Before; import org.junit.Test; import org.springframework.ldap.core.AuthenticationSource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -49,7 +48,7 @@ public class DefaultValuesAuthenticationSourceDecoratorTest { when(authenticationSourceMock.getPrincipal()).thenReturn("cn=someUser"); String principal = tested.getPrincipal(); - assertEquals("cn=someUser", principal); + assertThat(principal).isEqualTo("cn=someUser"); } @Test @@ -58,7 +57,7 @@ public class DefaultValuesAuthenticationSourceDecoratorTest { String principal = tested.getPrincipal(); - assertEquals(DEFAULT_USER, principal); + assertThat(principal).isEqualTo(DEFAULT_USER); } @Test @@ -68,7 +67,7 @@ public class DefaultValuesAuthenticationSourceDecoratorTest { String credentials = tested.getCredentials(); - assertEquals("somepassword", credentials); + assertThat(credentials).isEqualTo("somepassword"); } @Test @@ -78,7 +77,7 @@ public class DefaultValuesAuthenticationSourceDecoratorTest { String credentials = tested.getCredentials(); - assertEquals(DEFAULT_PASSWORD, credentials); + assertThat(credentials).isEqualTo(DEFAULT_PASSWORD); } @Test @@ -88,7 +87,7 @@ public class DefaultValuesAuthenticationSourceDecoratorTest { tested.afterPropertiesSet(); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @@ -99,7 +98,7 @@ public class DefaultValuesAuthenticationSourceDecoratorTest { tested.afterPropertiesSet(); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @@ -110,7 +109,7 @@ public class DefaultValuesAuthenticationSourceDecoratorTest { tested.afterPropertiesSet(); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } } diff --git a/core/src/test/java/org/springframework/ldap/config/LdapTemplateNamespaceHandlerTest.java b/core/src/test/java/org/springframework/ldap/config/LdapTemplateNamespaceHandlerTest.java index 9b79541f..6ccdb1ff 100644 --- a/core/src/test/java/org/springframework/ldap/config/LdapTemplateNamespaceHandlerTest.java +++ b/core/src/test/java/org/springframework/ldap/config/LdapTemplateNamespaceHandlerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2015 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,11 +47,7 @@ import java.lang.management.ManagementFactory; import java.util.Set; import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.internal.util.reflection.Whitebox.getInternalState; /** @@ -65,26 +61,26 @@ public class LdapTemplateNamespaceHandlerTest { ContextSource outerContextSource = ctx.getBean(ContextSource.class); LdapTemplate ldapTemplate = ctx.getBean(LdapTemplate.class); - assertNotNull(outerContextSource); - assertNotNull(ldapTemplate); + assertThat(outerContextSource).isNotNull(); + assertThat(ldapTemplate).isNotNull(); - assertTrue(outerContextSource instanceof TransactionAwareContextSourceProxy); + assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue(); ContextSource contextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); - assertEquals(LdapUtils.emptyLdapName(), getInternalState(contextSource, "base")); - assertEquals("uid=admin", getInternalState(contextSource, "userDn")); - assertEquals("apassword", getInternalState(contextSource, "password")); - assertArrayEquals(new String[]{"ldap://localhost:389"}, (Object[]) getInternalState(contextSource, "urls")); - assertEquals(Boolean.FALSE, getInternalState(contextSource, "pooled")); - assertEquals(Boolean.FALSE, getInternalState(contextSource, "anonymousReadOnly")); - assertNull(getInternalState(contextSource, "referral")); + assertThat(LdapUtils.emptyLdapName()).isEqualTo(getInternalState(contextSource, "base")); + assertThat("uid=admin").isEqualTo(getInternalState(contextSource, "userDn")); + assertThat("apassword").isEqualTo(getInternalState(contextSource, "password")); + assertThat(new String[]{"ldap://localhost:389"}).isEqualTo((Object[]) getInternalState(contextSource, "urls")); + assertThat(Boolean.FALSE).isEqualTo(getInternalState(contextSource, "pooled")); + assertThat(Boolean.FALSE).isEqualTo(getInternalState(contextSource, "anonymousReadOnly")); + assertThat(getInternalState(contextSource, "referral")).isNull(); - assertSame(outerContextSource, getInternalState(ldapTemplate, "contextSource")); - assertEquals(Boolean.FALSE, getInternalState(ldapTemplate, "ignorePartialResultException")); - assertEquals(Boolean.FALSE, getInternalState(ldapTemplate, "ignoreNameNotFoundException")); - assertEquals(0, getInternalState(ldapTemplate, "defaultCountLimit")); - assertEquals(0, getInternalState(ldapTemplate, "defaultTimeLimit")); - assertEquals(SearchControls.SUBTREE_SCOPE, getInternalState(ldapTemplate, "defaultSearchScope")); + assertThat(outerContextSource).isSameAs(getInternalState(ldapTemplate, "contextSource")); + assertThat(Boolean.FALSE).isEqualTo(getInternalState(ldapTemplate, "ignorePartialResultException")); + assertThat(Boolean.FALSE).isEqualTo(getInternalState(ldapTemplate, "ignoreNameNotFoundException")); + assertThat(0).isEqualTo(getInternalState(ldapTemplate, "defaultCountLimit")); + assertThat(0).isEqualTo(getInternalState(ldapTemplate, "defaultTimeLimit")); + assertThat(SearchControls.SUBTREE_SCOPE).isEqualTo(getInternalState(ldapTemplate, "defaultSearchScope")); } @Test @@ -92,9 +88,9 @@ public class LdapTemplateNamespaceHandlerTest { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-anonymous-read-only.xml"); ContextSource contextSource = ctx.getBean(ContextSource.class); - assertNotNull(contextSource); - assertTrue(contextSource instanceof LdapContextSource); - assertEquals(Boolean.TRUE, getInternalState(contextSource, "anonymousReadOnly")); + assertThat(contextSource).isNotNull(); + assertThat(contextSource instanceof LdapContextSource).isTrue(); + assertThat(Boolean.TRUE).isEqualTo(getInternalState(contextSource, "anonymousReadOnly")); } @Test(expected = BeansException.class) @@ -120,14 +116,14 @@ public class LdapTemplateNamespaceHandlerTest { DirContextAuthenticationStrategy authenticationStrategy = ctx.getBean(DirContextAuthenticationStrategy.class); Object baseEnv = ctx.getBean("baseEnvProps"); - assertNotNull(outerContextSource); + assertThat(outerContextSource).isNotNull(); - assertTrue(outerContextSource instanceof TransactionAwareContextSourceProxy); + assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue(); ContextSource contextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); - assertSame(authenticationSource, getInternalState(contextSource, "authenticationSource")); - assertSame(authenticationStrategy, getInternalState(contextSource, "authenticationStrategy")); - assertEquals(baseEnv, getInternalState(contextSource, "baseEnv")); + assertThat(authenticationSource).isSameAs(getInternalState(contextSource, "authenticationSource")); + assertThat(authenticationStrategy).isSameAs(getInternalState(contextSource, "authenticationStrategy")); + assertThat(baseEnv).isEqualTo(getInternalState(contextSource, "baseEnv")); } @Test @@ -137,27 +133,27 @@ public class LdapTemplateNamespaceHandlerTest { LdapTemplate ldapTemplate = ctx.getBean(LdapTemplate.class); DirContextAuthenticationStrategy authenticationStrategy = ctx.getBean(DirContextAuthenticationStrategy.class); - assertNotNull(outerContextSource); - assertNotNull(ldapTemplate); + assertThat(outerContextSource).isNotNull(); + assertThat(ldapTemplate).isNotNull(); - assertTrue(outerContextSource instanceof TransactionAwareContextSourceProxy); + assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue(); ContextSource contextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); - assertEquals(LdapUtils.newLdapName("dc=261consulting,dc=com"), getInternalState(contextSource, "base")); - assertEquals("uid=admin", getInternalState(contextSource, "userDn")); - assertEquals("apassword", getInternalState(contextSource, "password")); - assertArrayEquals(new String[]{"ldap://localhost:389"}, (Object[]) getInternalState(contextSource, "urls")); - assertEquals(Boolean.TRUE, getInternalState(contextSource, "pooled")); - assertEquals(Boolean.FALSE, getInternalState(contextSource, "anonymousReadOnly")); - assertEquals("follow", getInternalState(contextSource, "referral")); - assertSame(authenticationStrategy, getInternalState(contextSource, "authenticationStrategy")); + assertThat(LdapUtils.newLdapName("dc=261consulting,dc=com")).isEqualTo(getInternalState(contextSource, "base")); + assertThat("uid=admin").isEqualTo(getInternalState(contextSource, "userDn")); + assertThat("apassword").isEqualTo(getInternalState(contextSource, "password")); + assertThat(new String[]{"ldap://localhost:389"}).isEqualTo((Object[]) getInternalState(contextSource, "urls")); + assertThat(Boolean.TRUE).isEqualTo(getInternalState(contextSource, "pooled")); + assertThat(Boolean.FALSE).isEqualTo(getInternalState(contextSource, "anonymousReadOnly")); + assertThat("follow").isEqualTo(getInternalState(contextSource, "referral")); + assertThat(authenticationStrategy).isSameAs(getInternalState(contextSource, "authenticationStrategy")); - assertSame(outerContextSource, getInternalState(ldapTemplate, "contextSource")); - assertEquals(Boolean.TRUE, getInternalState(ldapTemplate, "ignorePartialResultException")); - assertEquals(Boolean.TRUE, getInternalState(ldapTemplate, "ignoreNameNotFoundException")); - assertEquals(100, getInternalState(ldapTemplate, "defaultCountLimit")); - assertEquals(200, getInternalState(ldapTemplate, "defaultTimeLimit")); - assertEquals(SearchControls.OBJECT_SCOPE, getInternalState(ldapTemplate, "defaultSearchScope")); + assertThat(outerContextSource).isSameAs(getInternalState(ldapTemplate, "contextSource")); + assertThat(Boolean.TRUE).isEqualTo(getInternalState(ldapTemplate, "ignorePartialResultException")); + assertThat(Boolean.TRUE).isEqualTo(getInternalState(ldapTemplate, "ignoreNameNotFoundException")); + assertThat(100).isEqualTo(getInternalState(ldapTemplate, "defaultCountLimit")); + assertThat(200).isEqualTo(getInternalState(ldapTemplate, "defaultTimeLimit")); + assertThat(SearchControls.OBJECT_SCOPE).isEqualTo(getInternalState(ldapTemplate, "defaultSearchScope")); } @Test @@ -165,15 +161,15 @@ public class LdapTemplateNamespaceHandlerTest { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-spel.xml"); ContextSource outerContextSource = ctx.getBean(ContextSource.class); - assertNotNull(outerContextSource); + assertThat(outerContextSource).isNotNull(); - assertTrue(outerContextSource instanceof TransactionAwareContextSourceProxy); + assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue(); ContextSource contextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); - assertEquals(LdapUtils.newLdapName("dc=261consulting,dc=com"), getInternalState(contextSource, "base")); - assertEquals("uid=admin", getInternalState(contextSource, "userDn")); - assertEquals("apassword", getInternalState(contextSource, "password")); - assertArrayEquals(new String[]{"ldap://localhost:389"}, (Object[]) getInternalState(contextSource, "urls")); + assertThat(LdapUtils.newLdapName("dc=261consulting,dc=com")).isEqualTo(getInternalState(contextSource, "base")); + assertThat("uid=admin").isEqualTo(getInternalState(contextSource, "userDn")); + assertThat("apassword").isEqualTo(getInternalState(contextSource, "password")); + assertThat(new String[]{"ldap://localhost:389"}).isEqualTo((Object[]) getInternalState(contextSource, "urls")); } @@ -182,9 +178,9 @@ public class LdapTemplateNamespaceHandlerTest { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-spel-multiurls.xml"); ContextSource outerContextSource = ctx.getBean(ContextSource.class); - assertNotNull(outerContextSource); + assertThat(outerContextSource).isNotNull(); - assertTrue(outerContextSource instanceof TransactionAwareContextSourceProxy); + assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue(); ContextSource contextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); assertArrayEquals(new String[] { "ldap://a.localhost:389", "ldap://b.localhost:389" }, @@ -197,9 +193,9 @@ public class LdapTemplateNamespaceHandlerTest { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-multiurls.xml"); ContextSource outerContextSource = ctx.getBean(ContextSource.class); - assertNotNull(outerContextSource); + assertThat(outerContextSource).isNotNull(); - assertTrue(outerContextSource instanceof TransactionAwareContextSourceProxy); + assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue(); ContextSource contextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); assertArrayEquals(new String[] { "ldap://a.localhost:389", "ldap://b.localhost:389" }, @@ -214,21 +210,21 @@ public class LdapTemplateNamespaceHandlerTest { ContextSource outerContextSource = ctx.getBean(ContextSource.class); PlatformTransactionManager transactionManager = ctx.getBean(PlatformTransactionManager.class); - assertNotNull(outerContextSource); - assertNotNull(transactionManager); + assertThat(outerContextSource).isNotNull(); + assertThat(transactionManager).isNotNull(); - assertTrue(outerContextSource instanceof TransactionAwareContextSourceProxy); + assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue(); ContextSource contextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); - assertTrue(transactionManager instanceof ContextSourceTransactionManager); + assertThat(transactionManager instanceof ContextSourceTransactionManager).isTrue(); Object delegate = getInternalState(transactionManager, "delegate"); - assertSame(contextSource, getInternalState(delegate, "contextSource")); + assertThat(contextSource).isSameAs(getInternalState(delegate, "contextSource")); TempEntryRenamingStrategy renamingStrategy = (TempEntryRenamingStrategy) getInternalState(delegate, "renamingStrategy"); - assertTrue(renamingStrategy instanceof DefaultTempEntryRenamingStrategy); - assertEquals("_temp", getInternalState(renamingStrategy, "tempSuffix")); + assertThat(renamingStrategy instanceof DefaultTempEntryRenamingStrategy).isTrue(); + assertThat("_temp").isEqualTo(getInternalState(renamingStrategy, "tempSuffix")); } @Test @@ -236,7 +232,7 @@ public class LdapTemplateNamespaceHandlerTest { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-transactional-datasource.xml"); PlatformTransactionManager transactionManager = ctx.getBean(PlatformTransactionManager.class); - assertTrue(transactionManager instanceof ContextSourceAndDataSourceTransactionManager); + assertThat(transactionManager instanceof ContextSourceAndDataSourceTransactionManager).isTrue(); } @Test @@ -245,15 +241,15 @@ public class LdapTemplateNamespaceHandlerTest { PlatformTransactionManager transactionManager = ctx.getBean(PlatformTransactionManager.class); - assertNotNull(transactionManager); - assertTrue(transactionManager instanceof ContextSourceTransactionManager); + assertThat(transactionManager).isNotNull(); + assertThat(transactionManager instanceof ContextSourceTransactionManager).isTrue(); Object delegate = getInternalState(transactionManager, "delegate"); TempEntryRenamingStrategy renamingStrategy = (TempEntryRenamingStrategy) getInternalState(delegate, "renamingStrategy"); - assertTrue(renamingStrategy instanceof DefaultTempEntryRenamingStrategy); - assertEquals("_thisisthesuffix", getInternalState(renamingStrategy, "tempSuffix")); + assertThat(renamingStrategy instanceof DefaultTempEntryRenamingStrategy).isTrue(); + assertThat("_thisisthesuffix").isEqualTo(getInternalState(renamingStrategy, "tempSuffix")); } @Test @@ -262,15 +258,15 @@ public class LdapTemplateNamespaceHandlerTest { PlatformTransactionManager transactionManager = ctx.getBean(PlatformTransactionManager.class); - assertNotNull(transactionManager); - assertTrue(transactionManager instanceof ContextSourceTransactionManager); + assertThat(transactionManager).isNotNull(); + assertThat(transactionManager instanceof ContextSourceTransactionManager).isTrue(); Object delegate = getInternalState(transactionManager, "delegate"); TempEntryRenamingStrategy renamingStrategy = (TempEntryRenamingStrategy) getInternalState(delegate, "renamingStrategy"); - assertTrue(renamingStrategy instanceof DifferentSubtreeTempEntryRenamingStrategy); - assertEquals(LdapUtils.newLdapName("ou=temp"), getInternalState(renamingStrategy, "subtreeNode")); + assertThat(renamingStrategy instanceof DifferentSubtreeTempEntryRenamingStrategy).isTrue(); + assertThat(LdapUtils.newLdapName("ou=temp")).isEqualTo(getInternalState(renamingStrategy, "subtreeNode")); } @Test @@ -279,28 +275,28 @@ public class LdapTemplateNamespaceHandlerTest { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling-defaults.xml"); ContextSource outerContextSource = ctx.getBean(ContextSource.class); - assertNotNull(outerContextSource); - assertTrue(outerContextSource instanceof TransactionAwareContextSourceProxy); + assertThat(outerContextSource).isNotNull(); + assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue(); ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); - assertNotNull(pooledContextSource); - assertTrue(pooledContextSource instanceof PoolingContextSource); + assertThat(pooledContextSource).isNotNull(); + assertThat(pooledContextSource instanceof PoolingContextSource).isTrue(); Object objectFactory = getInternalState(pooledContextSource, "dirContextPoolableObjectFactory"); - assertNotNull(getInternalState(objectFactory, "contextSource")); - assertNull(getInternalState(objectFactory, "dirContextValidator")); + assertThat(getInternalState(objectFactory, "contextSource")).isNotNull(); + assertThat(getInternalState(objectFactory, "dirContextValidator")).isNull(); Set> nonTransientExceptions = (Set>) getInternalState(objectFactory, "nonTransientExceptions"); - assertEquals(1, nonTransientExceptions.size()); - assertTrue(nonTransientExceptions.contains(CommunicationException.class)); + assertThat(nonTransientExceptions).hasSize(1); + assertThat(nonTransientExceptions.contains(CommunicationException.class)).isTrue(); GenericKeyedObjectPool objectPool = (GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool"); - assertEquals(8, objectPool.getMaxActive()); - assertEquals(-1, objectPool.getMaxTotal()); - assertEquals(8, objectPool.getMaxIdle()); - assertEquals(-1, objectPool.getMaxWait()); - assertEquals(0, objectPool.getMinIdle()); - assertEquals(1, objectPool.getWhenExhaustedAction()); + assertThat(objectPool.getMaxActive()).isEqualTo(8); + assertThat(objectPool.getMaxTotal()).isEqualTo(-1); + assertThat(objectPool.getMaxIdle()).isEqualTo(8); + assertThat(objectPool.getMaxWait()).isEqualTo(-1); + assertThat(objectPool.getMinIdle()).isEqualTo(0); + assertThat(objectPool.getWhenExhaustedAction()).isEqualTo((byte)1); } @Test @@ -308,18 +304,18 @@ public class LdapTemplateNamespaceHandlerTest { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling-configured-poolsize.xml"); ContextSource outerContextSource = ctx.getBean(ContextSource.class); - assertNotNull(outerContextSource); + assertThat(outerContextSource).isNotNull(); ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); - assertNotNull(pooledContextSource); + assertThat(pooledContextSource).isNotNull(); GenericKeyedObjectPool objectPool = (GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool"); - assertEquals(10, objectPool.getMaxActive()); - assertEquals(12, objectPool.getMaxTotal()); - assertEquals(11, objectPool.getMaxIdle()); - assertEquals(13, objectPool.getMaxWait()); - assertEquals(14, objectPool.getMinIdle()); - assertEquals(0, objectPool.getWhenExhaustedAction()); + assertThat(objectPool.getMaxActive()).isEqualTo(10); + assertThat(objectPool.getMaxTotal()).isEqualTo(12); + assertThat(objectPool.getMaxIdle()).isEqualTo(11); + assertThat(objectPool.getMaxWait()).isEqualTo(13); + assertThat(objectPool.getMinIdle()).isEqualTo(14); + assertThat(objectPool.getWhenExhaustedAction()).isEqualTo((byte)0); } @Test @@ -328,30 +324,30 @@ public class LdapTemplateNamespaceHandlerTest { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling-test-specified.xml"); ContextSource outerContextSource = ctx.getBean(ContextSource.class); - assertNotNull(outerContextSource); + assertThat(outerContextSource).isNotNull(); ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); - assertNotNull(pooledContextSource); + assertThat(pooledContextSource).isNotNull(); GenericKeyedObjectPool objectPool = (GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool"); - assertEquals(123, objectPool.getMinEvictableIdleTimeMillis()); - assertEquals(321, objectPool.getTimeBetweenEvictionRunsMillis()); - assertEquals(22, objectPool.getNumTestsPerEvictionRun()); + assertThat(objectPool.getMinEvictableIdleTimeMillis()).isEqualTo(123); + assertThat(objectPool.getTimeBetweenEvictionRunsMillis()).isEqualTo(321); + assertThat(objectPool.getNumTestsPerEvictionRun()).isEqualTo(22); Object objectFactory = getInternalState(pooledContextSource, "dirContextPoolableObjectFactory"); DefaultDirContextValidator validator = (DefaultDirContextValidator) getInternalState(objectFactory, "dirContextValidator"); - assertEquals("ou=test", validator.getBase()); - assertEquals("objectclass=person", validator.getFilter()); + assertThat(validator.getBase()).isEqualTo("ou=test"); + assertThat(validator.getFilter()).isEqualTo("objectclass=person"); SearchControls searchControls = ctx.getBean(SearchControls.class); - assertEquals("objectclass=person", validator.getFilter()); - assertSame(searchControls, validator.getSearchControls()); + assertThat(validator.getFilter()).isEqualTo("objectclass=person"); + assertThat(validator.getSearchControls()).isSameAs(searchControls); Set> nonTransientExceptions = (Set>) getInternalState(objectFactory, "nonTransientExceptions"); - assertEquals(2, nonTransientExceptions.size()); - assertTrue(nonTransientExceptions.contains(CommunicationException.class)); - assertTrue(nonTransientExceptions.contains(CannotProceedException.class)); + assertThat(nonTransientExceptions).hasSize(2); + assertThat(nonTransientExceptions.contains(CommunicationException.class)).isTrue(); + assertThat(nonTransientExceptions.contains(CannotProceedException.class)).isTrue(); } @Test(expected = BeansException.class) @@ -364,7 +360,7 @@ public class LdapTemplateNamespaceHandlerTest { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-with-repositories.xml"); DummyLdapRepository repository = ctx.getBean(DummyLdapRepository.class); - assertNotNull(repository); + assertThat(repository).isNotNull(); } @Test @@ -372,48 +368,48 @@ public class LdapTemplateNamespaceHandlerTest { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling2-defaults.xml"); ContextSource outerContextSource = ctx.getBean(ContextSource.class); - assertNotNull(outerContextSource); - assertTrue(outerContextSource instanceof TransactionAwareContextSourceProxy); + assertThat(outerContextSource).isNotNull(); + assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue(); ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); - assertNotNull(pooledContextSource); - assertTrue(pooledContextSource instanceof PooledContextSource); - assertNotNull(getInternalState(pooledContextSource, "poolConfig")); + assertThat(pooledContextSource).isNotNull(); + assertThat(pooledContextSource instanceof PooledContextSource).isTrue(); + assertThat(getInternalState(pooledContextSource, "poolConfig")).isNotNull(); Object objectFactory = getInternalState(pooledContextSource, "dirContextPooledObjectFactory"); - assertNotNull(getInternalState(objectFactory, "contextSource")); - assertNull(getInternalState(objectFactory, "dirContextValidator")); + assertThat(getInternalState(objectFactory, "contextSource")).isNotNull(); + assertThat(getInternalState(objectFactory, "dirContextValidator")).isNull(); Set> nonTransientExceptions = (Set>) getInternalState(objectFactory, "nonTransientExceptions"); - assertEquals(1, nonTransientExceptions.size()); - assertTrue(nonTransientExceptions.contains(CommunicationException.class)); + assertThat(nonTransientExceptions).hasSize(1); + assertThat(nonTransientExceptions.contains(CommunicationException.class)).isTrue(); org.apache.commons.pool2.impl.GenericKeyedObjectPool objectPool = (org.apache.commons.pool2.impl.GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool"); - assertEquals(8, objectPool.getMaxIdlePerKey()); - assertEquals(-1, objectPool.getMaxTotal()); - assertEquals(8, objectPool.getMaxTotalPerKey()); - assertEquals(0, objectPool.getMinIdlePerKey()); - assertEquals(true, objectPool.getBlockWhenExhausted()); - assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_EVICTION_POLICY_CLASS_NAME, objectPool.getEvictionPolicyClassName()); - assertEquals(false, objectPool.getFairness()); + assertThat(objectPool.getMaxIdlePerKey()).isEqualTo(8); + assertThat(objectPool.getMaxTotal()).isEqualTo(-1); + assertThat(objectPool.getMaxTotalPerKey()).isEqualTo(8); + assertThat(objectPool.getMinIdlePerKey()).isEqualTo(0); + assertThat(objectPool.getBlockWhenExhausted()).isEqualTo(true); + assertThat(objectPool.getEvictionPolicyClassName()).isEqualTo(GenericKeyedObjectPoolConfig.DEFAULT_EVICTION_POLICY_CLASS_NAME); + assertThat(objectPool.getFairness()).isEqualTo(false); // ensures the pool is registered ObjectName oname = objectPool.getJmxName(); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); Set result = mbs.queryNames(oname, null); - assertEquals(1, result.size()); + assertThat(result).hasSize(1); - assertEquals(true, objectPool.getLifo()); - assertEquals(-1L, objectPool.getMaxWaitMillis()); - assertEquals(1000L*60L*30L, objectPool.getMinEvictableIdleTimeMillis()); - assertEquals(3, objectPool.getNumTestsPerEvictionRun()); - assertEquals(-1L, objectPool.getSoftMinEvictableIdleTimeMillis()); - assertEquals(-1L, objectPool.getTimeBetweenEvictionRunsMillis()); - assertEquals(false, objectPool.getTestOnBorrow()); - assertEquals(false, objectPool.getTestOnCreate()); - assertEquals(false, objectPool.getTestOnReturn()); - assertEquals(false, objectPool.getTestWhileIdle()); + assertThat(objectPool.getLifo()).isEqualTo(true); + assertThat(objectPool.getMaxWaitMillis()).isEqualTo(-1L); + assertThat(objectPool.getMinEvictableIdleTimeMillis()).isEqualTo(1000L*60L*30L); + assertThat(objectPool.getNumTestsPerEvictionRun()).isEqualTo(3); + assertThat(objectPool.getSoftMinEvictableIdleTimeMillis()).isEqualTo(-1L); + assertThat(objectPool.getTimeBetweenEvictionRunsMillis()).isEqualTo(-1L); + assertThat(objectPool.getTestOnBorrow()).isEqualTo(false); + assertThat(objectPool.getTestOnCreate()).isEqualTo(false); + assertThat(objectPool.getTestOnReturn()).isEqualTo(false); + assertThat(objectPool.getTestWhileIdle()).isEqualTo(false); } @Test @@ -421,29 +417,29 @@ public class LdapTemplateNamespaceHandlerTest { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pool2-configured-poolsize.xml"); ContextSource outerContextSource = ctx.getBean(ContextSource.class); - assertNotNull(outerContextSource); + assertThat(outerContextSource).isNotNull(); ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); - assertNotNull(pooledContextSource); + assertThat(pooledContextSource).isNotNull(); org.apache.commons.pool2.impl.GenericKeyedObjectPool objectPool = (org.apache.commons.pool2.impl.GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool"); - assertEquals(12, objectPool.getMaxTotal()); - assertEquals(20, objectPool.getMaxIdlePerKey()); - assertEquals(10, objectPool.getMaxTotalPerKey()); - assertEquals(13, objectPool.getMaxWaitMillis()); - assertEquals(14, objectPool.getMinIdlePerKey()); - assertEquals(true, objectPool.getBlockWhenExhausted()); - assertEquals("org.springframework.ldap.pool2.DummyEvictionPolicy", objectPool.getEvictionPolicyClassName()); - assertEquals(true, objectPool.getFairness()); - assertEquals(false, objectPool.getLifo()); + assertThat(objectPool.getMaxTotal()).isEqualTo(12); + assertThat(objectPool.getMaxIdlePerKey()).isEqualTo(20); + assertThat(objectPool.getMaxTotalPerKey()).isEqualTo(10); + assertThat(objectPool.getMaxWaitMillis()).isEqualTo(13); + assertThat(objectPool.getMinIdlePerKey()).isEqualTo(14); + assertThat(objectPool.getBlockWhenExhausted()).isEqualTo(true); + assertThat(objectPool.getEvictionPolicyClassName()).isEqualTo("org.springframework.ldap.pool2.DummyEvictionPolicy"); + assertThat(objectPool.getFairness()).isEqualTo(true); + assertThat(objectPool.getLifo()).isEqualTo(false); // ensures the pool is registered ObjectName oname = objectPool.getJmxName(); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); Set result = mbs.queryNames(oname, null); - assertEquals(1, result.size()); - assertEquals("org.springframework.ldap.pool2:type=ldap-pool,name=test-pool", oname.toString()); + assertThat(result).hasSize(1); + assertThat(oname.toString()).isEqualTo("org.springframework.ldap.pool2:type=ldap-pool,name=test-pool"); } @Test @@ -451,38 +447,38 @@ public class LdapTemplateNamespaceHandlerTest { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pool2-test-specified.xml"); ContextSource outerContextSource = ctx.getBean(ContextSource.class); - assertNotNull(outerContextSource); + assertThat(outerContextSource).isNotNull(); ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); - assertNotNull(pooledContextSource); + assertThat(pooledContextSource).isNotNull(); org.apache.commons.pool2.impl.GenericKeyedObjectPool objectPool = (org.apache.commons.pool2.impl.GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool"); - assertEquals(123, objectPool.getMinEvictableIdleTimeMillis()); - assertEquals(321, objectPool.getTimeBetweenEvictionRunsMillis()); - assertEquals(22, objectPool.getNumTestsPerEvictionRun()); - assertEquals(12, objectPool.getSoftMinEvictableIdleTimeMillis()); + assertThat(objectPool.getMinEvictableIdleTimeMillis()).isEqualTo(123); + assertThat(objectPool.getTimeBetweenEvictionRunsMillis()).isEqualTo(321); + assertThat(objectPool.getNumTestsPerEvictionRun()).isEqualTo(22); + assertThat(objectPool.getSoftMinEvictableIdleTimeMillis()).isEqualTo(12); - assertEquals(true, objectPool.getTestOnBorrow()); - assertEquals(true, objectPool.getTestOnReturn()); - assertEquals(true, objectPool.getTestOnCreate()); - assertEquals(true, objectPool.getTestWhileIdle()); + assertThat(objectPool.getTestOnBorrow()).isEqualTo(true); + assertThat(objectPool.getTestOnReturn()).isEqualTo(true); + assertThat(objectPool.getTestOnCreate()).isEqualTo(true); + assertThat(objectPool.getTestWhileIdle()).isEqualTo(true); Object objectFactory = getInternalState(pooledContextSource, "dirContextPooledObjectFactory"); org.springframework.ldap.pool2.validation.DefaultDirContextValidator validator = (org.springframework.ldap.pool2.validation.DefaultDirContextValidator) getInternalState(objectFactory, "dirContextValidator"); - assertEquals("ou=test", validator.getBase()); - assertEquals("objectclass=person", validator.getFilter()); + assertThat(validator.getBase()).isEqualTo("ou=test"); + assertThat(validator.getFilter()).isEqualTo("objectclass=person"); SearchControls searchControls = ctx.getBean(SearchControls.class); - assertEquals("objectclass=person", validator.getFilter()); - assertSame(searchControls, validator.getSearchControls()); + assertThat(validator.getFilter()).isEqualTo("objectclass=person"); + assertThat(validator.getSearchControls()).isSameAs(searchControls); Set> nonTransientExceptions = (Set>) getInternalState(objectFactory, "nonTransientExceptions"); - assertEquals(2, nonTransientExceptions.size()); - assertTrue(nonTransientExceptions.contains(CommunicationException.class)); - assertTrue(nonTransientExceptions.contains(CannotProceedException.class)); + assertThat(nonTransientExceptions).hasSize(2); + assertThat(nonTransientExceptions.contains(CommunicationException.class)).isTrue(); + assertThat(nonTransientExceptions.contains(CannotProceedException.class)).isTrue(); } @Test(expected = BeansException.class) @@ -499,40 +495,40 @@ public class LdapTemplateNamespaceHandlerTest { public void verifyParsePoolWithPlaceholders() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling-config-with-placeholders.xml"); ContextSource outerContextSource = ctx.getBean(ContextSource.class); - assertNotNull(outerContextSource); + assertThat(outerContextSource).isNotNull(); ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); - assertNotNull(pooledContextSource); + assertThat(pooledContextSource).isNotNull(); GenericKeyedObjectPool objectPool = (GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool"); - assertEquals(10, objectPool.getTimeBetweenEvictionRunsMillis()); - assertEquals(20, objectPool.getMinEvictableIdleTimeMillis()); - assertEquals(10, objectPool.getMaxWait()); - assertEquals(11, objectPool.getMaxTotal()); - assertEquals(15, objectPool.getMaxActive()); - assertEquals(16, objectPool.getMinIdle()); - assertEquals(17, objectPool.getMaxIdle()); - assertEquals(18, objectPool.getNumTestsPerEvictionRun()); + assertThat(objectPool.getTimeBetweenEvictionRunsMillis()).isEqualTo(10); + assertThat(objectPool.getMinEvictableIdleTimeMillis()).isEqualTo(20); + assertThat(objectPool.getMaxWait()).isEqualTo(10); + assertThat(objectPool.getMaxTotal()).isEqualTo(11); + assertThat(objectPool.getMaxActive()).isEqualTo(15); + assertThat(objectPool.getMinIdle()).isEqualTo(16); + assertThat(objectPool.getMaxIdle()).isEqualTo(17); + assertThat(objectPool.getNumTestsPerEvictionRun()).isEqualTo(18); } @Test public void verifyParsePool2WithPlaceholders() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling2-config-with-placeholders.xml"); ContextSource outerContextSource = ctx.getBean(ContextSource.class); - assertNotNull(outerContextSource); + assertThat(outerContextSource).isNotNull(); ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget(); - assertNotNull(pooledContextSource); + assertThat(pooledContextSource).isNotNull(); org.apache.commons.pool2.impl.GenericKeyedObjectPool objectPool = (org.apache.commons.pool2.impl.GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool"); - assertEquals(10, objectPool.getTimeBetweenEvictionRunsMillis()); - assertEquals(20, objectPool.getMinEvictableIdleTimeMillis()); - assertEquals(10, objectPool.getMaxWaitMillis()); - assertEquals(11, objectPool.getMaxTotal()); - assertEquals(12, objectPool.getMinIdlePerKey()); - assertEquals(13, objectPool.getMaxIdlePerKey()); - assertEquals(14, objectPool.getMaxTotalPerKey()); - assertEquals(18, objectPool.getNumTestsPerEvictionRun()); + assertThat(objectPool.getTimeBetweenEvictionRunsMillis()).isEqualTo(10); + assertThat(objectPool.getMinEvictableIdleTimeMillis()).isEqualTo(20); + assertThat(objectPool.getMaxWaitMillis()).isEqualTo(10); + assertThat(objectPool.getMaxTotal()).isEqualTo(11); + assertThat(objectPool.getMinIdlePerKey()).isEqualTo(12); + assertThat(objectPool.getMaxIdlePerKey()).isEqualTo(13); + assertThat(objectPool.getMaxTotalPerKey()).isEqualTo(14); + assertThat(objectPool.getNumTestsPerEvictionRun()).isEqualTo(18); } } diff --git a/core/src/test/java/org/springframework/ldap/control/PagedResultsDirContextProcessorTest.java b/core/src/test/java/org/springframework/ldap/control/PagedResultsDirContextProcessorTest.java index 273aa17b..fa89492d 100644 --- a/core/src/test/java/org/springframework/ldap/control/PagedResultsDirContextProcessorTest.java +++ b/core/src/test/java/org/springframework/ldap/control/PagedResultsDirContextProcessorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,9 +29,7 @@ import javax.naming.ldap.PagedResultsControl; import javax.naming.ldap.PagedResultsResponseControl; import java.io.IOException; -import static junit.framework.Assert.assertNull; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -61,7 +59,7 @@ public class PagedResultsDirContextProcessorTest { public void testCreateRequestControl() throws Exception { PagedResultsControl control = (PagedResultsControl) tested .createRequestControl(); - assertNotNull(control); + assertThat(control).isNotNull(); } @Test @@ -72,7 +70,7 @@ public class PagedResultsDirContextProcessorTest { PagedResultsControl control = (PagedResultsControl) tested .createRequestControl(); - assertNotNull(control); + assertThat(control).isNotNull(); } @Test @@ -90,9 +88,9 @@ public class PagedResultsDirContextProcessorTest { tested.postProcess(ldapContextMock); PagedResultsCookie returnedCookie = tested.getCookie(); - assertEquals(8, returnedCookie.getCookie()[0]); - assertEquals(20, tested.getPageSize()); - assertEquals(50, tested.getResultSize()); + assertThat(returnedCookie.getCookie()[0]).isEqualTo((byte)8); + assertThat(tested.getPageSize()).isEqualTo(20); + assertThat(tested.getResultSize()).isEqualTo(50); } @Test @@ -112,9 +110,9 @@ public class PagedResultsDirContextProcessorTest { when(ldapContextMock.getResponseControls()).thenReturn(new Control[]{control}); tested.postProcess(ldapContextMock); - assertNull(tested.getCookie()); - assertEquals(20, tested.getPageSize()); - assertEquals(0, tested.getResultSize()); + assertThat(tested.getCookie()).isNull(); + assertThat(tested.getPageSize()).isEqualTo(20); + assertThat(tested.getResultSize()).isEqualTo(0); } @Test @@ -123,9 +121,9 @@ public class PagedResultsDirContextProcessorTest { tested.postProcess(ldapContextMock); - assertNull(tested.getCookie()); - assertEquals(20, tested.getPageSize()); - assertEquals(0, tested.getResultSize()); + assertThat(tested.getCookie()).isNull(); + assertThat(tested.getPageSize()).isEqualTo(20); + assertThat(tested.getResultSize()).isEqualTo(0); } @Test @@ -141,10 +139,10 @@ public class PagedResultsDirContextProcessorTest { int actualPageSize = ber.parseInt(); byte[] actualValue = ber.parseOctetString(Ber.ASN_OCTET_STR, null); - assertEquals("pageSize,", 20, actualPageSize); - assertEquals("value length", value.length, actualValue.length); + assertThat(actualPageSize).as("pageSize,").isEqualTo(20); + assertThat(actualValue.length).as("value length").isEqualTo(value.length); for (int i = 0; i < value.length; i++) { - assertEquals("value (index " + i + "),", value[i], actualValue[i]); + assertThat(actualValue[i]).as("value (index " + i + "),").isEqualTo(value[i]); } } diff --git a/core/src/test/java/org/springframework/ldap/control/SortControlDirContextProcessorTest.java b/core/src/test/java/org/springframework/ldap/control/SortControlDirContextProcessorTest.java index 96255e56..2fe3d1e7 100644 --- a/core/src/test/java/org/springframework/ldap/control/SortControlDirContextProcessorTest.java +++ b/core/src/test/java/org/springframework/ldap/control/SortControlDirContextProcessorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,7 @@ import javax.naming.ldap.SortControl; import javax.naming.ldap.SortResponseControl; import java.io.IOException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -55,9 +54,9 @@ public class SortControlDirContextProcessorTest { @Test public void testCreateRequestControl() throws Exception { SortControl result = (SortControl) tested.createRequestControl(); - assertNotNull(result); - assertEquals("1.2.840.113556.1.4.473", result.getID()); - assertEquals(9, result.getEncodedValue().length); + assertThat(result).isNotNull(); + assertThat(result.getID()).isEqualTo("1.2.840.113556.1.4.473"); + assertThat(result.getEncodedValue().length).isEqualTo(9); } @Test @@ -72,8 +71,8 @@ public class SortControlDirContextProcessorTest { tested.postProcess(ldapContextMock); - assertEquals(true, tested.isSorted()); - assertEquals(0, tested.getResultCode()); + assertThat(tested.isSorted()).isEqualTo(true); + assertThat(tested.getResultCode()).isEqualTo(0); } @Test @@ -88,8 +87,8 @@ public class SortControlDirContextProcessorTest { tested.postProcess(ldapContextMock); - assertEquals(false, tested.isSorted()); - assertEquals(1, tested.getResultCode()); + assertThat(tested.isSorted()).isEqualTo(false); + assertThat(tested.getResultCode()).isEqualTo(1); } @Test @@ -109,7 +108,7 @@ public class SortControlDirContextProcessorTest { tested.postProcess(ldapContextMock); - assertEquals(false, tested.isSorted()); + assertThat(tested.isSorted()).isEqualTo(false); } @Test @@ -122,7 +121,7 @@ public class SortControlDirContextProcessorTest { ber.parseSeq(null); int actualSortResult = ber.parseEnumeration(); - assertEquals("sortResult,", 53, actualSortResult); + assertThat(actualSortResult).as("sortResult,").isEqualTo(53); } private byte[] encodeValue(int sortResult) throws IOException { diff --git a/core/src/test/java/org/springframework/ldap/core/CollectingNameClassPairCallbackHandlerTest.java b/core/src/test/java/org/springframework/ldap/core/CollectingNameClassPairCallbackHandlerTest.java index 499d1068..323c5632 100644 --- a/core/src/test/java/org/springframework/ldap/core/CollectingNameClassPairCallbackHandlerTest.java +++ b/core/src/test/java/org/springframework/ldap/core/CollectingNameClassPairCallbackHandlerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import javax.naming.NameClassPair; import javax.naming.NamingException; import java.util.List; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertSame; public class CollectingNameClassPairCallbackHandlerTest { @@ -40,7 +40,7 @@ public class CollectingNameClassPairCallbackHandlerTest { expectedNameClassPair = new NameClassPair(null, null); tested = new CollectingNameClassPairCallbackHandler() { public Object getObjectFromNameClassPair(NameClassPair nameClassPair) { - assertSame(expectedNameClassPair, nameClassPair); + assertThat(nameClassPair).isSameAs(expectedNameClassPair); return expectedResult; } }; @@ -50,8 +50,8 @@ public class CollectingNameClassPairCallbackHandlerTest { public void testHandleNameClassPair() throws NamingException { tested.handleNameClassPair(expectedNameClassPair); List result = tested.getList(); - assertEquals(1, result.size()); - assertSame(expectedResult, result.get(0)); + assertThat(result).hasSize(1); + assertThat(result.get(0)).isSameAs(expectedResult); } } diff --git a/core/src/test/java/org/springframework/ldap/core/ContextMapperCallbackHandlerTest.java b/core/src/test/java/org/springframework/ldap/core/ContextMapperCallbackHandlerTest.java index 31635acd..0754a61a 100644 --- a/core/src/test/java/org/springframework/ldap/core/ContextMapperCallbackHandlerTest.java +++ b/core/src/test/java/org/springframework/ldap/core/ContextMapperCallbackHandlerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import org.junit.Test; import javax.naming.Binding; import javax.naming.NamingException; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -51,7 +51,7 @@ public class ContextMapperCallbackHandlerTest { when(mapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); Object actualResult = tested .getObjectFromNameClassPair(expectedBinding); - assertEquals(expectedResult, actualResult); + assertThat(actualResult).isEqualTo(expectedResult); } @Test(expected = ObjectRetrievalException.class) diff --git a/core/src/test/java/org/springframework/ldap/core/DirContextAdapterBugTest.java b/core/src/test/java/org/springframework/ldap/core/DirContextAdapterBugTest.java index f26bee75..3a137136 100644 --- a/core/src/test/java/org/springframework/ldap/core/DirContextAdapterBugTest.java +++ b/core/src/test/java/org/springframework/ldap/core/DirContextAdapterBugTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,7 @@ import javax.naming.Name; import javax.naming.directory.Attributes; import javax.naming.directory.BasicAttributes; -import static org.junit.Assert.assertEquals; - +import static org.assertj.core.api.Assertions.assertThat; /** * Unit tests that serve as regression tests for bugs that have been fixed. @@ -42,7 +41,7 @@ public class DirContextAdapterBugTest { ctx.setAttributeValues("myattr", new String[] { "a", "b" }); ctx.setAttributeValues("myattr", new String[] { "a", "b", "c" }); - assertEquals(0, ctx.getModificationItems().length); + assertThat(ctx.getModificationItems().length).isEqualTo(0); } @Test @@ -55,7 +54,7 @@ public class DirContextAdapterBugTest { ctx.setAttributeValues("myattr", new String[] { "a", "b", "d" }); ctx.setAttributeValues("myattr", new String[] { "a", "b", "c" }); - assertEquals(0, ctx.getModificationItems().length); + assertThat(ctx.getModificationItems().length).isEqualTo(0); } /** @@ -74,7 +73,7 @@ public class DirContextAdapterBugTest { ctx.setAttributeValues("myattr", new String[] { "a" }); ctx.setAttributeValues("myattr", null); - assertEquals(1, ctx.getModificationItems().length); + assertThat(ctx.getModificationItems().length).isEqualTo(1); } @Test @@ -85,7 +84,7 @@ public class DirContextAdapterBugTest { ctx.setAttributeValue("myattr", "a"); ctx.setAttributeValue("myattr", "b"); - assertEquals(0, ctx.getModificationItems().length); + assertThat(ctx.getModificationItems().length).isEqualTo(0); } private static class UpdateAdapter extends DirContextAdapter { diff --git a/core/src/test/java/org/springframework/ldap/core/DirContextAdapterTest.java b/core/src/test/java/org/springframework/ldap/core/DirContextAdapterTest.java index 33896f72..2620651d 100644 --- a/core/src/test/java/org/springframework/ldap/core/DirContextAdapterTest.java +++ b/core/src/test/java/org/springframework/ldap/core/DirContextAdapterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,12 +33,8 @@ import javax.naming.ldap.LdapName; import java.util.Iterator; import java.util.SortedSet; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Tests the DirContextAdapter class. @@ -62,33 +58,33 @@ public class DirContextAdapterTest { @Test public void testSetUpdateMode() throws Exception { - assertFalse(tested.isUpdateMode()); + assertThat(tested.isUpdateMode()).isFalse(); tested.setUpdateMode(true); - assertTrue(tested.isUpdateMode()); + assertThat(tested.isUpdateMode()).isTrue(); tested.setUpdateMode(false); - assertFalse(tested.isUpdateMode()); + assertThat(tested.isUpdateMode()).isFalse(); } @Test public void testGetModificationItems() throws Exception { ModificationItem[] items = tested.getModificationItems(); - assertEquals(0, items.length); + assertThat(items.length).isEqualTo(0); tested.setUpdateMode(true); - assertEquals(0, items.length); + assertThat(items.length).isEqualTo(0); } @Test public void testAlwaysReplace() throws Exception { ModificationItem[] items = tested.getModificationItems(); - assertEquals(0, items.length); + assertThat(items.length).isEqualTo(0); tested.setUpdateMode(true); - assertEquals(0, items.length); + assertThat(items.length).isEqualTo(0); } @Test public void testGetStringAttributeWhenAttributeDoesNotExist() throws Exception { String s = tested.getStringAttribute("does not exist"); - assertNull(s); + assertThat(s).isNull(); } @Test @@ -102,7 +98,7 @@ public class DirContextAdapterTest { } tested = new TestableDirContextAdapter(); String s = tested.getStringAttribute("abc"); - assertNull(s); + assertThat(s).isNull(); } @Test @@ -116,13 +112,13 @@ public class DirContextAdapterTest { } tested = new TestableDirContextAdapter(); boolean result = tested.attributeExists("abc"); - assertEquals(true, result); + assertThat(result).isEqualTo(true); } @Test public void testAttributeExistsWhenAttributeDoesNotExist() throws Exception { boolean result = tested.attributeExists("does not exist"); - assertEquals(false, result); + assertThat(result).isEqualTo(false); } @Test @@ -136,7 +132,7 @@ public class DirContextAdapterTest { } tested = new TestableDirContextAdapter(); String s = tested.getStringAttribute("abc"); - assertEquals("def", s); + assertThat(s).isEqualTo("def"); } @Test @@ -153,9 +149,9 @@ public class DirContextAdapterTest { } tested = new TestableDirContextAdapter(); String s[] = tested.getStringAttributes("abc"); - assertEquals("123", s[0]); - assertEquals("234", s[1]); - assertEquals(2, s.length); + assertThat(s[0]).isEqualTo("123"); + assertThat(s[1]).isEqualTo("234"); + assertThat(s.length).isEqualTo(2); } @Test @@ -175,7 +171,7 @@ public class DirContextAdapterTest { fail("ClassCastException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @@ -191,14 +187,14 @@ public class DirContextAdapterTest { } tested = new TestableDirContextAdapter(); String s[] = tested.getStringAttributes("abc"); - assertNotNull(s); - assertEquals(0, s.length); + assertThat(s).isNotNull(); + assertThat(s.length).isEqualTo(0); } @Test public void testGetStringAttributesNotExists() throws Exception { String s[] = tested.getStringAttributes("abc"); - assertNull(s); + assertThat(s).isNull(); } @Test @@ -215,11 +211,11 @@ public class DirContextAdapterTest { } tested = new TestableDirContextAdapter(); SortedSet s = tested.getAttributeSortedStringSet("abc"); - assertNotNull(s); - assertEquals(2, s.size()); + assertThat(s).isNotNull(); + assertThat(s).hasSize(2); Iterator it = s.iterator(); - assertEquals("123", it.next()); - assertEquals("234", it.next()); + assertThat(it.next()).isEqualTo("123"); + assertThat(it.next()).isEqualTo("234"); } @Test @@ -232,7 +228,7 @@ public class DirContextAdapterTest { } tested = new TestableDirContextAdapter(); SortedSet s = tested.getAttributeSortedStringSet("abc"); - assertNull(s); + assertThat(s).isNull(); } @Test @@ -242,7 +238,7 @@ public class DirContextAdapterTest { Attributes attrs = tested.getAttributes(); Attribute attr = attrs.get("abc"); - assertEquals("123", (String) attr.get()); + assertThat((String) attr.get()).isEqualTo("123"); } @Test @@ -255,8 +251,8 @@ public class DirContextAdapterTest { Attributes attrs = tested.getAttributes(); Attribute attr = attrs.get("abc"); - assertEquals("321", (String) attr.get(0)); - assertEquals("123", (String) attr.get(1)); + assertThat((String) attr.get(0)).isEqualTo("321"); + assertThat((String) attr.get(1)).isEqualTo("123"); } @Test @@ -269,8 +265,8 @@ public class DirContextAdapterTest { Attributes attrs = tested.getAttributes(); Attribute attr = attrs.get("abc"); - assertEquals(1, attr.size()); - assertEquals("123", (String) attr.get(0)); + assertThat(attr.size()).isEqualTo(1); + assertThat((String) attr.get(0)).isEqualTo("123"); } @Test @@ -280,13 +276,13 @@ public class DirContextAdapterTest { // Perform test Attributes attrs = tested.getAttributes(); - assertNull(attrs.get("abc")); + assertThat(attrs.get("abc")).isNull(); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(1, modificationItems.length); + assertThat(modificationItems.length).isEqualTo(1); Attribute attribute = modificationItems[0].getAttribute(); - assertEquals("abc", attribute.getID()); - assertEquals("123", attribute.get()); + assertThat(attribute.getID()).isEqualTo("abc"); + assertThat(attribute.get()).isEqualTo("123"); } @Test @@ -300,14 +296,14 @@ public class DirContextAdapterTest { tested.addAttributeValue("abc", "123"); Attributes attrs = tested.getAttributes(); - assertNotNull(attrs.get("abc")); + assertThat(attrs.get("abc")).isNotNull(); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(1, modificationItems.length); + assertThat(modificationItems.length).isEqualTo(1); Attribute attribute = modificationItems[0].getAttribute(); - assertEquals(1, attribute.size()); - assertEquals("abc", attribute.getID()); - assertEquals("123", attribute.get()); + assertThat(attribute.size()).isEqualTo(1); + assertThat(attribute.getID()).isEqualTo("abc"); + assertThat(attribute.get()).isEqualTo("123"); } @Test @@ -321,10 +317,10 @@ public class DirContextAdapterTest { tested.addAttributeValue("abc", "123"); Attributes attrs = tested.getAttributes(); - assertNotNull(attrs.get("abc")); + assertThat(attrs.get("abc")).isNotNull(); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(0, modificationItems.length); + assertThat(modificationItems.length).isEqualTo(0); } @Test @@ -337,14 +333,14 @@ public class DirContextAdapterTest { tested.addAttributeValue("abc", "123"); Attributes attrs = tested.getAttributes(); - assertNull(attrs.get("abc")); + assertThat(attrs.get("abc")).isNull(); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(1, modificationItems.length); + assertThat(modificationItems.length).isEqualTo(1); Attribute attribute = modificationItems[0].getAttribute(); - assertEquals("abc", attribute.getID()); - assertEquals("321", attribute.get(0)); - assertEquals("123", attribute.get(1)); + assertThat(attribute.getID()).isEqualTo("abc"); + assertThat(attribute.get(0)).isEqualTo("321"); + assertThat(attribute.get(1)).isEqualTo("123"); } @Test @@ -357,14 +353,14 @@ public class DirContextAdapterTest { tested.addAttributeValue("abc", "123"); Attributes attrs = tested.getAttributes(); - assertNull(attrs.get("abc")); + assertThat(attrs.get("abc")).isNull(); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(1, modificationItems.length); + assertThat(modificationItems.length).isEqualTo(1); Attribute attribute = modificationItems[0].getAttribute(); - assertEquals(1, attribute.size()); - assertEquals("abc", attribute.getID()); - assertEquals("123", attribute.get()); + assertThat(attribute.size()).isEqualTo(1); + assertThat(attribute.getID()).isEqualTo("abc"); + assertThat(attribute.get()).isEqualTo("123"); } @Test @@ -373,8 +369,8 @@ public class DirContextAdapterTest { tested.addAttributeValue("member2", LdapUtils.newLdapName("CN=test2,DC=root")); Attributes attrs = tested.getAttributes(); - assertEquals(LdapUtils.newLdapName("CN=test,DC=root"), attrs.get("member").get()); - assertEquals(LdapUtils.newLdapName("CN=test2,DC=root"), attrs.get("member2").get()); + assertThat(attrs.get("member").get()).isEqualTo(LdapUtils.newLdapName("CN=test,DC=root")); + assertThat(attrs.get("member2").get()).isEqualTo(LdapUtils.newLdapName("CN=test2,DC=root")); } @Test @@ -383,8 +379,8 @@ public class DirContextAdapterTest { tested.addAttributeValue("member2", LdapUtils.newLdapName("CN=test2,DC=root")); Attributes attrs = tested.getAttributes(); - assertEquals("CN=test,DC=root", attrs.get("member").get()); - assertEquals(LdapUtils.newLdapName("CN=test2,DC=root"), attrs.get("member2").get()); + assertThat(attrs.get("member").get()).isEqualTo("CN=test,DC=root"); + assertThat(attrs.get("member2").get()).isEqualTo(LdapUtils.newLdapName("CN=test2,DC=root")); } @Test @@ -393,7 +389,7 @@ public class DirContextAdapterTest { tested.removeAttributeValue("abc", "123"); Attributes attributes = tested.getAttributes(); - assertNull(attributes.get("abc")); + assertThat(attributes.get("abc")).isNull(); } @Test @@ -406,9 +402,9 @@ public class DirContextAdapterTest { Attributes attributes = tested.getAttributes(); Attribute attr = attributes.get("abc"); - assertNotNull(attr); - assertEquals(1, attr.size()); - assertEquals("321", attr.get()); + assertThat(attr).isNotNull(); + assertThat(attr.size()).isEqualTo(1); + assertThat(attr.get()).isEqualTo("321"); } @Test @@ -420,7 +416,7 @@ public class DirContextAdapterTest { Attributes attributes = tested.getAttributes(); Attribute attr = attributes.get("abc"); - assertNull(attr); + assertThat(attr).isNull(); } @Test @@ -436,9 +432,9 @@ public class DirContextAdapterTest { Attributes attributes = tested.getAttributes(); Attribute attr = attributes.get("abc"); - assertNotNull(attr); - assertEquals(1, attr.size()); - assertEquals("321", attr.get()); + assertThat(attr).isNotNull(); + assertThat(attr.size()).isEqualTo(1); + assertThat(attr.get()).isEqualTo("321"); } @Test @@ -448,10 +444,10 @@ public class DirContextAdapterTest { // Perform test tested.removeAttributeValue("abc", "123"); - assertNull(tested.getAttributes().get("abc")); + assertThat(tested.getAttributes().get("abc")).isNull(); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(0, modificationItems.length); + assertThat(modificationItems.length).isEqualTo(0); } @Test @@ -462,10 +458,10 @@ public class DirContextAdapterTest { // Perform test tested.removeAttributeValue("abc", "123"); - assertNull(tested.getAttributes().get("abc")); + assertThat(tested.getAttributes().get("abc")).isNull(); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(0, modificationItems.length); + assertThat(modificationItems.length).isEqualTo(0); } @Test @@ -477,14 +473,14 @@ public class DirContextAdapterTest { // Perform test tested.removeAttributeValue("abc", "123"); - assertNull(tested.getAttributes().get("abc")); + assertThat(tested.getAttributes().get("abc")).isNull(); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(1, modificationItems.length); + assertThat(modificationItems.length).isEqualTo(1); Attribute modificationAttribute = modificationItems[0].getAttribute(); - assertEquals("abc", modificationAttribute.getID()); - assertEquals(1, modificationAttribute.size()); - assertEquals("321", modificationAttribute.get()); + assertThat(modificationAttribute.getID()).isEqualTo("abc"); + assertThat(modificationAttribute.size()).isEqualTo(1); + assertThat(modificationAttribute.get()).isEqualTo("321"); } @Test @@ -496,13 +492,13 @@ public class DirContextAdapterTest { // Perform test tested.removeAttributeValue("abc", "123"); - assertNull(tested.getAttributes().get("abc")); + assertThat(tested.getAttributes().get("abc")).isNull(); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(1, modificationItems.length); + assertThat(modificationItems.length).isEqualTo(1); Attribute modificationAttribute = modificationItems[0].getAttribute(); - assertEquals("abc", modificationAttribute.getID()); - assertEquals(1, modificationAttribute.size()); + assertThat(modificationAttribute.getID()).isEqualTo("abc"); + assertThat(modificationAttribute.size()).isEqualTo(1); } @Test @@ -514,12 +510,11 @@ public class DirContextAdapterTest { tested.removeAttributeValue("abc", "123"); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(1, modificationItems.length); + assertThat(modificationItems.length).isEqualTo(1); Attribute modificationAttribute = modificationItems[0].getAttribute(); - assertEquals("abc", modificationAttribute.getID()); - assertEquals(0, modificationAttribute.size()); - assertEquals(DirContext.REMOVE_ATTRIBUTE, modificationItems[0] - .getModificationOp()); + assertThat(modificationAttribute.getID()).isEqualTo("abc"); + assertThat(modificationAttribute.size()).isEqualTo(0); + assertThat(modificationItems[0].getModificationOp()).isEqualTo(DirContext.REMOVE_ATTRIBUTE); } @Test @@ -535,60 +530,59 @@ public class DirContextAdapterTest { tested.removeAttributeValue("abc", "123"); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(1, modificationItems.length); + assertThat(modificationItems.length).isEqualTo(1); Attribute modificationAttribute = modificationItems[0].getAttribute(); - assertEquals("abc", modificationAttribute.getID()); - assertEquals(1, modificationAttribute.size()); - assertEquals("123", modificationAttribute.get()); - assertEquals(DirContext.REMOVE_ATTRIBUTE, modificationItems[0] - .getModificationOp()); + assertThat(modificationAttribute.getID()).isEqualTo("abc"); + assertThat(modificationAttribute.size()).isEqualTo(1); + assertThat(modificationAttribute.get()).isEqualTo("123"); + assertThat(modificationItems[0].getModificationOp()).isEqualTo(DirContext.REMOVE_ATTRIBUTE); } @Test public void testSetStringAttribute() throws Exception { - assertFalse(tested.isUpdateMode()); + assertThat(tested.isUpdateMode()).isFalse(); tested.setAttributeValue("abc", "123"); Attributes attrs = tested.getAttributes(); Attribute attr = attrs.get("abc"); - assertEquals("123", (String) attr.get()); + assertThat((String) attr.get()).isEqualTo("123"); } @Test public void testSetStringAttributeNull() throws Exception { - assertFalse(tested.isUpdateMode()); + assertThat(tested.isUpdateMode()).isFalse(); tested.setAttributeValue("abc", null); Attributes attrs = tested.getAttributes(); Attribute attr = attrs.get("abc"); - assertNull(attr); + assertThat(attr).isNull(); } @Test public void testAddAttribute() throws Exception { tested.setUpdateMode(true); - assertTrue(tested.isUpdateMode()); + assertThat(tested.isUpdateMode()).isTrue(); tested.setAttributeValue("abc", "123"); Attributes attrs = tested.getAttributes(); Attribute attr = attrs.get("abc"); - assertNull(attr); + assertThat(attr).isNull(); ModificationItem[] mods = tested.getModificationItems(); - assertEquals(1, mods.length); - assertEquals(DirContext.ADD_ATTRIBUTE, mods[0].getModificationOp()); + assertThat(mods.length).isEqualTo(1); + assertThat(mods[0].getModificationOp()).isEqualTo(DirContext.ADD_ATTRIBUTE); attr = mods[0].getAttribute(); - assertEquals("123", (String) attr.get()); + assertThat((String) attr.get()).isEqualTo("123"); String[] modNames = tested.getNamesOfModifiedAttributes(); - assertEquals(1, modNames.length); - assertEquals("abc", modNames[0]); + assertThat(modNames.length).isEqualTo(1); + assertThat(modNames[0]).isEqualTo("abc"); tested.update(); mods = tested.getModificationItems(); - assertEquals(0, mods.length); + assertThat(mods.length).isEqualTo(0); modNames = tested.getNamesOfModifiedAttributes(); - assertEquals(0, modNames.length); + assertThat(modNames.length).isEqualTo(0); attrs = tested.getAttributes(); attr = attrs.get("abc"); - assertEquals("123", (String) attr.get()); + assertThat((String) attr.get()).isEqualTo("123"); } // LDAP-304 @@ -596,18 +590,18 @@ public class DirContextAdapterTest { public void testModifyNull() throws Exception { tested.setAttributeValue("memberDN", null); tested.setUpdateMode(true); - assertTrue(tested.isUpdateMode()); + assertThat(tested.isUpdateMode()).isTrue(); tested.setAttributeValue("memberDN", new LdapName("ou=test")); ModificationItem[] mods = tested.getModificationItems(); - assertEquals(1, mods.length); + assertThat(mods.length).isEqualTo(1); } @Test public void testGetDn() throws Exception { DirContextAdapter tested = new DirContextAdapter(DUMMY_NAME); Name result = tested.getDn(); - assertEquals(DUMMY_NAME, result); + assertThat(result).isEqualTo(DUMMY_NAME); } @Test @@ -615,14 +609,14 @@ public class DirContextAdapterTest { DirContextAdapter tested = new DirContextAdapter(null, DUMMY_NAME, BASE_NAME); Name result = tested.getDn(); - assertEquals(DUMMY_NAME, result); + assertThat(result).isEqualTo(DUMMY_NAME); } @Test public void testGetNameInNamespace() { DirContextAdapter tested = new DirContextAdapter(DUMMY_NAME); String result = tested.getNameInNamespace(); - assertEquals(DUMMY_NAME.toString(), result); + assertThat(result).isEqualTo(DUMMY_NAME.toString()); } @Test @@ -630,38 +624,38 @@ public class DirContextAdapterTest { DirContextAdapter tested = new DirContextAdapter(null, LdapUtils.newLdapName("c=SE"), BASE_NAME); String result = tested.getNameInNamespace(); - assertEquals(DUMMY_NAME.toString(), result); + assertThat(result).isEqualTo(DUMMY_NAME.toString()); } @Test public void testAddMultiAttributes() throws Exception { tested.setUpdateMode(true); - assertTrue(tested.isUpdateMode()); + assertThat(tested.isUpdateMode()).isTrue(); tested.setAttributeValues("abc", new String[] { "123", "456" }); Attributes attrs = tested.getAttributes(); Attribute attr = attrs.get("abc"); - assertNull(attr); + assertThat(attr).isNull(); ModificationItem[] mods = tested.getModificationItems(); - assertEquals(1, mods.length); - assertEquals(DirContext.ADD_ATTRIBUTE, mods[0].getModificationOp()); + assertThat(mods.length).isEqualTo(1); + assertThat(mods[0].getModificationOp()).isEqualTo(DirContext.ADD_ATTRIBUTE); attr = mods[0].getAttribute(); - assertEquals(2, attr.size()); - assertEquals("123", (String) attr.get(0)); - assertEquals("456", (String) attr.get(1)); + assertThat(attr.size()).isEqualTo(2); + assertThat((String) attr.get(0)).isEqualTo("123"); + assertThat((String) attr.get(1)).isEqualTo("456"); String[] modNames = tested.getNamesOfModifiedAttributes(); - assertEquals(1, modNames.length); - assertEquals("abc", modNames[0]); + assertThat(modNames.length).isEqualTo(1); + assertThat(modNames[0]).isEqualTo("abc"); tested.update(); mods = tested.getModificationItems(); - assertEquals(0, mods.length); + assertThat(mods.length).isEqualTo(0); modNames = tested.getNamesOfModifiedAttributes(); - assertEquals(0, modNames.length); + assertThat(modNames.length).isEqualTo(0); attrs = tested.getAttributes(); attr = attrs.get("abc"); - assertEquals("123", (String) attr.get(0)); - assertEquals("456", (String) attr.get(1)); + assertThat((String) attr.get(0)).isEqualTo("123"); + assertThat((String) attr.get(1)).isEqualTo("456"); } @Test @@ -677,29 +671,29 @@ public class DirContextAdapterTest { tested = new TestableDirContextAdapter(); tested.setUpdateMode(true); - assertTrue(tested.isUpdateMode()); + assertThat(tested.isUpdateMode()).isTrue(); tested.setAttributeValue("abc", null); Attributes attrs = tested.getAttributes(); Attribute attr = attrs.get("abc"); - assertEquals("123", (String) attr.get()); + assertThat((String) attr.get()).isEqualTo("123"); ModificationItem[] mods = tested.getModificationItems(); - assertEquals(1, mods.length); - assertEquals(DirContext.REMOVE_ATTRIBUTE, mods[0].getModificationOp()); + assertThat(mods.length).isEqualTo(1); + assertThat(mods[0].getModificationOp()).isEqualTo(DirContext.REMOVE_ATTRIBUTE); attr = mods[0].getAttribute(); - assertEquals("abc", (String) attr.getID()); + assertThat((String) attr.getID()).isEqualTo("abc"); String[] modNames = tested.getNamesOfModifiedAttributes(); - assertEquals(1, modNames.length); - assertEquals("abc", modNames[0]); + assertThat(modNames.length).isEqualTo(1); + assertThat(modNames[0]).isEqualTo("abc"); tested.update(); mods = tested.getModificationItems(); - assertEquals(0, mods.length); + assertThat(mods.length).isEqualTo(0); modNames = tested.getNamesOfModifiedAttributes(); - assertEquals(0, modNames.length); + assertThat(modNames.length).isEqualTo(0); attrs = tested.getAttributes(); attr = attrs.get("abc"); - assertNull(attr); + assertThat(attr).isNull(); } @Test @@ -721,11 +715,11 @@ public class DirContextAdapterTest { tested.setAttributeValues("abc", new String[] {}); ModificationItem[] mods = tested.getModificationItems(); - assertEquals(1, mods.length); - assertEquals(DirContext.REMOVE_ATTRIBUTE, mods[0].getModificationOp()); + assertThat(mods.length).isEqualTo(1); + assertThat(mods[0].getModificationOp()).isEqualTo(DirContext.REMOVE_ATTRIBUTE); Attribute attr = mods[0].getAttribute(); - assertEquals("abc", (String) attr.getID()); - assertEquals(0, attr.size()); + assertThat((String) attr.getID()).isEqualTo("abc"); + assertThat(attr.size()).isEqualTo(0); } @Test @@ -742,11 +736,11 @@ public class DirContextAdapterTest { tested.setAttributeValue("abc", "234"); // change ModificationItem[] mods = tested.getModificationItems(); - assertEquals(1, mods.length); - assertEquals(DirContext.REPLACE_ATTRIBUTE, mods[0].getModificationOp()); + assertThat(mods.length).isEqualTo(1); + assertThat(mods[0].getModificationOp()).isEqualTo(DirContext.REPLACE_ATTRIBUTE); Attribute attr = mods[0].getAttribute(); - assertEquals("abc", (String) attr.getID()); - assertEquals("234", (String) attr.get()); + assertThat((String) attr.getID()).isEqualTo("abc"); + assertThat((String) attr.get()).isEqualTo("234"); } @Test @@ -760,11 +754,11 @@ public class DirContextAdapterTest { } } tested = new TestableDirContextAdapter(); - assertTrue(tested.isUpdateMode()); + assertThat(tested.isUpdateMode()).isTrue(); tested.setAttributeValue("abc", "123"); // change ModificationItem[] mods = tested.getModificationItems(); - assertEquals(0, mods.length); + assertThat(mods.length).isEqualTo(0); } @Test @@ -781,13 +775,13 @@ public class DirContextAdapterTest { } } tested = new TestableDirContextAdapter(); - assertTrue(tested.isUpdateMode()); + assertThat(tested.isUpdateMode()).isTrue(); tested.setAttributeValues("abc", new String[] { "123", "qwe" }); ModificationItem[] mods = tested.getModificationItems(); - assertEquals(0, mods.length); + assertThat(mods.length).isEqualTo(0); String[] modNames = tested.getNamesOfModifiedAttributes(); - assertEquals(0, modNames.length); + assertThat(modNames.length).isEqualTo(0); } @Test @@ -807,9 +801,9 @@ public class DirContextAdapterTest { tested.setAttributeValues("abc", new String[] { "qwe", "123" }); ModificationItem[] mods = tested.getModificationItems(); - assertEquals(0, mods.length); + assertThat(mods.length).isEqualTo(0); String[] modNames = tested.getNamesOfModifiedAttributes(); - assertEquals(0, modNames.length); + assertThat(modNames.length).isEqualTo(0); } @Test @@ -826,16 +820,16 @@ public class DirContextAdapterTest { } } tested = new TestableDirContextAdapter(); - assertTrue(tested.isUpdateMode()); + assertThat(tested.isUpdateMode()).isTrue(); tested.setAttributeValues("abc", new String[] { "qwe", "123" }, true); // change ModificationItem[] mods = tested.getModificationItems(); - assertEquals(1, mods.length); - assertEquals(DirContext.REPLACE_ATTRIBUTE, mods[0].getModificationOp()); + assertThat(mods.length).isEqualTo(1); + assertThat(mods[0].getModificationOp()).isEqualTo(DirContext.REPLACE_ATTRIBUTE); Attribute attr = mods[0].getAttribute(); - assertEquals("qwe", attr.get(0)); - assertEquals("123", attr.get(1)); + assertThat(attr.get(0)).isEqualTo("qwe"); + assertThat(attr.get(1)).isEqualTo("123"); } /** @@ -857,18 +851,18 @@ public class DirContextAdapterTest { } } tested = new TestableDirContextAdapter(); - assertTrue(tested.isUpdateMode()); + assertThat(tested.isUpdateMode()).isTrue(); tested.setAttributeValues("title", new String[] { "Jim", "George", "Juergen" }, true); // change ModificationItem[] mods = tested.getModificationItems(); - assertEquals(1, mods.length); - assertEquals(DirContext.REPLACE_ATTRIBUTE, mods[0].getModificationOp()); + assertThat(mods.length).isEqualTo(1); + assertThat(mods[0].getModificationOp()).isEqualTo(DirContext.REPLACE_ATTRIBUTE); Attribute attr = mods[0].getAttribute(); - assertEquals("Jim", attr.get(0)); - assertEquals("George", attr.get(1)); - assertEquals("Juergen", attr.get(2)); + assertThat(attr.get(0)).isEqualTo("Jim"); + assertThat(attr.get(1)).isEqualTo("George"); + assertThat(attr.get(2)).isEqualTo("Juergen"); } @Test @@ -885,16 +879,15 @@ public class DirContextAdapterTest { } } tested = new TestableDirContextAdapter(); - assertTrue(tested.isUpdateMode()); + assertThat(tested.isUpdateMode()).isTrue(); tested .setAttributeValues("abc", new String[] { "123", "qwe", "klytt" }); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(1, modificationItems.length); - assertEquals(DirContext.ADD_ATTRIBUTE, modificationItems[0] - .getModificationOp()); - assertEquals("klytt", modificationItems[0].getAttribute().get()); + assertThat(modificationItems.length).isEqualTo(1); + assertThat(modificationItems[0].getModificationOp()).isEqualTo(DirContext.ADD_ATTRIBUTE); + assertThat(modificationItems[0].getAttribute().get()).isEqualTo("klytt"); } @Test @@ -911,14 +904,13 @@ public class DirContextAdapterTest { } } tested = new TestableDirContextAdapter(); - assertTrue(tested.isUpdateMode()); + assertThat(tested.isUpdateMode()).isTrue(); tested.setAttributeValues("abc", new String[] { "123" }); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(1, modificationItems.length); - assertEquals(DirContext.REMOVE_ATTRIBUTE, modificationItems[0] - .getModificationOp()); - assertEquals("qwe", modificationItems[0].getAttribute().get()); + assertThat(modificationItems.length).isEqualTo(1); + assertThat(modificationItems[0].getModificationOp()).isEqualTo(DirContext.REMOVE_ATTRIBUTE); + assertThat(modificationItems[0].getAttribute().get()).isEqualTo("qwe"); } @Test @@ -936,15 +928,14 @@ public class DirContextAdapterTest { } } tested = new TestableDirContextAdapter(); - assertTrue(tested.isUpdateMode()); + assertThat(tested.isUpdateMode()).isTrue(); tested.setAttributeValues("abc", new String[] { "123" }); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(1, modificationItems.length); - assertEquals(DirContext.REMOVE_ATTRIBUTE, modificationItems[0] - .getModificationOp()); - assertEquals("qwe", modificationItems[0].getAttribute().get(0)); - assertEquals("rty", modificationItems[0].getAttribute().get(1)); + assertThat(modificationItems.length).isEqualTo(1); + assertThat(modificationItems[0].getModificationOp()).isEqualTo(DirContext.REMOVE_ATTRIBUTE); + assertThat(modificationItems[0].getAttribute().get(0)).isEqualTo("qwe"); + assertThat(modificationItems[0].getAttribute().get(1)).isEqualTo("rty"); } @Test @@ -961,13 +952,12 @@ public class DirContextAdapterTest { } } tested = new TestableDirContextAdapter(); - assertTrue(tested.isUpdateMode()); + assertThat(tested.isUpdateMode()).isTrue(); tested.setAttributeValues("abc", null); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(1, modificationItems.length); - assertEquals(DirContext.REMOVE_ATTRIBUTE, modificationItems[0] - .getModificationOp()); + assertThat(modificationItems.length).isEqualTo(1); + assertThat(modificationItems[0].getModificationOp()).isEqualTo(DirContext.REMOVE_ATTRIBUTE); } @Test @@ -984,11 +974,11 @@ public class DirContextAdapterTest { } } tested = new TestableDirContextAdapter(); - assertTrue(tested.isUpdateMode()); + assertThat(tested.isUpdateMode()).isTrue(); tested.setAttributeValues("abc", new String[] { "123", "qwe" }); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(0, modificationItems.length); + assertThat(modificationItems.length).isEqualTo(0); } @Test @@ -1007,28 +997,26 @@ public class DirContextAdapterTest { } } tested = new TestableDirContextAdapter(); - assertTrue(tested.isUpdateMode()); + assertThat(tested.isUpdateMode()).isTrue(); tested.setAttributeValues("abc", new String[] { "123", "qwe", "klytt", "kalle" }); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(2, modificationItems.length); + assertThat(modificationItems.length).isEqualTo(2); Attribute modifiedAttribute = modificationItems[0].getAttribute(); - assertEquals(DirContext.REMOVE_ATTRIBUTE, modificationItems[0] - .getModificationOp()); - assertEquals("abc", modifiedAttribute.getID()); - assertEquals(2, modifiedAttribute.size()); - assertEquals("rty", modifiedAttribute.get(0)); - assertEquals("uio", modifiedAttribute.get(1)); + assertThat(modificationItems[0].getModificationOp()).isEqualTo(DirContext.REMOVE_ATTRIBUTE); + assertThat(modifiedAttribute.getID()).isEqualTo("abc"); + assertThat(modifiedAttribute.size()).isEqualTo(2); + assertThat(modifiedAttribute.get(0)).isEqualTo("rty"); + assertThat(modifiedAttribute.get(1)).isEqualTo("uio"); - assertEquals(DirContext.ADD_ATTRIBUTE, modificationItems[1] - .getModificationOp()); + assertThat(modificationItems[1].getModificationOp()).isEqualTo(DirContext.ADD_ATTRIBUTE); modifiedAttribute = modificationItems[1].getAttribute(); - assertEquals("abc", modifiedAttribute.getID()); - assertEquals(2, modifiedAttribute.size()); - assertEquals("klytt", modifiedAttribute.get(0)); - assertEquals("kalle", modifiedAttribute.get(1)); + assertThat(modifiedAttribute.getID()).isEqualTo("abc"); + assertThat(modifiedAttribute.size()).isEqualTo(2); + assertThat(modifiedAttribute.get(0)).isEqualTo("klytt"); + assertThat(modifiedAttribute.get(1)).isEqualTo("kalle"); } @Test @@ -1045,12 +1033,12 @@ public class DirContextAdapterTest { } } tested = new TestableDirContextAdapter(); - assertTrue(tested.isUpdateMode()); + assertThat(tested.isUpdateMode()).isTrue(); tested.setAttributeValues("def", new String[] { "kalle", "klytt" }); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(1, modificationItems.length); - assertEquals("def", modificationItems[0].getAttribute().getID()); + assertThat(modificationItems.length).isEqualTo(1); + assertThat(modificationItems[0].getAttribute().getID()).isEqualTo("def"); } @Test @@ -1064,26 +1052,26 @@ public class DirContextAdapterTest { } } tested = new TestableDirContextAdapter(); - assertTrue(tested.isUpdateMode()); + assertThat(tested.isUpdateMode()).isTrue(); tested.setAttributeValue("abc", "234"); // change tested.setAttributeValue("abc", "987"); // change a second time ModificationItem[] mods = tested.getModificationItems(); - assertEquals(1, mods.length); - assertEquals(DirContext.REPLACE_ATTRIBUTE, mods[0].getModificationOp()); + assertThat(mods.length).isEqualTo(1); + assertThat(mods[0].getModificationOp()).isEqualTo(DirContext.REPLACE_ATTRIBUTE); Attribute attr = mods[0].getAttribute(); - assertEquals("abc", (String) attr.getID()); - assertEquals("987", (String) attr.get()); + assertThat((String) attr.getID()).isEqualTo("abc"); + assertThat((String) attr.get()).isEqualTo("987"); tested.update(); mods = tested.getModificationItems(); - assertEquals(0, mods.length); + assertThat(mods.length).isEqualTo(0); String[] modNames = tested.getNamesOfModifiedAttributes(); - assertEquals(0, modNames.length); + assertThat(modNames.length).isEqualTo(0); Attributes attrs = tested.getAttributes(); attr = attrs.get("abc"); - assertEquals("987", (String) attr.get()); - assertEquals("987", tested.getStringAttribute("abc")); + assertThat((String) attr.get()).isEqualTo("987"); + assertThat(tested.getStringAttribute("abc")).isEqualTo("987"); } @Test @@ -1098,49 +1086,49 @@ public class DirContextAdapterTest { } } tested = new TestableDirContextAdapter(); - assertTrue(tested.isUpdateMode()); + assertThat(tested.isUpdateMode()).isTrue(); tested.setAttributeValue("abc", "234"); // change tested.setAttributeValue("qwe", null); // remove tested.setAttributeValue("zzz", "new"); // new Attributes attrs = tested.getAttributes(); Attribute attr = attrs.get("abc"); - assertEquals("123", (String) attr.get()); - assertEquals(2, attrs.size()); + assertThat((String) attr.get()).isEqualTo("123"); + assertThat(attrs.size()).isEqualTo(2); ModificationItem[] mods = tested.getModificationItems(); - assertEquals(3, mods.length); + assertThat(mods.length).isEqualTo(3); String[] modNames = tested.getNamesOfModifiedAttributes(); - assertEquals(3, modNames.length); + assertThat(modNames.length).isEqualTo(3); ModificationItem mod = getModificationItem(mods, DirContext.REPLACE_ATTRIBUTE); - assertNotNull(mod); + assertThat(mod).isNotNull(); attr = mod.getAttribute(); - assertEquals("abc", (String) attr.getID()); - assertEquals("234", (String) attr.get()); + assertThat((String) attr.getID()).isEqualTo("abc"); + assertThat((String) attr.get()).isEqualTo("234"); mod = getModificationItem(mods, DirContext.REMOVE_ATTRIBUTE); - assertNotNull(mod); + assertThat(mod).isNotNull(); attr = mod.getAttribute(); - assertEquals("qwe", (String) attr.getID()); + assertThat((String) attr.getID()).isEqualTo("qwe"); mod = getModificationItem(mods, DirContext.ADD_ATTRIBUTE); - assertNotNull(mod); + assertThat(mod).isNotNull(); attr = mod.getAttribute(); - assertEquals("zzz", (String) attr.getID()); - assertEquals("new", (String) attr.get()); + assertThat((String) attr.getID()).isEqualTo("zzz"); + assertThat((String) attr.get()).isEqualTo("new"); tested.update(); mods = tested.getModificationItems(); - assertEquals(0, mods.length); + assertThat(mods.length).isEqualTo(0); modNames = tested.getNamesOfModifiedAttributes(); - assertEquals(0, modNames.length); + assertThat(modNames.length).isEqualTo(0); attrs = tested.getAttributes(); - assertEquals(2, attrs.size()); + assertThat(attrs.size()).isEqualTo(2); attr = attrs.get("abc"); - assertEquals("234", (String) attr.get()); - assertEquals("new", tested.getStringAttribute("zzz")); + assertThat((String) attr.get()).isEqualTo("234"); + assertThat(tested.getStringAttribute("zzz")).isEqualTo("new"); } /** @@ -1164,25 +1152,25 @@ public class DirContextAdapterTest { // Verify result ModificationItem[] mods = tested.getModificationItems(); - assertEquals(1, mods.length); - assertEquals(DirContext.REPLACE_ATTRIBUTE, mods[0].getModificationOp()); + assertThat(mods.length).isEqualTo(1); + assertThat(mods[0].getModificationOp()).isEqualTo(DirContext.REPLACE_ATTRIBUTE); Attribute modificationAttribute = mods[0].getAttribute(); - assertEquals("cn", modificationAttribute.getID()); - assertEquals("nisse hult", modificationAttribute.get()); + assertThat(modificationAttribute.getID()).isEqualTo("cn"); + assertThat(modificationAttribute.get()).isEqualTo("nisse hult"); } @Test public void testGetStringAttributes_NullValue() { String result = tested.getStringAttribute("someAbsentAttribute"); - assertNull(result); + assertThat(result).isNull(); } @Test public void testGetStringAttributes_AttributeExists_NullValue() { tested.setAttribute(new BasicAttribute("someAttribute", null)); String result = tested.getStringAttribute("someAttribute"); - assertNull(result); + assertThat(result).isNull(); } private ModificationItem getModificationItem(ModificationItem[] mods, @@ -1209,15 +1197,13 @@ public class DirContextAdapterTest { // Perform test ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(2, modificationItems.length); + assertThat(modificationItems.length).isEqualTo(2); ModificationItem modificationItem = modificationItems[0]; - assertEquals(DirContext.REMOVE_ATTRIBUTE, modificationItem - .getModificationOp()); - assertEquals("Some Person", modificationItem.getAttribute().get()); + assertThat(modificationItem.getModificationOp()).isEqualTo(DirContext.REMOVE_ATTRIBUTE); + assertThat(modificationItem.getAttribute().get()).isEqualTo("Some Person"); modificationItem = modificationItems[1]; - assertEquals(DirContext.ADD_ATTRIBUTE, modificationItem - .getModificationOp()); - assertEquals("some person", modificationItem.getAttribute().get()); + assertThat(modificationItem.getModificationOp()).isEqualTo(DirContext.ADD_ATTRIBUTE); + assertThat(modificationItem.getAttribute().get()).isEqualTo("some person"); } /** @@ -1233,7 +1219,7 @@ public class DirContextAdapterTest { tested.setAttributeValue("abc", new byte[] { 1, 2, 3 }); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(0, modificationItems.length); + assertThat(modificationItems.length).isEqualTo(0); } /** @@ -1246,14 +1232,13 @@ public class DirContextAdapterTest { CompositeName compositeName = new CompositeName(); compositeName.add("cn=Some\\\\Person6,ou=company1,c=Sweden"); DirContextAdapter adapter = new DirContextAdapter(compositeName); - assertEquals("cn=Some\\\\Person6,ou=company1,c=Sweden", adapter.getDn() - .toString()); + assertThat(adapter.getDn().toString()).isEqualTo("cn=Some\\\\Person6,ou=company1,c=Sweden"); } @Test public void testStringConstructor() { DirContextAdapter tested = new DirContextAdapter("cn=john doe, ou=company"); - assertEquals(LdapUtils.newLdapName("cn=john doe, ou=company"), tested.getDn()); + assertThat(tested.getDn()).isEqualTo(LdapUtils.newLdapName("cn=john doe, ou=company")); } @Test @@ -1266,7 +1251,7 @@ public class DirContextAdapterTest { tested.addAttributeValue("uniqueMember", LdapUtils.newLdapName("cn=john doe, ou=company")); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(0, modificationItems.length); + assertThat(modificationItems.length).isEqualTo(0); } @Test @@ -1279,7 +1264,7 @@ public class DirContextAdapterTest { tested.addAttributeValue("uniqueMember", LdapUtils.newLdapName("cn=john doe, ou=company")); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(0, modificationItems.length); + assertThat(modificationItems.length).isEqualTo(0); } @Test @@ -1292,11 +1277,11 @@ public class DirContextAdapterTest { tested.removeAttributeValue("uniqueMember", LdapUtils.newLdapName("cn=john doe, ou=company")); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(1, modificationItems.length); + assertThat(modificationItems.length).isEqualTo(1); ModificationItem modificationItem = modificationItems[0]; - assertEquals(DirContext.REMOVE_ATTRIBUTE, modificationItem.getModificationOp()); - assertEquals("uniqueMember", modificationItem.getAttribute().getID()); + assertThat(modificationItem.getModificationOp()).isEqualTo(DirContext.REMOVE_ATTRIBUTE); + assertThat(modificationItem.getAttribute().getID()).isEqualTo("uniqueMember"); } @Test @@ -1311,12 +1296,12 @@ public class DirContextAdapterTest { tested.removeAttributeValue("uniqueMember", LdapUtils.newLdapName("cn=john doe, ou=company")); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(1, modificationItems.length); + assertThat(modificationItems.length).isEqualTo(1); ModificationItem modificationItem = modificationItems[0]; - assertEquals(DirContext.REMOVE_ATTRIBUTE, modificationItem.getModificationOp()); - assertEquals("uniqueMember", modificationItem.getAttribute().getID()); - assertEquals("cn=john doe,OU=company", modificationItem.getAttribute().get()); + assertThat(modificationItem.getModificationOp()).isEqualTo(DirContext.REMOVE_ATTRIBUTE); + assertThat(modificationItem.getAttribute().getID()).isEqualTo("uniqueMember"); + assertThat(modificationItem.getAttribute().get()).isEqualTo("cn=john doe,OU=company"); } @Test @@ -1329,12 +1314,12 @@ public class DirContextAdapterTest { tested.addAttributeValue("uniqueMember", LdapUtils.newLdapName("cn=jane doe, ou=company")); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(1, modificationItems.length); + assertThat(modificationItems.length).isEqualTo(1); ModificationItem modificationItem = modificationItems[0]; - assertEquals(DirContext.ADD_ATTRIBUTE, modificationItem.getModificationOp()); - assertEquals("uniqueMember", modificationItem.getAttribute().getID()); - assertEquals("cn=jane doe, ou=company", modificationItem.getAttribute().get()); + assertThat(modificationItem.getModificationOp()).isEqualTo(DirContext.ADD_ATTRIBUTE); + assertThat(modificationItem.getAttribute().getID()).isEqualTo("uniqueMember"); + assertThat(modificationItem.getAttribute().get()).isEqualTo("cn=jane doe, ou=company"); } @Test @@ -1347,7 +1332,7 @@ public class DirContextAdapterTest { tested.setAttributeValue("uniqueMember", LdapUtils.newLdapName("cn=john doe, ou=company")); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(0, modificationItems.length); + assertThat(modificationItems.length).isEqualTo(0); } @Test @@ -1360,7 +1345,7 @@ public class DirContextAdapterTest { tested.setAttributeValues("uniqueMember", new Object[]{LdapUtils.newLdapName("cn=john doe, ou=company")}); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(0, modificationItems.length); + assertThat(modificationItems.length).isEqualTo(0); } @Test @@ -1377,11 +1362,11 @@ public class DirContextAdapterTest { }); ModificationItem[] modificationItems = tested.getModificationItems(); - assertEquals(1, modificationItems.length); + assertThat(modificationItems.length).isEqualTo(1); ModificationItem modificationItem = modificationItems[0]; - assertEquals(DirContext.ADD_ATTRIBUTE, modificationItem.getModificationOp()); - assertEquals("uniqueMember", modificationItem.getAttribute().getID()); - assertEquals("cn=jane doe, ou=company", modificationItem.getAttribute().get()); + assertThat(modificationItem.getModificationOp()).isEqualTo(DirContext.ADD_ATTRIBUTE); + assertThat(modificationItem.getAttribute().getID()).isEqualTo("uniqueMember"); + assertThat(modificationItem.getAttribute().get()).isEqualTo("cn=jane doe, ou=company"); } } diff --git a/core/src/test/java/org/springframework/ldap/core/DistinguishedNameEditorTest.java b/core/src/test/java/org/springframework/ldap/core/DistinguishedNameEditorTest.java index 2f1dab2d..a9a2c0f5 100644 --- a/core/src/test/java/org/springframework/ldap/core/DistinguishedNameEditorTest.java +++ b/core/src/test/java/org/springframework/ldap/core/DistinguishedNameEditorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,10 +18,8 @@ package org.springframework.ldap.core; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Unit tests for {@link DistinguishedNameEditor}. @@ -43,14 +41,14 @@ public class DistinguishedNameEditorTest { tested.setAsText(expectedDn); DistinguishedName result = (DistinguishedName) tested.getValue(); - assertEquals(new DistinguishedName(expectedDn), result); + assertThat(result).isEqualTo(new DistinguishedName(expectedDn)); try { result.getNames().add(new LdapRdn("cn", "john doe")); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @@ -58,7 +56,7 @@ public class DistinguishedNameEditorTest { public void testSetAsTextNullValue() throws Exception { tested.setAsText(null); Object result = tested.getValue(); - assertNull(result); + assertThat(result).isNull(); } @Test @@ -66,13 +64,13 @@ public class DistinguishedNameEditorTest { String expectedDn = "dc=jayway,dc=se"; tested.setValue(new DistinguishedName(expectedDn)); String text = tested.getAsText(); - assertEquals(expectedDn, text); + assertThat(text).isEqualTo(expectedDn); } @Test public void testGetAsTextNullValue() throws Exception { tested.setValue(null); String text = tested.getAsText(); - assertNull(text); + assertThat(text).isNull(); } } diff --git a/core/src/test/java/org/springframework/ldap/core/DistinguishedNameTest.java b/core/src/test/java/org/springframework/ldap/core/DistinguishedNameTest.java index e66eb691..1e31b2ef 100644 --- a/core/src/test/java/org/springframework/ldap/core/DistinguishedNameTest.java +++ b/core/src/test/java/org/springframework/ldap/core/DistinguishedNameTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,11 +25,8 @@ import javax.naming.InvalidNameException; import javax.naming.Name; import java.util.Enumeration; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Unit tests for the {@link DistinguishedName} class. @@ -43,20 +40,20 @@ public class DistinguishedNameTest { public void testDistinguishedName_CompositeWithSlash() throws Exception { Name testPath = new CompositeName("cn=foo\\/bar"); DistinguishedName path = new DistinguishedName(testPath); - assertEquals("cn=foo/bar", path.toString()); + assertThat(path.toString()).isEqualTo("cn=foo/bar"); } @Test public void testDistinguishedName_CompositeWithSlashAsString() throws Exception { Name testPath = new CompositeName("cn=foo\\/bar"); DistinguishedName path = new DistinguishedName(testPath.toString()); - assertEquals("cn=foo/bar", path.toString()); + assertThat(path.toString()).isEqualTo("cn=foo/bar"); } @Test public void testDistinguishedName_Ldap237_NotDestroyedByCompositeName() throws InvalidNameException { DistinguishedName path = new DistinguishedName("ou=Roger \\\"Bunny\\\" Rabbit,dc=somecompany,dc=com"); - assertEquals("ou=Roger \\\"Bunny\\\" Rabbit,dc=somecompany,dc=com", path.toString()); + assertThat(path.toString()).isEqualTo("ou=Roger \\\"Bunny\\\" Rabbit,dc=somecompany,dc=com"); } /** @@ -67,7 +64,7 @@ public class DistinguishedNameTest { @Test public void testDistinguishedName_Ldap237_DestroyedByCompositeName() throws InvalidNameException { DistinguishedName path = new DistinguishedName("ou=Roger \\\\\"Bunny\\\\\" Rabbit,dc=somecompany,dc=com"); - assertEquals("ou=Roger \\\"Bunny\\\" Rabbit,dc=somecompany,dc=com", path.toString()); + assertThat(path.toString()).isEqualTo("ou=Roger \\\"Bunny\\\" Rabbit,dc=somecompany,dc=com"); } @Test @@ -78,7 +75,7 @@ public class DistinguishedNameTest { fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @@ -91,24 +88,24 @@ public class DistinguishedNameTest { DistinguishedName path = new DistinguishedName(testPath); - assertEquals("cn", path.getLdapRdn(8).getComponent().getKey()); - assertEquals("foo,bar", path.getLdapRdn(8).getComponent().getValue()); - assertEquals("ou", path.getLdapRdn(7).getComponent().getKey()); - assertEquals("FOO,bar", path.getLdapRdn(7).getComponent().getValue()); - assertEquals("ou", path.getLdapRdn(6).getComponent().getKey()); - assertEquals("foo;bar", path.getLdapRdn(6).getComponent().getValue()); - assertEquals("ou", path.getLdapRdn(5).getComponent().getKey()); - assertEquals("foo;bar", path.getLdapRdn(5).getComponent().getValue()); - assertEquals("ou", path.getLdapRdn(4).getComponent().getKey()); - assertEquals("foo,", path.getLdapRdn(4).getComponent().getValue()); - assertEquals("ou", path.getLdapRdn(3).getComponent().getKey()); - assertEquals("foo,", path.getLdapRdn(3).getComponent().getValue()); - assertEquals("ou", path.getLdapRdn(2).getComponent().getKey()); - assertEquals("foo;", path.getLdapRdn(2).getComponent().getValue()); - assertEquals("ou", path.getLdapRdn(1).getComponent().getKey()); - assertEquals("foo,", path.getLdapRdn(1).getComponent().getValue()); - assertEquals("ou", path.getLdapRdn(0).getComponent().getKey()); - assertEquals("bar,", path.getLdapRdn(0).getComponent().getValue()); + assertThat(path.getLdapRdn(8).getComponent().getKey()).isEqualTo("cn"); + assertThat(path.getLdapRdn(8).getComponent().getValue()).isEqualTo("foo,bar"); + assertThat(path.getLdapRdn(7).getComponent().getKey()).isEqualTo("ou"); + assertThat(path.getLdapRdn(7).getComponent().getValue()).isEqualTo("FOO,bar"); + assertThat(path.getLdapRdn(6).getComponent().getKey()).isEqualTo("ou"); + assertThat(path.getLdapRdn(6).getComponent().getValue()).isEqualTo("foo;bar"); + assertThat(path.getLdapRdn(5).getComponent().getKey()).isEqualTo("ou"); + assertThat(path.getLdapRdn(5).getComponent().getValue()).isEqualTo("foo;bar"); + assertThat(path.getLdapRdn(4).getComponent().getKey()).isEqualTo("ou"); + assertThat(path.getLdapRdn(4).getComponent().getValue()).isEqualTo("foo,"); + assertThat(path.getLdapRdn(3).getComponent().getKey()).isEqualTo("ou"); + assertThat(path.getLdapRdn(3).getComponent().getValue()).isEqualTo("foo,"); + assertThat(path.getLdapRdn(2).getComponent().getKey()).isEqualTo("ou"); + assertThat(path.getLdapRdn(2).getComponent().getValue()).isEqualTo("foo;"); + assertThat(path.getLdapRdn(1).getComponent().getKey()).isEqualTo("ou"); + assertThat(path.getLdapRdn(1).getComponent().getValue()).isEqualTo("foo,"); + assertThat(path.getLdapRdn(0).getComponent().getKey()).isEqualTo("ou"); + assertThat(path.getLdapRdn(0).getComponent().getValue()).isEqualTo("bar,"); } @Test @@ -120,7 +117,7 @@ public class DistinguishedNameTest { path.remove(1); path.remove(3); - assertEquals("cn=john.doe,ou=Some Company,ou=G,ou=M", path.toString()); + assertThat(path.toString()).isEqualTo("cn=john.doe,ou=Some Company,ou=G,ou=M"); } /** @@ -138,13 +135,13 @@ public class DistinguishedNameTest { DistinguishedName pathE1 = new DistinguishedName("cn=john.doe, OU=Users,OU=SE,ou=G,OU=L,OU=M, ou=foo"); DistinguishedName pathE2 = new DistinguishedName("cn=john.doe, OU=Users,OU=SE"); - assertTrue("Contains MIG", path1.contains(migpath)); - assertTrue("Contains MIG", path2.contains(migpath)); - assertTrue("Contains MIG", path3.contains(migpath)); - assertTrue("Contains MIG", path4.contains(migpath)); + assertThat(path1.contains(migpath)).isTrue(); + assertThat(path2.contains(migpath)).isTrue(); + assertThat(path3.contains(migpath)).isTrue(); + assertThat(path4.contains(migpath)).isTrue(); - assertFalse("Does not contain MIG", pathE1.contains(migpath)); - assertFalse("Does not contain MIG", pathE2.contains(migpath)); + assertThat(pathE1.contains(migpath)).isFalse(); + assertThat(pathE2.contains(migpath)).isFalse(); } @Test @@ -154,7 +151,7 @@ public class DistinguishedNameTest { path1.append(path2); - assertEquals("Append failed", "ou=baz,ou=foo,ou=bar", path1.toString()); + assertThat(path1.toString()).isEqualTo("ou=baz,ou=foo,ou=bar"); } @Test @@ -164,7 +161,7 @@ public class DistinguishedNameTest { path1.prepend(path2); - assertEquals("Append failed", "ou=foo,ou=bar,cn=fie,ou=baz", path1.toString()); + assertThat(path1.toString()).isEqualTo("ou=foo,ou=bar,cn=fie,ou=baz"); } @Test @@ -195,10 +192,10 @@ public class DistinguishedNameTest { DistinguishedName path2 = (DistinguishedName) path1.clone(); - assertEquals("Should be equal", path1, path2); + assertThat(path2).as("Should be equal").isEqualTo(path1); path2.removeFirst(); - assertFalse("Should not be equal", path1.equals(path2)); + assertThat(path1.equals(path2)).isFalse(); } @@ -210,8 +207,8 @@ public class DistinguishedNameTest { DistinguishedName path2 = new DistinguishedName("uid=mtah.test, ou=people, ou=EU, o=example.com"); DistinguishedName ending2 = new DistinguishedName("uid=mtah.test, ou=people, ou=EU"); - assertTrue(path1.endsWith(ending1)); - assertTrue(path2.endsWith(ending2)); + assertThat(path1.endsWith(ending1)).isTrue(); + assertThat(path2.endsWith(ending2)).isTrue(); } @Test @@ -222,8 +219,8 @@ public class DistinguishedNameTest { DistinguishedName path2 = new DistinguishedName("uid=mtah.test, ou=people, ou=EU, o=example.com"); DistinguishedName ending2 = new DistinguishedName("ou=EU, o=example.com"); - assertFalse(path1.endsWith(ending1)); - assertFalse(path2.endsWith(ending2)); + assertThat(path1.endsWith(ending1)).isFalse(); + assertThat(path2.endsWith(ending2)).isFalse(); } @Test @@ -233,16 +230,16 @@ public class DistinguishedNameTest { Enumeration elements = path.getAll(); String element = (String) elements.nextElement(); - assertEquals("o=example.com", element); + assertThat(element).isEqualTo("o=example.com"); element = (String) elements.nextElement(); - assertEquals("ou=EU", element); + assertThat(element).isEqualTo("ou=EU"); element = (String) elements.nextElement(); - assertEquals("ou=people", element); + assertThat(element).isEqualTo("ou=people"); element = (String) elements.nextElement(); - assertEquals("uid=mtah.test", element); + assertThat(element).isEqualTo("uid=mtah.test"); } @Test @@ -251,16 +248,16 @@ public class DistinguishedNameTest { String string = path.get(1); - assertEquals("ou=EU", string); + assertThat(string).isEqualTo("ou=EU"); } @Test public void testSize() { DistinguishedName path1 = new DistinguishedName(); - assertEquals(0, path1.size()); + assertThat(path1.size()).isEqualTo(0); DistinguishedName path2 = new DistinguishedName("uid=mtah.test, ou=people, ou=EU, o=example.com"); - assertEquals(4, path2.size()); + assertThat(path2.size()).isEqualTo(4); } @Test @@ -268,16 +265,16 @@ public class DistinguishedNameTest { DistinguishedName path = new DistinguishedName("uid=mtah.test, ou=people, ou=EU, o=example.com"); Name prefix = path.getPrefix(0); - assertEquals(0, prefix.size()); + assertThat(prefix.size()).isEqualTo(0); prefix = path.getPrefix(1); - assertEquals(1, prefix.size()); - assertEquals("o=example.com", prefix.get(0)); + assertThat(prefix.size()).isEqualTo(1); + assertThat(prefix.get(0)).isEqualTo("o=example.com"); prefix = path.getPrefix(2); - assertEquals(2, prefix.size()); - assertEquals("o=example.com", prefix.get(0)); - assertEquals("ou=EU", prefix.get(1)); + assertThat(prefix.size()).isEqualTo(2); + assertThat(prefix.get(0)).isEqualTo("o=example.com"); + assertThat(prefix.get(1)).isEqualTo("ou=EU"); } @Test @@ -285,21 +282,21 @@ public class DistinguishedNameTest { DistinguishedName path = new DistinguishedName("uid=mtah.test, ou=people, ou=EU, o=example.com"); Name suffix = path.getSuffix(0); - assertEquals(4, suffix.size()); + assertThat(suffix.size()).isEqualTo(4); suffix = path.getSuffix(2); - assertEquals(2, suffix.size()); - assertEquals("ou=people", suffix.get(0)); + assertThat(suffix.size()).isEqualTo(2); + assertThat(suffix.get(0)).isEqualTo("ou=people"); suffix = path.getSuffix(4); - assertEquals(0, suffix.size()); + assertThat(suffix.size()).isEqualTo(0); try { path.getSuffix(5); fail("ArrayIndexOutOfBoundsException expected"); } catch (ArrayIndexOutOfBoundsException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @@ -311,8 +308,8 @@ public class DistinguishedNameTest { DistinguishedName path2 = new DistinguishedName("uid=mtah.test, ou=people, ou=EU, o=example.com"); DistinguishedName start2 = new DistinguishedName("ou=people, ou=EU, o=example.com"); - assertTrue(path1.startsWith(start1)); - assertTrue(path2.startsWith(start2)); + assertThat(path1.startsWith(start1)).isTrue(); + assertThat(path2.startsWith(start2)).isTrue(); } @Test @@ -323,8 +320,8 @@ public class DistinguishedNameTest { DistinguishedName path2 = new DistinguishedName("uid=mtah.test, ou=people, ou=EU, o=example.com"); DistinguishedName start2 = new DistinguishedName("uid=mtah.test, ou=EU, ou=people"); - assertFalse(path1.startsWith(start1)); - assertFalse(path2.startsWith(start2)); + assertThat(path1.startsWith(start1)).isFalse(); + assertThat(path2.startsWith(start2)).isFalse(); } @Test @@ -333,7 +330,7 @@ public class DistinguishedNameTest { DistinguishedName path2 = new DistinguishedName("uid=mtah.test, ou=people, ou=EU, o=example.com, o=a.com"); - assertFalse(path1.startsWith(path2)); + assertThat(path1.startsWith(path2)).isFalse(); } @Test @@ -342,19 +339,19 @@ public class DistinguishedNameTest { DistinguishedName path2 = new DistinguishedName(); - assertFalse(path1.startsWith(path2)); + assertThat(path1.startsWith(path2)).isFalse(); } @Test public void testIsEmpty_True() { DistinguishedName path = new DistinguishedName(); - assertTrue(path.isEmpty()); + assertThat(path.isEmpty()).isTrue(); } @Test public void testIsEmpty_False() { DistinguishedName path = new DistinguishedName("o=example.com"); - assertFalse(path.isEmpty()); + assertThat(path.isEmpty()).isFalse(); } @Test @@ -364,7 +361,7 @@ public class DistinguishedNameTest { path1.addAll(path2); - assertEquals("AddAll failed", "ou=baz,ou=foo,ou=bar", path1.toString()); + assertThat(path1.toString()).isEqualTo("ou=baz,ou=foo,ou=bar"); } @Test @@ -374,7 +371,7 @@ public class DistinguishedNameTest { path1.addAll(1, path2); - assertEquals("AddAll failed", "ou=foo,ou=baz,ou=bar", path1.toString()); + assertThat(path1.toString()).isEqualTo("ou=foo,ou=baz,ou=bar"); } @Test @@ -382,7 +379,7 @@ public class DistinguishedNameTest { DistinguishedName path1 = new DistinguishedName("ou=foo, ou=bar"); path1.add("ou=baz"); - assertEquals("Add failed", "ou=baz,ou=foo,ou=bar", path1.toString()); + assertThat(path1.toString()).isEqualTo("ou=baz,ou=foo,ou=bar"); } @Test @@ -390,7 +387,7 @@ public class DistinguishedNameTest { DistinguishedName path1 = new DistinguishedName("ou=foo, ou=bar"); path1.add(1, "ou=baz"); - assertEquals("Add failed", "ou=foo,ou=baz,ou=bar", path1.toString()); + assertThat(path1.toString()).isEqualTo("ou=foo,ou=baz,ou=bar"); } @Test @@ -398,14 +395,14 @@ public class DistinguishedNameTest { DistinguishedName path = new DistinguishedName("dc=jayway, dc=se"); String url = path.toUrl(); - assertEquals("dc=jayway,dc=se", url); + assertThat(url).isEqualTo("dc=jayway,dc=se"); } @Test public void testMultiValueRdn() throws Exception { DistinguishedName path = new DistinguishedName("firstName=Rod+lastName=Johnson,ou=UK,dc=interface21,dc=com"); - assertEquals(4, path.size()); - assertEquals("firstname=Rod+lastname=Johnson", path.get(3)); + assertThat(path.size()).isEqualTo(4); + assertThat(path.get(3)).isEqualTo("firstname=Rod+lastname=Johnson"); } @Test @@ -414,7 +411,7 @@ public class DistinguishedNameTest { DistinguishedName name2 = new DistinguishedName("cn=john doe, ou=Some company, c=SE"); int result = name1.compareTo(name2); - assertEquals(0, result); + assertThat(result).isEqualTo(0); } @Test @@ -423,7 +420,7 @@ public class DistinguishedNameTest { DistinguishedName name2 = new DistinguishedName("cn=john doe, ou=Some company, c=SE"); int result = name1.compareTo(name2); - assertTrue(result < 0); + assertThat(result < 0).isTrue(); } @Test @@ -432,7 +429,7 @@ public class DistinguishedNameTest { DistinguishedName name2 = new DistinguishedName("cn=john doe, ou=Some company, c=SE"); int result = name1.compareTo(name2); - assertTrue(result < 0); + assertThat(result < 0).isTrue(); } @Test @@ -441,7 +438,7 @@ public class DistinguishedNameTest { DistinguishedName name2 = new DistinguishedName("cn=john doe, ou=Some company, c=DK"); int result = name1.compareTo(name2); - assertTrue(result > 0); + assertThat(result > 0).isTrue(); } @Test @@ -450,7 +447,7 @@ public class DistinguishedNameTest { DistinguishedName name2 = new DistinguishedName("cn=john doe, ou=Some company, c=SE"); int result = name1.compareTo(name2); - assertTrue(result > 0); + assertThat(result > 0).isTrue(); } @Test @@ -459,14 +456,14 @@ public class DistinguishedNameTest { DistinguishedName name2 = new DistinguishedName("leaf=someleaf, cn=john doe, ou=Some company, c=SE"); int result = name1.compareTo(name2); - assertTrue(result < 0); + assertThat(result < 0).isTrue(); } @Test public void testGetLdapRdnForKey() throws Exception { DistinguishedName dn = new DistinguishedName("cn=john doe, ou=Some company, c=SE"); LdapRdn ldapRdn = dn.getLdapRdn("ou"); - assertEquals(new LdapRdn("ou=Some company"), ldapRdn); + assertThat(ldapRdn).isEqualTo(new LdapRdn("ou=Some company")); } @Test(expected = IllegalArgumentException.class) @@ -479,7 +476,7 @@ public class DistinguishedNameTest { public void testGetValue() throws Exception { DistinguishedName dn = new DistinguishedName("cn=john doe, ou=Some company, c=SE"); String value = dn.getValue("ou"); - assertEquals("Some company", value); + assertThat(value).isEqualTo("Some company"); } @Test(expected = IllegalArgumentException.class) @@ -491,7 +488,7 @@ public class DistinguishedNameTest { @Test public void test_longDN() throws InvalidNameException { DistinguishedName name = new DistinguishedName(""); - assertNotNull(name); + assertThat(name).isNotNull(); } /** @@ -500,7 +497,7 @@ public class DistinguishedNameTest { @Test public void testParseAtSign() { DistinguishedName name = new DistinguishedName("cn=testname@example.com"); - assertNotNull(name); + assertThat(name).isNotNull(); } /** @@ -509,7 +506,7 @@ public class DistinguishedNameTest { @Test public void testParseAtSign2() { DistinguishedName name = new DistinguishedName("cn=te\\+stname@example.com"); - assertNotNull(name); + assertThat(name).isNotNull(); } /** @@ -526,7 +523,7 @@ public class DistinguishedNameTest { @Test public void testParseValidQuotation() { DistinguishedName name = new DistinguishedName("cn=jo\"hn doe"); - assertNotNull(name); + assertThat(name).isNotNull(); } @Test @@ -534,7 +531,7 @@ public class DistinguishedNameTest { DistinguishedName tested = new DistinguishedName("dc=mycompany,dc=com"); tested.append("ou", "company1").append("cn", "john doe"); - assertEquals("cn=john doe,ou=company1,dc=mycompany,dc=com", tested.toString()); + assertThat(tested.toString()).isEqualTo("cn=john doe,ou=company1,dc=mycompany,dc=com"); } @Test(expected = UnsupportedOperationException.class) @@ -571,7 +568,7 @@ public class DistinguishedNameTest { public void testUnmodifiableDistinguishedNameEqualsIdenticalMutableOne() throws Exception { DistinguishedName immutable = DistinguishedName.immutableDistinguishedName("cn=john doe"); DistinguishedName mutable = new DistinguishedName("cn=john doe"); - assertTrue(immutable.equals(mutable)); + assertThat(immutable.equals(mutable)).isTrue(); } /** @@ -580,7 +577,7 @@ public class DistinguishedNameTest { @Test public void testDistinguishedNameWithCRParsesProperly() { DistinguishedName name = new DistinguishedName("cn=foo \r bar"); - assertNotNull(name); + assertThat(name).isNotNull(); } /** @@ -589,13 +586,13 @@ public class DistinguishedNameTest { @Test public void testDistinguishedNameWithDotParsesProperly() { DistinguishedName name = new DistinguishedName("cn=first.last,OU=DevTest Users,DC=xyz,DC=com"); - assertEquals("cn=first.last,ou=DevTest Users,dc=xyz,dc=com", name.toCompactString()); + assertThat(name.toCompactString()).isEqualTo("cn=first.last,ou=DevTest Users,dc=xyz,dc=com"); DistinguishedName dn = new DistinguishedName(); dn.parse("cn=first.last,OU=DevTest Users,DC=xyz,DC=com"); - assertEquals("first.last", dn.getValue("cn")); - assertEquals("DevTest Users", dn.getValue("ou")); - assertEquals("xyz", dn.getLdapRdn(1).getValue()); - assertEquals("com", dn.getLdapRdn(0).getValue()); + assertThat(dn.getValue("cn")).isEqualTo("first.last"); + assertThat(dn.getValue("ou")).isEqualTo("DevTest Users"); + assertThat(dn.getLdapRdn(1).getValue()).isEqualTo("xyz"); + assertThat(dn.getLdapRdn(0).getValue()).isEqualTo("com"); } @Test @@ -603,9 +600,9 @@ public class DistinguishedNameTest { try { DistinguishedName name = new DistinguishedName("cn=john doe, ou=company"); // First check the default - assertEquals("cn=john doe,ou=company", name.toString()); + assertThat(name.toString()).isEqualTo("cn=john doe,ou=company"); System.setProperty(DistinguishedName.SPACED_DN_FORMAT_PROPERTY, "true"); - assertEquals("cn=john doe, ou=company", name.toString()); + assertThat(name.toString()).isEqualTo("cn=john doe, ou=company"); } finally { // Always restore the system setting @@ -620,12 +617,12 @@ public class DistinguishedNameTest { DistinguishedName name = new DistinguishedName(dnString); // First check the default - assertEquals("ou=foo,ou=bar,ou=baz,ou=bim", name.toString()); + assertThat(name.toString()).isEqualTo("ou=foo,ou=bar,ou=baz,ou=bim"); System.setProperty(DistinguishedName.KEY_CASE_FOLD_PROPERTY, DistinguishedName.KEY_CASE_FOLD_NONE); name = new DistinguishedName(dnString); System.out.println(dnString + " folded as \"" + DistinguishedName.KEY_CASE_FOLD_NONE + "\": " + name); - assertEquals(dnString, name.toString()); + assertThat(name.toString()).isEqualTo(dnString); } finally { // Always restore the system setting @@ -640,12 +637,12 @@ public class DistinguishedNameTest { DistinguishedName name = new DistinguishedName(dnString); // First check the default - assertEquals("ou=foo,ou=bar,ou=baz,ou=bim", name.toString()); + assertThat(name.toString()).isEqualTo("ou=foo,ou=bar,ou=baz,ou=bim"); System.setProperty(DistinguishedName.KEY_CASE_FOLD_PROPERTY, DistinguishedName.KEY_CASE_FOLD_UPPER); name = new DistinguishedName(dnString); System.out.println(dnString + " folded as \"" + DistinguishedName.KEY_CASE_FOLD_UPPER + "\": " + name); - assertEquals("OU=foo,OU=bar,OU=baz,OU=bim", name.toString()); + assertThat(name.toString()).isEqualTo("OU=foo,OU=bar,OU=baz,OU=bim"); } finally { // Always restore the system setting @@ -660,12 +657,12 @@ public class DistinguishedNameTest { DistinguishedName name = new DistinguishedName(dnString); // First check the default - assertEquals("ou=foo,ou=bar,ou=baz,ou=bim", name.toString()); + assertThat(name.toString()).isEqualTo("ou=foo,ou=bar,ou=baz,ou=bim"); System.setProperty(DistinguishedName.KEY_CASE_FOLD_PROPERTY, DistinguishedName.KEY_CASE_FOLD_LOWER); name = new DistinguishedName(dnString); System.out.println(dnString + " folded as \"" + DistinguishedName.KEY_CASE_FOLD_LOWER + "\": " + name); - assertEquals("ou=foo,ou=bar,ou=baz,ou=bim", name.toString()); + assertThat(name.toString()).isEqualTo("ou=foo,ou=bar,ou=baz,ou=bim"); } finally { // Always restore the system setting @@ -680,12 +677,12 @@ public class DistinguishedNameTest { DistinguishedName name = new DistinguishedName(dnString); // First check the default - assertEquals("ou=foo,ou=bar,ou=baz,ou=bim", name.toString()); + assertThat(name.toString()).isEqualTo("ou=foo,ou=bar,ou=baz,ou=bim"); System.setProperty(DistinguishedName.KEY_CASE_FOLD_PROPERTY, "whatever"); name = new DistinguishedName(dnString); System.out.println(dnString + " folded as \"whatever\": " + name); - assertEquals("ou=foo,ou=bar,ou=baz,ou=bim", name.toString()); + assertThat(name.toString()).isEqualTo("ou=foo,ou=bar,ou=baz,ou=bim"); } finally { // Always restore the system setting @@ -695,25 +692,19 @@ public class DistinguishedNameTest { @Test public void testHashSignLdap229() { - assertEquals( - new DistinguishedName("cn=Foo\\#Bar"), - new DistinguishedName("cn=Foo#Bar") - ); + assertThat(new DistinguishedName("cn=Foo\\#Bar")).isEqualTo( + new DistinguishedName("cn=Foo#Bar")); } @Test public void testEqualsSignLdap229() { - assertEquals( - new DistinguishedName("cn=Foo\\=Bar"), - new DistinguishedName("cn=Foo=Bar") - ); + assertThat(new DistinguishedName("cn=Foo\\=Bar")).isEqualTo( + new DistinguishedName("cn=Foo=Bar")); } @Test public void testSpaceSignLdap229() { - assertEquals( - new DistinguishedName("cn=Foo\\ Bar"), - new DistinguishedName("cn=Foo Bar") - ); + assertThat(new DistinguishedName("cn=Foo\\ Bar")).isEqualTo( + new DistinguishedName("cn=Foo Bar")); } } diff --git a/core/src/test/java/org/springframework/ldap/core/LdapRdnComponentTest.java b/core/src/test/java/org/springframework/ldap/core/LdapRdnComponentTest.java index 5b49b330..74c7003b 100644 --- a/core/src/test/java/org/springframework/ldap/core/LdapRdnComponentTest.java +++ b/core/src/test/java/org/springframework/ldap/core/LdapRdnComponentTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,8 +17,7 @@ package org.springframework.ldap.core; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for LdapRdnComponent. @@ -32,7 +31,7 @@ public class LdapRdnComponentTest { LdapRdnComponent component1 = new LdapRdnComponent("cn", "john doe"); LdapRdnComponent component2 = new LdapRdnComponent("sn", "doe"); int result = component1.compareTo(component2); - assertTrue(result < 0); + assertThat(result < 0).isTrue(); } @Test @@ -40,7 +39,7 @@ public class LdapRdnComponentTest { LdapRdnComponent component1 = new LdapRdnComponent("sn", "doe"); LdapRdnComponent component2 = new LdapRdnComponent("cn", "john doe"); int result = component1.compareTo(component2); - assertTrue(result > 0); + assertThat(result > 0).isTrue(); } @Test @@ -48,7 +47,7 @@ public class LdapRdnComponentTest { LdapRdnComponent component1 = new LdapRdnComponent("cn", "john doe"); LdapRdnComponent component2 = new LdapRdnComponent("cn", "john doe"); int result = component1.compareTo(component2); - assertEquals(0, result); + assertThat(result).isEqualTo(0); } @Test @@ -56,8 +55,8 @@ public class LdapRdnComponentTest { LdapRdnComponent component1 = new LdapRdnComponent("cn", "john doe"); LdapRdnComponent component2 = new LdapRdnComponent("CN", "John Doe"); - assertEquals("Should be equal", component1, component2); - assertTrue("0 should be returned by compareTo", component1.compareTo(component2) == 0); + assertThat(component2).as("Should be equal").isEqualTo(component1); + assertThat(component1.compareTo(component2) == 0).as("0 should be returned by compareTo").isTrue(); } @Test @@ -65,7 +64,7 @@ public class LdapRdnComponentTest { LdapRdnComponent component1 = new LdapRdnComponent("cn", "john doe"); LdapRdnComponent component2 = new LdapRdnComponent("CN", "John Doe"); - assertEquals("Should be equal", component1.hashCode(), component2.hashCode()); + assertThat(component2.hashCode()).as("Should be equal").isEqualTo(component1.hashCode()); } -} \ No newline at end of file +} diff --git a/core/src/test/java/org/springframework/ldap/core/LdapRdnTest.java b/core/src/test/java/org/springframework/ldap/core/LdapRdnTest.java index 16dfa888..19dce0b0 100644 --- a/core/src/test/java/org/springframework/ldap/core/LdapRdnTest.java +++ b/core/src/test/java/org/springframework/ldap/core/LdapRdnTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,7 @@ import com.gargoylesoftware.base.testing.EqualsTester; import org.junit.Test; import org.springframework.ldap.BadLdapGrammarException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Unit test for the LdapRdn class. @@ -35,11 +34,11 @@ public class LdapRdnTest { LdapRdn rdn = new LdapRdn("foo=bar"); - assertEquals("foo", rdn.getComponent().getKey()); - assertEquals("bar", rdn.getComponent().getValue()); - assertEquals("foo=bar", rdn.getComponent().getLdapEncoded()); - assertEquals("foo", rdn.getKey()); - assertEquals("bar", rdn.getValue()); + assertThat(rdn.getComponent().getKey()).isEqualTo("foo"); + assertThat(rdn.getComponent().getValue()).isEqualTo("bar"); + assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=bar"); + assertThat(rdn.getKey()).isEqualTo("foo"); + assertThat(rdn.getValue()).isEqualTo("bar"); } @Test @@ -47,9 +46,9 @@ public class LdapRdnTest { LdapRdn rdn = new LdapRdn(" foo = bar "); - assertEquals("foo", rdn.getComponent().getKey()); - assertEquals("bar", rdn.getComponent().getValue()); - assertEquals("foo=bar", rdn.getComponent().getLdapEncoded()); + assertThat(rdn.getComponent().getKey()).isEqualTo("foo"); + assertThat(rdn.getComponent().getValue()).isEqualTo("bar"); + assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=bar"); } @Test @@ -57,9 +56,9 @@ public class LdapRdnTest { LdapRdn rdn = new LdapRdn("foo=bar\\=fum"); - assertEquals("foo", rdn.getComponent().getKey()); - assertEquals("bar=fum", rdn.getComponent().getValue()); - assertEquals("foo=bar\\=fum", rdn.getComponent().getLdapEncoded()); + assertThat(rdn.getComponent().getKey()).isEqualTo("foo"); + assertThat(rdn.getComponent().getValue()).isEqualTo("bar=fum"); + assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=bar\\=fum"); } @Test @@ -67,9 +66,9 @@ public class LdapRdnTest { LdapRdn rdn = new LdapRdn("foo=bar\\0dfum"); - assertEquals("foo", rdn.getComponent().getKey()); - assertEquals("bar\rfum", rdn.getComponent().getValue()); - assertEquals("foo=bar\\0Dfum", rdn.getComponent().getLdapEncoded()); + assertThat(rdn.getComponent().getKey()).isEqualTo("foo"); + assertThat(rdn.getComponent().getValue()).isEqualTo("bar\rfum"); + assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=bar\\0Dfum"); } @Test(expected = BadLdapGrammarException.class) @@ -81,9 +80,9 @@ public class LdapRdnTest { public void testLdapRdn_parse_spaces_escape() { LdapRdn rdn = new LdapRdn(" foo = \\ bar\\20 \\ "); - assertEquals("foo", rdn.getComponent().getKey()); - assertEquals(" bar ", rdn.getComponent().getValue()); - assertEquals("foo=\\ bar \\ ", rdn.getComponent().getLdapEncoded()); + assertThat(rdn.getComponent().getKey()).isEqualTo("foo"); + assertThat(rdn.getComponent().getValue()).isEqualTo(" bar "); + assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=\\ bar \\ "); } @Test(expected = BadLdapGrammarException.class) @@ -95,11 +94,9 @@ public class LdapRdnTest { public void testLdapRdn_parse_slash() { LdapRdn rdn = new LdapRdn("ou=Clerical / Secretarial Staff"); - assertEquals("ou", rdn.getComponent().getKey()); - assertEquals("Clerical / Secretarial Staff", rdn.getComponent() - .getValue()); - assertEquals("ou=Clerical / Secretarial Staff", rdn.getComponent() - .getLdapEncoded()); + assertThat(rdn.getComponent().getKey()).isEqualTo("ou"); + assertThat(rdn.getComponent().getValue()).isEqualTo("Clerical / Secretarial Staff"); + assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("ou=Clerical / Secretarial Staff"); } @Test(expected = BadLdapGrammarException.class) @@ -111,42 +108,42 @@ public class LdapRdnTest { public void testLdapRdn_KeyValue_simple() { LdapRdn rdn = new LdapRdn("foo", "bar"); - assertEquals("foo", rdn.getComponent().getKey()); - assertEquals("bar", rdn.getComponent().getValue()); - assertEquals("foo=bar", rdn.getComponent().getLdapEncoded()); + assertThat(rdn.getComponent().getKey()).isEqualTo("foo"); + assertThat(rdn.getComponent().getValue()).isEqualTo("bar"); + assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=bar"); } @Test public void testLdapRdn_KeyValue_valueNeedsEscape() { LdapRdn rdn = new LdapRdn("foo", "bar\\"); - assertEquals("foo", rdn.getComponent().getKey()); - assertEquals("bar\\", rdn.getComponent().getValue()); - assertEquals("foo=bar\\\\", rdn.getComponent().getLdapEncoded()); + assertThat(rdn.getComponent().getKey()).isEqualTo("foo"); + assertThat(rdn.getComponent().getValue()).isEqualTo("bar\\"); + assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=bar\\\\"); } @Test public void testEncodeUrl() { LdapRdn rdn = new LdapRdn("o = example.com "); - assertEquals("o=example.com", rdn.encodeUrl()); + assertThat(rdn.encodeUrl()).isEqualTo("o=example.com"); } @Test public void testEncodeUrl_SpacesInValue() { LdapRdn rdn = new LdapRdn("o = my organization "); - assertEquals("o=my%20organization", rdn.encodeUrl()); + assertThat(rdn.encodeUrl()).isEqualTo("o=my%20organization"); } @Test public void testLdapRdn_Parse_MultipleComponents() { LdapRdn rdn = new LdapRdn("cn=John Doe+sn=Doe"); - assertEquals("cn=John Doe", rdn.getComponent(0).encodeLdap()); - assertEquals("sn=Doe", rdn.getComponent(1).encodeLdap()); - assertEquals("cn=John Doe+sn=Doe", rdn.getLdapEncoded()); - assertEquals("cn", rdn.getKey()); - assertEquals("John Doe", rdn.getValue()); - assertEquals("John Doe", rdn.getValue("cn")); - assertEquals("Doe", rdn.getValue("sn")); + assertThat(rdn.getComponent(0).encodeLdap()).isEqualTo("cn=John Doe"); + assertThat(rdn.getComponent(1).encodeLdap()).isEqualTo("sn=Doe"); + assertThat(rdn.getLdapEncoded()).isEqualTo("cn=John Doe+sn=Doe"); + assertThat(rdn.getKey()).isEqualTo("cn"); + assertThat(rdn.getValue()).isEqualTo("John Doe"); + assertThat(rdn.getValue("cn")).isEqualTo("John Doe"); + assertThat(rdn.getValue("sn")).isEqualTo("Doe"); } @Test(expected = IllegalArgumentException.class) @@ -187,7 +184,7 @@ public class LdapRdnTest { LdapRdn rdn2 = new LdapRdn("cn=john doe"); int result = rdn1.compareTo(rdn2); - assertEquals(0, result); + assertThat(result).isEqualTo(0); } @Test @@ -195,7 +192,7 @@ public class LdapRdnTest { LdapRdn rdn1 = new LdapRdn("cn=john doe+sn=doe"); LdapRdn rdn2 = new LdapRdn("sn=doe+cn=john doe"); - assertEquals("Should be equal", rdn1, rdn2); + assertThat(rdn2).as("Should be equal").isEqualTo(rdn1); } @Test @@ -203,7 +200,7 @@ public class LdapRdnTest { LdapRdn rdn1 = new LdapRdn("cn=john doe+sn=doe"); LdapRdn rdn2 = new LdapRdn("sn=doe+cn=john doe"); - assertEquals("Should be equal", rdn1.hashCode(), rdn2.hashCode()); + assertThat(rdn2.hashCode()).as("Should be equal").isEqualTo(rdn1.hashCode()); } @Test @@ -212,7 +209,7 @@ public class LdapRdnTest { LdapRdn rdn2 = new LdapRdn("cn=john doe+sn=doe"); int result = rdn1.compareTo(rdn2); - assertEquals(0, result); + assertThat(result).isEqualTo(0); } @Test @@ -221,7 +218,7 @@ public class LdapRdnTest { LdapRdn rdn2 = new LdapRdn("cn=john doe+tn=doe"); int result = rdn1.compareTo(rdn2); - assertTrue(result < 0); + assertThat(result < 0).isTrue(); } @Test @@ -230,7 +227,7 @@ public class LdapRdnTest { LdapRdn rdn2 = new LdapRdn("cn=john doe+sn=doe"); int result = rdn1.compareTo(rdn2); - assertTrue(result < 0); + assertThat(result < 0).isTrue(); } @Test @@ -239,7 +236,7 @@ public class LdapRdnTest { LdapRdn rdn2 = new LdapRdn("cn=john doe+sn=doa"); int result = rdn1.compareTo(rdn2); - assertTrue(result > 0); + assertThat(result > 0).isTrue(); } @Test @@ -248,7 +245,7 @@ public class LdapRdnTest { LdapRdn rdn2 = new LdapRdn("cn=john doe+sn=doe+description=tjo"); int result = rdn1.compareTo(rdn2); - assertTrue(result < 0); + assertThat(result < 0).isTrue(); } @Test @@ -257,6 +254,6 @@ public class LdapRdnTest { LdapRdn rdn2 = new LdapRdn("cn=john doe+sn=doe"); int result = rdn1.compareTo(rdn2); - assertTrue(result > 0); + assertThat(result > 0).isTrue(); } } diff --git a/core/src/test/java/org/springframework/ldap/core/LdapTemplateListTest.java b/core/src/test/java/org/springframework/ldap/core/LdapTemplateListTest.java index 76632c83..8ad6e4d5 100644 --- a/core/src/test/java/org/springframework/ldap/core/LdapTemplateListTest.java +++ b/core/src/test/java/org/springframework/ldap/core/LdapTemplateListTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,11 +30,8 @@ import javax.naming.directory.DirContext; import javax.naming.ldap.LdapContext; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -137,9 +134,9 @@ public class LdapTemplateListTest { verify(dirContextMock).close(); verify(namingEnumerationMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(NAME, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(NAME); } @Test @@ -155,9 +152,9 @@ public class LdapTemplateListTest { verify(dirContextMock).close(); verify(namingEnumerationMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(NAME, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(NAME); } @Test @@ -201,7 +198,7 @@ public class LdapTemplateListTest { tested.list(NAME); fail("PartialResultException expected"); } catch (PartialResultException expected) { - assertTrue(true); + assertThat(true).isTrue(); } verify(dirContextMock).close(); @@ -220,8 +217,8 @@ public class LdapTemplateListTest { verify(dirContextMock).close(); - assertNotNull(list); - assertEquals(0, list.size()); + assertThat(list).isNotNull(); + assertThat(list).isEmpty(); } @Test @@ -235,7 +232,7 @@ public class LdapTemplateListTest { tested.list(NAME); fail("LimitExceededException expected"); } catch (LimitExceededException expected) { - assertTrue(true); + assertThat(true).isTrue(); } verify(dirContextMock).close(); @@ -256,9 +253,9 @@ public class LdapTemplateListTest { verify(dirContextMock).close(); verify(namingEnumerationMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(NAME, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(NAME); } @Test @@ -274,9 +271,9 @@ public class LdapTemplateListTest { verify(dirContextMock).close(); verify(namingEnumerationMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(NAME, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(NAME); } @Test @@ -296,9 +293,9 @@ public class LdapTemplateListTest { verify(dirContextMock).close(); verify(namingEnumerationMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(expectedResult, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(expectedResult); } @Test @@ -318,8 +315,8 @@ public class LdapTemplateListTest { verify(dirContextMock).close(); verify(namingEnumerationMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(expectedResult, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(expectedResult); } } diff --git a/core/src/test/java/org/springframework/ldap/core/LdapTemplateLookupTest.java b/core/src/test/java/org/springframework/ldap/core/LdapTemplateLookupTest.java index 9d6a38eb..565da722 100644 --- a/core/src/test/java/org/springframework/ldap/core/LdapTemplateLookupTest.java +++ b/core/src/test/java/org/springframework/ldap/core/LdapTemplateLookupTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,9 +29,8 @@ import javax.naming.directory.DirContext; import javax.naming.ldap.LdapContext; import javax.naming.ldap.LdapName; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -88,7 +87,7 @@ public class LdapTemplateLookupTest { verify(dirContextMock).close(); - assertSame(expected, actual); + assertThat(actual).isSameAs(expected); } @Test @@ -102,7 +101,7 @@ public class LdapTemplateLookupTest { verify(dirContextMock).close(); - assertSame(expected, actual); + assertThat(actual).isSameAs(expected); } @Test @@ -116,7 +115,7 @@ public class LdapTemplateLookupTest { tested.lookup(nameMock); fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } verify(dirContextMock).close(); @@ -138,7 +137,7 @@ public class LdapTemplateLookupTest { verify(dirContextMock).close(); - assertSame(expected, actual); + assertThat(actual).isSameAs(expected); } @Test @@ -156,7 +155,7 @@ public class LdapTemplateLookupTest { verify(dirContextMock).close(); - assertSame(expected, actual); + assertThat(actual).isSameAs(expected); } @Test @@ -170,7 +169,7 @@ public class LdapTemplateLookupTest { tested.lookup(nameMock, attributesMapperMock); fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } verify(dirContextMock).close(); @@ -192,7 +191,7 @@ public class LdapTemplateLookupTest { verify(dirContextMock).close(); - assertSame(transformed, actual); + assertThat(actual).isSameAs(transformed); } @Test @@ -208,7 +207,7 @@ public class LdapTemplateLookupTest { // Perform test Object result = tested.findByDn(nameMock, expectedClass); - assertSame(transformed, result); + assertThat(result).isSameAs(transformed); verify(odmMock).manageClass(expectedClass); } @@ -229,7 +228,7 @@ public class LdapTemplateLookupTest { verify(dirContextMock).close(); - assertSame(transformed, actual); + assertThat(actual).isSameAs(transformed); } @Test @@ -243,7 +242,7 @@ public class LdapTemplateLookupTest { tested.lookup(nameMock, contextMapperMock); fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } verify(dirContextMock).close(); @@ -270,7 +269,7 @@ public class LdapTemplateLookupTest { verify(dirContextMock).close(); - assertSame(expected, actual); + assertThat(actual).isSameAs(expected); } @Test @@ -293,7 +292,7 @@ public class LdapTemplateLookupTest { verify(dirContextMock).close(); - assertSame(expected, actual); + assertThat(actual).isSameAs(expected); } // Tests for lookup(name, attributes, ContextMapper) @@ -320,7 +319,7 @@ public class LdapTemplateLookupTest { verify(dirContextMock).close(); - assertSame(transformed, actual); + assertThat(actual).isSameAs(transformed); } @Test @@ -347,6 +346,6 @@ public class LdapTemplateLookupTest { verify(dirContextMock).close(); - assertSame(transformed, actual); + assertThat(actual).isSameAs(transformed); } } diff --git a/core/src/test/java/org/springframework/ldap/core/LdapTemplateRenameTest.java b/core/src/test/java/org/springframework/ldap/core/LdapTemplateRenameTest.java index 913d749b..f0d4adad 100644 --- a/core/src/test/java/org/springframework/ldap/core/LdapTemplateRenameTest.java +++ b/core/src/test/java/org/springframework/ldap/core/LdapTemplateRenameTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,8 +25,8 @@ import javax.naming.Name; import javax.naming.directory.DirContext; import javax.naming.ldap.LdapContext; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -91,7 +91,7 @@ public class LdapTemplateRenameTest { tested.rename(oldNameMock, newNameMock); fail("NameAlreadyBoundException expected"); } catch (NameAlreadyBoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } verify(dirContextMock).close(); @@ -109,7 +109,7 @@ public class LdapTemplateRenameTest { tested.rename(oldNameMock, newNameMock); fail("UncategorizedLdapException expected"); } catch (UncategorizedLdapException expected) { - assertTrue(true); + assertThat(true).isTrue(); } verify(dirContextMock).close(); diff --git a/core/src/test/java/org/springframework/ldap/core/LdapTemplateTest.java b/core/src/test/java/org/springframework/ldap/core/LdapTemplateTest.java index 386f4308..908f2172 100644 --- a/core/src/test/java/org/springframework/ldap/core/LdapTemplateTest.java +++ b/core/src/test/java/org/springframework/ldap/core/LdapTemplateTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,12 +49,8 @@ import javax.naming.ldap.LdapName; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.mockito.Matchers.any; import static org.mockito.Matchers.argThat; import static org.mockito.Matchers.eq; @@ -228,7 +224,7 @@ public class LdapTemplateTest { fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } verify(dirContextMock).close(); } @@ -320,9 +316,9 @@ public class LdapTemplateTest { verify(namingEnumerationMock).close(); verify(dirContextMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(expectedResult, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(expectedResult); } @Test @@ -347,9 +343,9 @@ public class LdapTemplateTest { verify(namingEnumerationMock).close(); verify(dirContextMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(expectedResult, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(expectedResult); } @Test @@ -374,9 +370,9 @@ public class LdapTemplateTest { verify(namingEnumerationMock).close(); verify(dirContextMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(expectedResult, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(expectedResult); } @Test @@ -400,9 +396,9 @@ public class LdapTemplateTest { verify(namingEnumerationMock).close(); verify(dirContextMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(expectedResult, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(expectedResult); } @Test @@ -428,9 +424,9 @@ public class LdapTemplateTest { verify(namingEnumerationMock).close(); verify(dirContextMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(expectedResult, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(expectedResult); } @Test @@ -456,9 +452,9 @@ public class LdapTemplateTest { verify(namingEnumerationMock).close(); verify(dirContextMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(expectedResult, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(expectedResult); } @Test @@ -488,9 +484,9 @@ public class LdapTemplateTest { verify(namingEnumerationMock).close(); verify(dirContextMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(expectedResult, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(expectedResult); } @Test @@ -513,9 +509,9 @@ public class LdapTemplateTest { verify(namingEnumerationMock).close(); verify(dirContextMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(expectedResult, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(expectedResult); } @Test @@ -538,9 +534,9 @@ public class LdapTemplateTest { verify(namingEnumerationMock).close(); verify(dirContextMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(expectedResult, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(expectedResult); } @Test @@ -563,9 +559,9 @@ public class LdapTemplateTest { verify(namingEnumerationMock).close(); verify(dirContextMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(expectedResult, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(expectedResult); } @Test @@ -588,9 +584,9 @@ public class LdapTemplateTest { verify(namingEnumerationMock).close(); verify(dirContextMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(expectedResult, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(expectedResult); } @Test @@ -609,9 +605,9 @@ public class LdapTemplateTest { verify(namingEnumerationMock).close(); verify(dirContextMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(expectedResult, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(expectedResult); } @Test @@ -635,7 +631,7 @@ public class LdapTemplateTest { verify(namingEnumerationMock).close(); verify(dirContextMock).close(); - assertSame(expectedResult, result); + assertThat(result).isSameAs(expectedResult); } @Test @@ -652,7 +648,7 @@ public class LdapTemplateTest { tested.findOne(query().where("ou").is("somevalue"), expectedClass); fail("EmptyResultDataAccessException expected"); } catch (EmptyResultDataAccessException expected) { - assertTrue(true); + assertThat(true).isTrue(); } verify(namingEnumerationMock).close(); @@ -680,7 +676,7 @@ public class LdapTemplateTest { tested.findOne(query().where("ou").is("somevalue"), expectedClass); fail("EmptyResultDataAccessException expected"); } catch (IncorrectResultSizeDataAccessException expected) { - assertTrue(true); + assertThat(true).isTrue(); } verify(namingEnumerationMock).close(); @@ -709,9 +705,9 @@ public class LdapTemplateTest { verify(namingEnumerationMock).close(); verify(dirContextMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(expectedResult, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(expectedResult); } @Test @@ -736,9 +732,9 @@ public class LdapTemplateTest { verify(namingEnumerationMock).close(); verify(dirContextMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(expectedResult, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(expectedResult); } @Test @@ -761,9 +757,9 @@ public class LdapTemplateTest { verify(namingEnumerationMock).close(); verify(dirContextMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(expectedResult, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(expectedResult); } @Test @@ -783,9 +779,9 @@ public class LdapTemplateTest { verify(namingEnumerationMock).close(); verify(dirContextMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(expectedResult, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(expectedResult); } @Test @@ -807,9 +803,9 @@ public class LdapTemplateTest { verify(namingEnumerationMock).close(); verify(dirContextMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(expectedResult, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(expectedResult); } @Test @@ -831,9 +827,9 @@ public class LdapTemplateTest { verify(namingEnumerationMock).close(); verify(dirContextMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(expectedResult, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(expectedResult); } @Test @@ -860,9 +856,9 @@ public class LdapTemplateTest { verify(namingEnumerationMock).close(); verify(dirContextMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(expectedResult, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(expectedResult); } @Test @@ -884,9 +880,9 @@ public class LdapTemplateTest { verify(namingEnumerationMock).close(); verify(dirContextMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(expectedResult, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(expectedResult); } @Test @@ -909,9 +905,9 @@ public class LdapTemplateTest { verify(namingEnumerationMock).close(); verify(dirContextMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(expectedResult, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(expectedResult); } @Test @@ -934,9 +930,9 @@ public class LdapTemplateTest { verify(namingEnumerationMock).close(); verify(dirContextMock).close(); - assertNotNull(list); - assertEquals(1, list.size()); - assertSame(expectedResult, list.get(0)); + assertThat(list).isNotNull(); + assertThat(list).hasSize(1); + assertThat(list.get(0)).isSameAs(expectedResult); } @Test @@ -977,7 +973,7 @@ public class LdapTemplateTest { fail("LimitExceededException expected"); } catch (LimitExceededException expected) { - assertTrue(true); + assertThat(true).isTrue(); } verify(dirContextMock).close(); @@ -1024,7 +1020,7 @@ public class LdapTemplateTest { fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } verify(dirContextMock).close(); @@ -1090,7 +1086,7 @@ public class LdapTemplateTest { tested.create(expectedObject); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @@ -1283,7 +1279,7 @@ public class LdapTemplateTest { fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } verify(dirContextMock).close(); @@ -1300,7 +1296,7 @@ public class LdapTemplateTest { verify(dirContextMock).close(); - assertSame(object, result); + assertThat(result).isSameAs(object); } @Test @@ -1315,7 +1311,7 @@ public class LdapTemplateTest { fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } verify(dirContextMock).close(); @@ -1332,7 +1328,7 @@ public class LdapTemplateTest { verify(dirContextMock).close(); - assertSame(object, result); + assertThat(result).isSameAs(object); } @Test @@ -1347,7 +1343,7 @@ public class LdapTemplateTest { fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } verify(dirContextMock).close(); @@ -1385,7 +1381,7 @@ public class LdapTemplateTest { fail("LimitExceededException expected"); } catch (LimitExceededException expected) { - assertTrue(true); + assertThat(true).isTrue(); } verify(dirContextProcessorMock).preProcess(dirContextMock); @@ -1423,7 +1419,7 @@ public class LdapTemplateTest { fail("LimitExceededException expected"); } catch (LimitExceededException expected) { - assertTrue(true); + assertThat(true).isTrue(); } verify(dirContextMock).close(); @@ -1443,7 +1439,7 @@ public class LdapTemplateTest { fail("LimitExceededException expected"); } catch (LimitExceededException expected) { - assertTrue(true); + assertThat(true).isTrue(); } verify(namingEnumerationMock).close(); @@ -1461,7 +1457,7 @@ public class LdapTemplateTest { fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } verify(dirContextMock).close(); @@ -1479,7 +1475,7 @@ public class LdapTemplateTest { fail("PartialResultException expected"); } catch (PartialResultException expected) { - assertTrue(true); + assertThat(true).isTrue(); } verify(dirContextProcessorMock).preProcess(dirContextMock); @@ -1509,13 +1505,13 @@ public class LdapTemplateTest { final LdapName expectedName = LdapUtils.emptyLdapName(); LdapTemplate tested = new LdapTemplate() { public Object lookup(Name dn) { - assertSame(dn, dn); + assertThat(dn).isSameAs(dn); return expectedResult; } }; DirContextOperations result = tested.lookupContext(expectedName); - assertSame(expectedResult, result); + assertThat(result).isSameAs(expectedResult); } @@ -1526,13 +1522,13 @@ public class LdapTemplateTest { LdapTemplate tested = new LdapTemplate() { public Object lookup(String dn) { - assertSame(expectedName, dn); + assertThat(dn).isSameAs(expectedName); return expectedResult; } }; DirContextOperations result = tested.lookupContext(expectedName); - assertSame(expectedResult, result); + assertThat(result).isSameAs(expectedResult); } @Test @@ -1546,8 +1542,8 @@ public class LdapTemplateTest { LdapTemplate tested = new LdapTemplate() { public void modifyAttributes(Name dn, ModificationItem[] mods) { - assertSame(epectedDn, dn); - assertSame(expectedModifications, mods); + assertThat(dn).isSameAs(epectedDn); + assertThat(mods).isSameAs(expectedModifications); } }; @@ -1571,7 +1567,7 @@ public class LdapTemplateTest { fail("IllegalStateException expected"); } catch (IllegalStateException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @@ -1590,7 +1586,7 @@ public class LdapTemplateTest { fail("IllegalStateException expected"); } catch (IllegalStateException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @@ -1610,8 +1606,8 @@ public class LdapTemplateTest { verify(dirContextMock).close(); - assertNotNull(result); - assertSame(expectedResult, result); + assertThat(result).isNotNull(); + assertThat(result).isSameAs(expectedResult); } @Test @@ -1640,7 +1636,7 @@ public class LdapTemplateTest { fail("IncorrectResultSizeDataAccessException expected"); } catch (IncorrectResultSizeDataAccessException expected) { - assertTrue(true); + assertThat(true).isTrue(); } verify(namingEnumerationMock).close(); @@ -1658,7 +1654,7 @@ public class LdapTemplateTest { fail("EmptyResultDataAccessException expected"); } catch (EmptyResultDataAccessException expected) { - assertTrue(true); + assertThat(true).isTrue(); } verify(dirContextMock).close(); @@ -1684,7 +1680,7 @@ public class LdapTemplateTest { verify(authenticatedContextMock).close(); verify(dirContextMock).close(); - assertTrue(result); + assertThat(result).isTrue(); } @Test @@ -1719,7 +1715,7 @@ public class LdapTemplateTest { verify(dirContextMock).close(); - assertFalse(result); + assertThat(result).isFalse(); } @Test @@ -1779,7 +1775,7 @@ public class LdapTemplateTest { verify(dirContextMock).close(); - assertFalse(result); + assertThat(result).isFalse(); } @Test @@ -1804,7 +1800,7 @@ public class LdapTemplateTest { verify(authenticatedContextMock).close(); verify(dirContextMock).close(); - assertFalse(result); + assertThat(result).isFalse(); } private void noSearchResults(SearchControls controls) throws Exception { diff --git a/core/src/test/java/org/springframework/ldap/core/NameAwareAttributeTest.java b/core/src/test/java/org/springframework/ldap/core/NameAwareAttributeTest.java index 8064827c..566daa27 100644 --- a/core/src/test/java/org/springframework/ldap/core/NameAwareAttributeTest.java +++ b/core/src/test/java/org/springframework/ldap/core/NameAwareAttributeTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2005-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.ldap.core; import org.junit.Test; @@ -5,9 +21,7 @@ import org.springframework.ldap.support.LdapUtils; import javax.naming.NamingException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Mattias Hellborg Arthursson @@ -18,7 +32,7 @@ public class NameAwareAttributeTest { NameAwareAttribute attr1 = new NameAwareAttribute("someAttribute"); NameAwareAttribute attr2 = new NameAwareAttribute("someOtherAttribute"); - assertFalse(attr1.equals(attr2)); + assertThat(attr1.equals(attr2)).isFalse(); } @Test @@ -26,8 +40,8 @@ public class NameAwareAttributeTest { NameAwareAttribute attr1 = new NameAwareAttribute("someAttribute"); NameAwareAttribute attr2 = new NameAwareAttribute("someAttribute"); - assertTrue(attr1.equals(attr2)); - assertEquals(attr1.hashCode(), attr2.hashCode()); + assertThat(attr1.equals(attr2)).isTrue(); + assertThat(attr2.hashCode()).isEqualTo(attr1.hashCode()); } @Test @@ -41,8 +55,8 @@ public class NameAwareAttributeTest { attr2.add("value2"); attr2.add("value3"); - assertTrue(attr1.equals(attr2)); - assertEquals(attr1.hashCode(), attr2.hashCode()); + assertThat(attr1.equals(attr2)).isTrue(); + assertThat(attr2.hashCode()).isEqualTo(attr1.hashCode()); } @Test @@ -56,8 +70,8 @@ public class NameAwareAttributeTest { attr2.add(new byte[]{3, 2, 1}); attr2.add(new byte[]{1}); - assertTrue(attr1.equals(attr2)); - assertEquals(attr1.hashCode(), attr2.hashCode()); + assertThat(attr1.equals(attr2)).isTrue(); + assertThat(attr2.hashCode()).isEqualTo(attr1.hashCode()); } @Test @@ -71,8 +85,8 @@ public class NameAwareAttributeTest { attr2.add(new byte[]{1}); attr2.add(new byte[]{1, 2, 3}); - assertTrue(attr1.equals(attr2)); - assertEquals(attr1.hashCode(), attr2.hashCode()); + assertThat(attr1.equals(attr2)).isTrue(); + assertThat(attr2.hashCode()).isEqualTo(attr1.hashCode()); } @Test @@ -86,7 +100,7 @@ public class NameAwareAttributeTest { attr2.add(new byte[]{3, 2, 1}); attr2.add(new byte[]{1}); - assertFalse(attr1.equals(attr2)); + assertThat(attr1.equals(attr2)).isFalse(); } @Test @@ -99,7 +113,7 @@ public class NameAwareAttributeTest { attr2.add(new byte[]{1, 2, 3}); attr2.add(new byte[]{1}); - assertFalse(attr1.equals(attr2)); + assertThat(attr1.equals(attr2)).isFalse(); } @Test @@ -113,8 +127,8 @@ public class NameAwareAttributeTest { attr2.add(new byte[]{3, 2, 1}); attr2.add(new byte[]{1}); - assertTrue(attr1.equals(attr2)); - assertEquals(attr1.hashCode(), attr2.hashCode()); + assertThat(attr1.equals(attr2)).isTrue(); + assertThat(attr2.hashCode()).isEqualTo(attr1.hashCode()); } @Test @@ -128,8 +142,8 @@ public class NameAwareAttributeTest { attr2.add(new byte[]{3, 2, 1}); attr2.add(new byte[]{1}); - assertTrue(attr1.equals(attr2)); - assertEquals(attr1.hashCode(), attr2.hashCode()); + assertThat(attr1.equals(attr2)).isTrue(); + assertThat(attr2.hashCode()).isEqualTo(attr1.hashCode()); } @Test @@ -143,7 +157,7 @@ public class NameAwareAttributeTest { attr2.add(new byte[]{1}); attr2.add(new byte[]{1, 2, 3}); - assertFalse(attr1.equals(attr2)); + assertThat(attr1.equals(attr2)).isFalse(); } @Test @@ -155,10 +169,10 @@ public class NameAwareAttributeTest { NameAwareAttribute attr2 = new NameAwareAttribute("someAttribute"); attr2.add(LdapUtils.newLdapName(expectedName)); - assertEquals(attr1, attr2); - assertEquals(attr1.hashCode(), attr2.hashCode()); - assertEquals(expectedName, attr1.get()); - assertEquals(expectedName, attr2.get()); + assertThat(attr2).isEqualTo(attr1); + assertThat(attr2.hashCode()).isEqualTo(attr1.hashCode()); + assertThat(attr1.get()).isEqualTo(expectedName); + assertThat(attr2.get()).isEqualTo(expectedName); } @Test @@ -172,10 +186,10 @@ public class NameAwareAttributeTest { NameAwareAttribute attr2 = new NameAwareAttribute("someAttribute"); attr2.add(LdapUtils.newLdapName(expectedName2)); - assertEquals(attr1, attr2); - assertEquals(attr1.hashCode(), attr2.hashCode()); - assertEquals(expectedName1, attr1.get()); - assertEquals(expectedName2, attr2.get()); + assertThat(attr2).isEqualTo(attr1); + assertThat(attr2.hashCode()).isEqualTo(attr1.hashCode()); + assertThat(attr1.get()).isEqualTo(expectedName1); + assertThat(attr2.get()).isEqualTo(expectedName2); } @Test @@ -189,9 +203,9 @@ public class NameAwareAttributeTest { NameAwareAttribute attr2 = new NameAwareAttribute("someAttribute"); attr2.add(LdapUtils.newLdapName(expectedName2)); - assertFalse(attr1.equals(attr2)); - assertEquals(expectedName1, attr1.get()); - assertEquals(expectedName2, attr2.get()); + assertThat(attr1.equals(attr2)).isFalse(); + assertThat(attr1.get()).isEqualTo(expectedName1); + assertThat(attr2.get()).isEqualTo(expectedName2); } @Test @@ -207,10 +221,10 @@ public class NameAwareAttributeTest { attr1.initValuesAsNames(); - assertTrue(attr1.equals(attr2)); - assertEquals(attr1.hashCode(), attr2.hashCode()); - assertEquals(expectedName1, attr1.get()); - assertEquals(expectedName2, attr2.get()); + assertThat(attr1.equals(attr2)).isTrue(); + assertThat(attr2.hashCode()).isEqualTo(attr1.hashCode()); + assertThat(attr1.get()).isEqualTo(expectedName1); + assertThat(attr2.get()).isEqualTo(expectedName2); } @Test @@ -224,9 +238,9 @@ public class NameAwareAttributeTest { NameAwareAttribute attr2 = new NameAwareAttribute("someAttribute"); attr2.add(LdapUtils.newLdapName(expectedName2)); - assertFalse(attr1.equals(attr2)); - assertEquals(expectedName1, attr1.get()); - assertEquals(expectedName2, attr2.get()); + assertThat(attr1.equals(attr2)).isFalse(); + assertThat(attr1.get()).isEqualTo(expectedName1); + assertThat(attr2.get()).isEqualTo(expectedName2); } @Test @@ -240,8 +254,8 @@ public class NameAwareAttributeTest { NameAwareAttribute attr2 = new NameAwareAttribute("someAttribute"); attr2.add(expectedValue2); - assertFalse(attr1.equals(attr2)); - assertEquals(expectedName1, attr1.get()); - assertEquals(expectedValue2, attr2.get()); + assertThat(attr1.equals(attr2)).isFalse(); + assertThat(attr1.get()).isEqualTo(expectedName1); + assertThat(attr2.get()).isEqualTo(expectedValue2); } } diff --git a/core/src/test/java/org/springframework/ldap/core/support/AbstractContextSourceTest.java b/core/src/test/java/org/springframework/ldap/core/support/AbstractContextSourceTest.java index 7c0caa54..20b10aa6 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/AbstractContextSourceTest.java +++ b/core/src/test/java/org/springframework/ldap/core/support/AbstractContextSourceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import org.junit.Test; import javax.naming.InvalidNameException; import javax.naming.ldap.LdapName; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Mattias Hellborg Arthursson @@ -33,7 +33,7 @@ public class AbstractContextSourceTest { LdapName ldapName = new LdapName("dc=261consulting, dc=com"); String result = AbstractContextSource.formatForUrl(ldapName); - assertEquals("dc=261consulting,dc=com", result); + assertThat(result).isEqualTo("dc=261consulting,dc=com"); } @Test @@ -41,7 +41,7 @@ public class AbstractContextSourceTest { LdapName ldapName = new LdapName("dc=261consulting?, dc=com"); String result = AbstractContextSource.formatForUrl(ldapName); - assertEquals("dc=261consulting%3F,dc=com", result); + assertThat(result).isEqualTo("dc=261consulting%3F,dc=com"); } @Test @@ -49,7 +49,7 @@ public class AbstractContextSourceTest { LdapName ldapName = new LdapName("ou=some department, dc=261consulting, dc=com"); String result = AbstractContextSource.formatForUrl(ldapName); - assertEquals("ou=some%20department,dc=261consulting,dc=com", result); + assertThat(result).isEqualTo("ou=some%20department,dc=261consulting,dc=com"); } @Test @@ -57,6 +57,6 @@ public class AbstractContextSourceTest { LdapName ldapName = new LdapName(""); String result = AbstractContextSource.formatForUrl(ldapName); - assertEquals("", result); + assertThat(result).isEqualTo(""); } } diff --git a/core/src/test/java/org/springframework/ldap/core/support/BaseLdapPathBeanPostProcessorTest.java b/core/src/test/java/org/springframework/ldap/core/support/BaseLdapPathBeanPostProcessorTest.java index 536a663d..bfb6a813 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/BaseLdapPathBeanPostProcessorTest.java +++ b/core/src/test/java/org/springframework/ldap/core/support/BaseLdapPathBeanPostProcessorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import org.springframework.ldap.support.LdapUtils; import java.util.HashMap; -import static org.junit.Assert.assertSame; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -62,7 +62,7 @@ public class BaseLdapPathBeanPostProcessorTest { verify(ldapPathAwareMock).setBaseLdapPath(new DistinguishedName(expectedPath)); - assertSame(ldapPathAwareMock, result); + assertThat(result).isSameAs(ldapPathAwareMock); } @Test @@ -74,7 +74,7 @@ public class BaseLdapPathBeanPostProcessorTest { verify(ldapNameAwareMock).setBaseLdapPath(LdapUtils.newLdapName(expectedPath)); - assertSame(ldapNameAwareMock, result); + assertThat(result).isSameAs(ldapNameAwareMock); } @@ -94,7 +94,7 @@ public class BaseLdapPathBeanPostProcessorTest { verify(ldapPathAwareMock).setBaseLdapPath(new DistinguishedName(expectedPath)); - assertSame(ldapPathAwareMock, result); + assertThat(result).isSameAs(ldapPathAwareMock); } @Test @@ -113,7 +113,7 @@ public class BaseLdapPathBeanPostProcessorTest { verify(ldapNameAwareMock).setBaseLdapPath(LdapUtils.newLdapName(expectedPath)); - assertSame(ldapNameAwareMock, result); + assertThat(result).isSameAs(ldapNameAwareMock); } @Test @@ -129,7 +129,7 @@ public class BaseLdapPathBeanPostProcessorTest { BaseLdapPathSource result = tested.getBaseLdapPathSourceFromApplicationContext(); - assertSame(expectedContextSource, result); + assertThat(result).isSameAs(expectedContextSource); } @Test(expected = NoSuchBeanDefinitionException.class) diff --git a/core/src/test/java/org/springframework/ldap/core/support/ContextMapperCallbackHandlerWithControlsTest.java b/core/src/test/java/org/springframework/ldap/core/support/ContextMapperCallbackHandlerWithControlsTest.java index 4a1596ca..6c84d9d7 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/ContextMapperCallbackHandlerWithControlsTest.java +++ b/core/src/test/java/org/springframework/ldap/core/support/ContextMapperCallbackHandlerWithControlsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ import javax.naming.NamingException; import javax.naming.ldap.Control; import javax.naming.ldap.HasControls; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -72,7 +72,7 @@ public class ContextMapperCallbackHandlerWithControlsTest { Object actualResult = tested.getObjectFromNameClassPair(expectedBinding); - assertEquals(expectedResult, actualResult); + assertThat(actualResult).isEqualTo(expectedResult); } @Test @@ -85,7 +85,7 @@ public class ContextMapperCallbackHandlerWithControlsTest { Object actualResult = tested.getObjectFromNameClassPair(expectedBinding); - assertEquals(expectedResult, actualResult); + assertThat(actualResult).isEqualTo(expectedResult); } @Test(expected = ObjectRetrievalException.class) diff --git a/core/src/test/java/org/springframework/ldap/core/support/CountNameClassPairResultCallbackHandlerTest.java b/core/src/test/java/org/springframework/ldap/core/support/CountNameClassPairResultCallbackHandlerTest.java index 9150b65c..74bb7c62 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/CountNameClassPairResultCallbackHandlerTest.java +++ b/core/src/test/java/org/springframework/ldap/core/support/CountNameClassPairResultCallbackHandlerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ import org.junit.Test; import javax.naming.directory.SearchResult; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class CountNameClassPairResultCallbackHandlerTest { @@ -38,7 +38,7 @@ public class CountNameClassPairResultCallbackHandlerTest { tested.handleNameClassPair(dummy); tested.handleNameClassPair(dummy); - assertEquals(3, tested.getNoOfRows()); + assertThat(tested.getNoOfRows()).isEqualTo(3); } } diff --git a/core/src/test/java/org/springframework/ldap/core/support/DefaultDirObjectFactoryTest.java b/core/src/test/java/org/springframework/ldap/core/support/DefaultDirObjectFactoryTest.java index 8979c814..22668c64 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/DefaultDirObjectFactoryTest.java +++ b/core/src/test/java/org/springframework/ldap/core/support/DefaultDirObjectFactoryTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,7 @@ import javax.naming.directory.Attributes; import javax.naming.directory.BasicAttributes; import java.util.Hashtable; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -64,8 +64,8 @@ public class DefaultDirObjectFactoryTest { verify(contextMock).close(); - assertEquals(DN, adapter.getDn()); - assertEquals(expectedAttributes, adapter.getAttributes()); + assertThat(adapter.getDn()).isEqualTo(DN); + assertThat(adapter.getAttributes()).isEqualTo(expectedAttributes); } @Test @@ -81,8 +81,8 @@ public class DefaultDirObjectFactoryTest { verify(contextMock).close(); - assertEquals(DN, adapter.getDn()); - assertEquals(expectedAttributes, adapter.getAttributes()); + assertThat(adapter.getDn()).isEqualTo(DN); + assertThat(adapter.getAttributes()).isEqualTo(expectedAttributes); } @Test @@ -93,8 +93,8 @@ public class DefaultDirObjectFactoryTest { DirContextAdapter adapter = (DirContextAdapter) tested.getObjectInstance(null, DN, null, new Hashtable(), expectedAttributes); - assertEquals(DN, adapter.getDn()); - assertEquals(expectedAttributes, adapter.getAttributes()); + assertThat(adapter.getDn()).isEqualTo(DN); + assertThat(adapter.getAttributes()).isEqualTo(expectedAttributes); } @Test @@ -105,8 +105,8 @@ public class DefaultDirObjectFactoryTest { DirContextAdapter adapter = (DirContextAdapter) tested.getObjectInstance(new Object(), DN, null, new Hashtable(), expectedAttributes); - assertEquals(DN, adapter.getDn()); - assertEquals(expectedAttributes, adapter.getAttributes()); + assertThat(adapter.getDn()).isEqualTo(DN); + assertThat(adapter.getAttributes()).isEqualTo(expectedAttributes); } /** @@ -126,9 +126,9 @@ public class DefaultDirObjectFactoryTest { verify(contextMock).close(); - assertEquals("ou=some unit", adapter.getDn().toString()); - assertEquals("ou=some unit,dc=jayway,dc=se", adapter.getNameInNamespace()); - assertEquals(expectedAttributes, adapter.getAttributes()); + assertThat(adapter.getDn().toString()).isEqualTo("ou=some unit"); + assertThat(adapter.getNameInNamespace()).isEqualTo("ou=some unit,dc=jayway,dc=se"); + assertThat(adapter.getAttributes()).isEqualTo(expectedAttributes); } @Test @@ -138,8 +138,8 @@ public class DefaultDirObjectFactoryTest { DefaultDirObjectFactory tested = new DefaultDirObjectFactory(); DirContextAdapter result = tested.constructAdapterFromName(new BasicAttributes(), name, ""); - assertEquals("ou=People,o=JNDITutorial", result.getDn().toString()); - assertEquals("ldap://localhost:389", result.getReferralUrl().toString()); + assertThat(result.getDn().toString()).isEqualTo("ou=People,o=JNDITutorial"); + assertThat(result.getReferralUrl().toString()).isEqualTo("ldap://localhost:389"); } @Test @@ -149,8 +149,8 @@ public class DefaultDirObjectFactoryTest { DefaultDirObjectFactory tested = new DefaultDirObjectFactory(); DirContextAdapter result = tested.constructAdapterFromName(new BasicAttributes(), name, ""); - assertEquals("ou=People,o=JNDITutorial", result.getDn().toString()); - assertEquals("ldaps://localhost:389", result.getReferralUrl().toString()); + assertThat(result.getDn().toString()).isEqualTo("ou=People,o=JNDITutorial"); + assertThat(result.getReferralUrl().toString()).isEqualTo("ldaps://localhost:389"); } @Test @@ -160,8 +160,8 @@ public class DefaultDirObjectFactoryTest { DefaultDirObjectFactory tested = new DefaultDirObjectFactory(); DirContextAdapter result = tested.constructAdapterFromName(new BasicAttributes(), name, ""); - assertEquals("", result.getDn().toString()); - assertEquals("ldap://localhost:389", result.getReferralUrl().toString()); + assertThat(result.getDn().toString()).isEqualTo(""); + assertThat(result.getReferralUrl().toString()).isEqualTo("ldap://localhost:389"); } @Test @@ -171,7 +171,7 @@ public class DefaultDirObjectFactoryTest { DefaultDirObjectFactory tested = new DefaultDirObjectFactory(); DirContextAdapter result = tested.constructAdapterFromName(new BasicAttributes(), name, ""); - assertEquals("", result.getDn().toString()); - assertEquals("ldap://localhost:389", result.getReferralUrl().toString()); + assertThat(result.getDn().toString()).isEqualTo(""); + assertThat(result.getReferralUrl().toString()).isEqualTo("ldap://localhost:389"); } } diff --git a/core/src/test/java/org/springframework/ldap/core/support/DefaultIncrementalAttributesMapperTest.java b/core/src/test/java/org/springframework/ldap/core/support/DefaultIncrementalAttributesMapperTest.java index d69d17de..a80e57d7 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/DefaultIncrementalAttributesMapperTest.java +++ b/core/src/test/java/org/springframework/ldap/core/support/DefaultIncrementalAttributesMapperTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,10 +24,7 @@ import javax.naming.directory.Attributes; import javax.naming.directory.BasicAttribute; import javax.naming.directory.BasicAttributes; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * IncrementalAttributesMapper Tester. @@ -47,15 +44,15 @@ public class DefaultIncrementalAttributesMapperTest { public void testGetAttributesArray() throws Exception { String[] attributes = tested.getAttributesForLookup(); - assertEquals(1, attributes.length); - assertEquals("member", attributes[0]); + assertThat(attributes.length).isEqualTo(1); + assertThat(attributes[0]).isEqualTo("member"); tested = new DefaultIncrementalAttributesMapper(10, "member"); attributes = tested.getAttributesForLookup(); - assertEquals(1, attributes.length); - assertEquals("member;Range=0-10", attributes[0]); + assertThat(attributes.length).isEqualTo(1); + assertThat(attributes[0]).isEqualTo("member;Range=0-10"); } @Test @@ -63,22 +60,22 @@ public class DefaultIncrementalAttributesMapperTest { tested = new DefaultIncrementalAttributesMapper(20, new String[]{"member", "cn"}); String[] attributes = tested.getAttributesForLookup(); - assertEquals(2, attributes.length); + assertThat(attributes.length).isEqualTo(2); - assertEquals("member;Range=0-20", attributes[0]); - assertEquals("cn;Range=0-20", attributes[1]); + assertThat(attributes[0]).isEqualTo("member;Range=0-20"); + assertThat(attributes[1]).isEqualTo("cn;Range=0-20"); } @Test public void testLoopEmpty() throws Exception { - assertTrue(tested.hasMore()); + assertThat(tested.hasMore()).isTrue(); Attributes attributes = new BasicAttributes(); tested.mapFromAttributes(attributes); - assertFalse(tested.hasMore()); - assertNull(tested.getValues("member")); + assertThat(tested.hasMore()).isFalse(); + assertThat(tested.getValues("member")).isNull(); } @Test @@ -87,15 +84,15 @@ public class DefaultIncrementalAttributesMapperTest { tested.mapFromAttributes(attributes); - assertTrue(tested.hasMore()); - assertEquals(11, tested.getValues("member").size()); + assertThat(tested.hasMore()).isTrue(); + assertThat(tested.getValues("member")).hasSize(11); attributes = createAttributes("member", new RangeOption(11), 5); tested.mapFromAttributes(attributes); - assertFalse(tested.hasMore()); - assertEquals(16, tested.getValues("member").size()); + assertThat(tested.hasMore()).isFalse(); + assertThat(tested.getValues("member")).hasSize(16); } @Test @@ -106,8 +103,8 @@ public class DefaultIncrementalAttributesMapperTest { tested.mapFromAttributes(attributes); - assertFalse(tested.hasMore()); - assertEquals(11, tested.getValues("member").size()); + assertThat(tested.hasMore()).isFalse(); + assertThat(tested.getValues("member")).hasSize(11); } @Test @@ -118,15 +115,15 @@ public class DefaultIncrementalAttributesMapperTest { tested.mapFromAttributes(attributes); - assertTrue(tested.hasMore()); - assertEquals(11, tested.getValues("member").size()); + assertThat(tested.hasMore()).isTrue(); + assertThat(tested.getValues("member")).hasSize(11); attributes = createAttributes("member", new RangeOption(11, 30)); tested.mapFromAttributes(attributes); - assertFalse(tested.hasMore()); - assertEquals(31, tested.getValues("member").size()); + assertThat(tested.hasMore()).isFalse(); + assertThat(tested.getValues("member")).hasSize(31); } @Test @@ -137,15 +134,15 @@ public class DefaultIncrementalAttributesMapperTest { tested.mapFromAttributes(attributes); - assertTrue(tested.hasMore()); - assertEquals(11, tested.getValues("member").size()); + assertThat(tested.hasMore()).isTrue(); + assertThat(tested.getValues("member")).hasSize(11); attributes = createAttributes("member", new RangeOption(11), 5); tested.mapFromAttributes(attributes); - assertFalse(tested.hasMore()); - assertEquals(16, tested.getValues("member").size()); + assertThat(tested.hasMore()).isFalse(); + assertThat(tested.getValues("member")).hasSize(16); } @Test @@ -157,18 +154,18 @@ public class DefaultIncrementalAttributesMapperTest { tested.mapFromAttributes(attributes); - assertTrue(tested.hasMore()); - assertEquals(6, tested.getValues("member").size()); - assertEquals(10, tested.getValues("cn").size()); + assertThat(tested.hasMore()).isTrue(); + assertThat(tested.getValues("member")).hasSize(6); + assertThat(tested.getValues("cn")).hasSize(10); - assertEquals(1, tested.getAttributesForLookup().length); + assertThat(tested.getAttributesForLookup().length).isEqualTo(1); attributes = createAttributes("member", new RangeOption(6), 5); tested.mapFromAttributes(attributes); - assertFalse(tested.hasMore()); - assertEquals(11, tested.getValues("member").size()); + assertThat(tested.hasMore()).isFalse(); + assertThat(tested.getValues("member")).hasSize(11); } private Attributes createAttributes(String attributeName, RangeOption range) { diff --git a/core/src/test/java/org/springframework/ldap/core/support/LdapContextSourceTest.java b/core/src/test/java/org/springframework/ldap/core/support/LdapContextSourceTest.java index 7fc0e0dc..641ab933 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/LdapContextSourceTest.java +++ b/core/src/test/java/org/springframework/ldap/core/support/LdapContextSourceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,8 +24,7 @@ import javax.naming.Context; import java.util.HashMap; import java.util.Hashtable; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.assertj.core.api.Assertions.assertThat; /** * Unit tests for the LdapContextSource class. @@ -69,13 +68,13 @@ public class LdapContextSourceTest { tested.setPassword("secret"); tested.afterPropertiesSet(); Hashtable env = tested.getAnonymousEnv(); - assertEquals("ldap://ldap.example.com:389/dc=some%20example,dc=se", env.get(Context.PROVIDER_URL)); - assertEquals("true", env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG)); - assertNull(env.get(Context.SECURITY_PRINCIPAL)); - assertNull(env.get(Context.SECURITY_CREDENTIALS)); + assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap.example.com:389/dc=some%20example,dc=se"); + assertThat(env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isEqualTo("true"); + assertThat(env.get(Context.SECURITY_PRINCIPAL)).isNull(); + assertThat(env.get(Context.SECURITY_CREDENTIALS)).isNull(); // check that base was added to environment - assertEquals(LdapUtils.newLdapName("dc=some example,dc=se"), env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)); + assertThat(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)).isEqualTo(LdapUtils.newLdapName("dc=some example,dc=se")); // Verify that changing values does not change the environment values. tested.setBase("dc=other,dc=se"); @@ -83,12 +82,12 @@ public class LdapContextSourceTest { tested.setPooled(false); env = tested.getAnonymousEnv(); - assertEquals("ldap://ldap.example.com:389/dc=some%20example,dc=se", env.get(Context.PROVIDER_URL)); - assertEquals("true", env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG)); - assertNull(env.get(Context.SECURITY_PRINCIPAL)); - assertNull(env.get(Context.SECURITY_CREDENTIALS)); + assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap.example.com:389/dc=some%20example,dc=se"); + assertThat(env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isEqualTo("true"); + assertThat(env.get(Context.SECURITY_PRINCIPAL)).isNull(); + assertThat(env.get(Context.SECURITY_CREDENTIALS)).isNull(); - assertEquals(LdapUtils.newLdapName("dc=some example,dc=se"), env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)); + assertThat(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)).isEqualTo(LdapUtils.newLdapName("dc=some example,dc=se")); } @Test @@ -96,10 +95,10 @@ public class LdapContextSourceTest { tested.setUrl("ldap://ldap.example.com:389"); tested.afterPropertiesSet(); Hashtable env = tested.getAnonymousEnv(); - assertEquals("ldap://ldap.example.com:389", env.get(Context.PROVIDER_URL)); + assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap.example.com:389"); // check that base was not added to environment - assertNull(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)); + assertThat(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)).isNull(); } @Test @@ -110,8 +109,8 @@ public class LdapContextSourceTest { tested.setBaseEnvironmentProperties(map); tested.afterPropertiesSet(); Hashtable env = tested.getAnonymousEnv(); - assertEquals("ldap://ldap.example.com:389", env.get(Context.PROVIDER_URL)); - assertNull(env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG)); + assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap.example.com:389"); + assertThat(env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isNull(); } @Test @@ -123,8 +122,8 @@ public class LdapContextSourceTest { tested.setPooled(false); tested.afterPropertiesSet(); Hashtable env = tested.getAnonymousEnv(); - assertEquals("ldap://ldap.example.com:389", env.get(Context.PROVIDER_URL)); - assertNull(env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG)); + assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap.example.com:389"); + assertThat(env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isNull(); } @Test @@ -133,10 +132,10 @@ public class LdapContextSourceTest { tested.setBase(null); tested.afterPropertiesSet(); Hashtable env = tested.getAnonymousEnv(); - assertEquals("ldap://ldap.example.com:389", env.get(Context.PROVIDER_URL)); + assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap.example.com:389"); // check that base was not added to environment - assertNull(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)); + assertThat(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)).isNull(); } @Test @@ -151,7 +150,7 @@ public class LdapContextSourceTest { // check that base was not added to environment Hashtable env = tested.getAnonymousEnv(); - assertNull(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)); + assertThat(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)).isNull(); } @Test(expected = IllegalArgumentException.class) @@ -179,7 +178,7 @@ public class LdapContextSourceTest { // check that base was not added to environment Hashtable env = tested.getAnonymousEnv(); - assertNull(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)); + assertThat(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)).isNull(); } @Test @@ -192,13 +191,13 @@ public class LdapContextSourceTest { tested.afterPropertiesSet(); Hashtable env = tested.getAuthenticatedEnv("cn=Some User", "secret"); - assertEquals("ldap://ldap.example.com:389/dc=example,dc=se", env.get(Context.PROVIDER_URL)); - assertEquals("true", env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG)); - assertEquals("cn=Some User", env.get(Context.SECURITY_PRINCIPAL)); - assertEquals("secret", env.get(Context.SECURITY_CREDENTIALS)); + assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap.example.com:389/dc=example,dc=se"); + assertThat(env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isEqualTo("true"); + assertThat(env.get(Context.SECURITY_PRINCIPAL)).isEqualTo("cn=Some User"); + assertThat(env.get(Context.SECURITY_CREDENTIALS)).isEqualTo("secret"); // check that base was added to environment - assertEquals(LdapUtils.newLdapName("dc=example,dc=se"), env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)); + assertThat(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)).isEqualTo(LdapUtils.newLdapName("dc=example,dc=se")); } @Test @@ -211,13 +210,13 @@ public class LdapContextSourceTest { tested.setCacheEnvironmentProperties(false); tested.afterPropertiesSet(); Hashtable env = tested.getAnonymousEnv(); - assertEquals("ldap://ldap.example.com:389/dc=example,dc=se", env.get(Context.PROVIDER_URL)); - assertEquals("true", env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG)); - assertNull(env.get(Context.SECURITY_PRINCIPAL)); - assertNull(env.get(Context.SECURITY_CREDENTIALS)); + assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap.example.com:389/dc=example,dc=se"); + assertThat(env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isEqualTo("true"); + assertThat(env.get(Context.SECURITY_PRINCIPAL)).isNull(); + assertThat(env.get(Context.SECURITY_CREDENTIALS)).isNull(); tested.setUrl("ldap://ldap2.example.com:389"); env = tested.getAnonymousEnv(); - assertEquals("ldap://ldap2.example.com:389/dc=example,dc=se", env.get(Context.PROVIDER_URL)); + assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap2.example.com:389/dc=example,dc=se"); } } diff --git a/core/src/test/java/org/springframework/ldap/core/support/RangeOptionTest.java b/core/src/test/java/org/springframework/ldap/core/support/RangeOptionTest.java index 2af694fa..11f26ae3 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/RangeOptionTest.java +++ b/core/src/test/java/org/springframework/ldap/core/support/RangeOptionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,10 +18,8 @@ package org.springframework.ldap.core.support; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * IncrementalAttributesMapper Tester. @@ -37,7 +35,7 @@ public class RangeOptionTest { fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } try { @@ -45,7 +43,7 @@ public class RangeOptionTest { fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } try { @@ -53,7 +51,7 @@ public class RangeOptionTest { fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } try { @@ -61,82 +59,82 @@ public class RangeOptionTest { fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @Test public void testToString() throws Exception { RangeOption range = new RangeOption(0, 100); - assertEquals("Range=0-100", range.toString()); + assertThat(range.toString()).isEqualTo("Range=0-100"); range = new RangeOption(0, RangeOption.TERMINAL_END_OF_RANGE); - assertEquals("Range=0-*", range.toString()); + assertThat(range.toString()).isEqualTo("Range=0-*"); range = new RangeOption(0, RangeOption.TERMINAL_MISSING); - assertEquals("Range=0", range.toString()); + assertThat(range.toString()).isEqualTo("Range=0"); } @Test public void testParse() throws Exception { RangeOption range = RangeOption.parse("Range=0-100"); - assertEquals(0, range.getInitial()); - assertEquals(100, range.getTerminal()); + assertThat(range.getInitial()).isEqualTo(0); + assertThat(range.getTerminal()).isEqualTo(100); range = RangeOption.parse("range=0-100"); - assertEquals(0, range.getInitial()); - assertEquals(100, range.getTerminal()); + assertThat(range.getInitial()).isEqualTo(0); + assertThat(range.getTerminal()).isEqualTo(100); range = RangeOption.parse("RANGE=0-100"); - assertEquals(0, range.getInitial()); - assertEquals(100, range.getTerminal()); + assertThat(range.getInitial()).isEqualTo(0); + assertThat(range.getTerminal()).isEqualTo(100); range = RangeOption.parse("Range=0-*"); - assertEquals(0, range.getInitial()); - assertEquals(RangeOption.TERMINAL_END_OF_RANGE, range.getTerminal()); + assertThat(range.getInitial()).isEqualTo(0); + assertThat(range.getTerminal()).isEqualTo(RangeOption.TERMINAL_END_OF_RANGE); range = RangeOption.parse("Range=10"); - assertEquals(10, range.getInitial()); - assertEquals(RangeOption.TERMINAL_MISSING, range.getTerminal()); + assertThat(range.getInitial()).isEqualTo(10); + assertThat(range.getTerminal()).isEqualTo(RangeOption.TERMINAL_MISSING); } @Test public void testParseInvalid() { - assertNull(RangeOption.parse("Range=10-")); - assertNull(RangeOption.parse("Range=10-a")); - assertNull(RangeOption.parse("lang-en")); - assertNull(RangeOption.parse("member;Range=10-100")); - assertNull(RangeOption.parse(";Range=10-100")); - assertNull(RangeOption.parse("Range=10-100;")); - assertNull(RangeOption.parse("Range=10-100;lang-de")); + assertThat(RangeOption.parse("Range=10-")).isNull(); + assertThat(RangeOption.parse("Range=10-a")).isNull(); + assertThat(RangeOption.parse("lang-en")).isNull(); + assertThat(RangeOption.parse("member;Range=10-100")).isNull(); + assertThat(RangeOption.parse(";Range=10-100")).isNull(); + assertThat(RangeOption.parse("Range=10-100;")).isNull(); + assertThat(RangeOption.parse("Range=10-100;lang-de")).isNull(); } @Test public void testCompare() { RangeOption range1 = RangeOption.parse("Range=10-500"); RangeOption range2 = RangeOption.parse("Range=10-500"); - assertTrue(range1.compareTo(range2) == 0); - assertTrue(range2.compareTo(range1) == 0); + assertThat(range1.compareTo(range2) == 0).isTrue(); + assertThat(range2.compareTo(range1) == 0).isTrue(); range1 = RangeOption.parse("Range=0-*"); range2 = RangeOption.parse("Range=0-*"); - assertTrue(range1.compareTo(range2) == 0); - assertTrue(range2.compareTo(range1) == 0); + assertThat(range1.compareTo(range2) == 0).isTrue(); + assertThat(range2.compareTo(range1) == 0).isTrue(); range1 = RangeOption.parse("Range=0"); range2 = RangeOption.parse("Range=0"); - assertTrue(range1.compareTo(range2) == 0); - assertTrue(range2.compareTo(range1) == 0); + assertThat(range1.compareTo(range2) == 0).isTrue(); + assertThat(range2.compareTo(range1) == 0).isTrue(); range1 = RangeOption.parse("Range=0-101"); range2 = RangeOption.parse("Range=0-100"); - assertTrue(range1.compareTo(range2) > 0); - assertTrue(range2.compareTo(range1) < 0); + assertThat(range1.compareTo(range2) > 0).isTrue(); + assertThat(range2.compareTo(range1) < 0).isTrue(); range1 = RangeOption.parse("Range=0-*"); range2 = RangeOption.parse("Range=0-100"); - assertTrue(range1.compareTo(range2) > 0); - assertTrue(range2.compareTo(range1) < 0); + assertThat(range1.compareTo(range2) > 0).isTrue(); + assertThat(range2.compareTo(range1) < 0).isTrue(); } @Test @@ -145,33 +143,33 @@ public class RangeOptionTest { RangeOption range2 = RangeOption.parse("Range=11-500"); try { - assertTrue(range1.compareTo(range2) == 0); + assertThat(range1.compareTo(range2) == 0).isTrue(); fail("IllegalStateException expected"); } catch (IllegalStateException expected) { - assertTrue(true); + assertThat(true).isTrue(); } range1 = RangeOption.parse("Range=10"); range2 = RangeOption.parse("Range=10-500"); try { - assertTrue(range1.compareTo(range2) == 0); + assertThat(range1.compareTo(range2) == 0).isTrue(); fail("IllegalStateException expected"); } catch (IllegalStateException expected) { - assertTrue(true); + assertThat(true).isTrue(); } range1 = RangeOption.parse("Range=10-500"); range2 = RangeOption.parse("Range=10"); try { - assertTrue(range1.compareTo(range2) == 0); + assertThat(range1.compareTo(range2) == 0).isTrue(); fail("IllegalStateException expected"); } catch (IllegalStateException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @@ -180,15 +178,15 @@ public class RangeOptionTest { RangeOption range = RangeOption.parse("Range=0-100"); range = range.nextRange(100); - assertEquals(101, range.getInitial()); - assertEquals(200, range.getTerminal()); + assertThat(range.getInitial()).isEqualTo(101); + assertThat(range.getTerminal()).isEqualTo(200); range = range.nextRange(10); - assertEquals(201, range.getInitial()); - assertEquals(210, range.getTerminal()); + assertThat(range.getInitial()).isEqualTo(201); + assertThat(range.getTerminal()).isEqualTo(210); range = range.nextRange(RangeOption.TERMINAL_END_OF_RANGE); - assertEquals(211, range.getInitial()); - assertEquals(RangeOption.TERMINAL_END_OF_RANGE, range.getTerminal()); + assertThat(range.getInitial()).isEqualTo(211); + assertThat(range.getTerminal()).isEqualTo(RangeOption.TERMINAL_END_OF_RANGE); } } diff --git a/core/src/test/java/org/springframework/ldap/core/support/SimpleDirContextAuthenticationStrategyTest.java b/core/src/test/java/org/springframework/ldap/core/support/SimpleDirContextAuthenticationStrategyTest.java old mode 100755 new mode 100644 index e231ff4f..a1f1f9ac --- a/core/src/test/java/org/springframework/ldap/core/support/SimpleDirContextAuthenticationStrategyTest.java +++ b/core/src/test/java/org/springframework/ldap/core/support/SimpleDirContextAuthenticationStrategyTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,7 @@ import org.junit.Test; import javax.naming.Context; import java.util.Hashtable; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; public class SimpleDirContextAuthenticationStrategyTest { private SimpleDirContextAuthenticationStrategy tested; @@ -37,9 +36,9 @@ public class SimpleDirContextAuthenticationStrategyTest { Hashtable env = new Hashtable(); tested.setupEnvironment(env, "cn=John Doe", "pw"); - assertEquals("simple", env.get(Context.SECURITY_AUTHENTICATION)); - assertEquals("cn=John Doe", env.get(Context.SECURITY_PRINCIPAL)); - assertEquals("pw", env.get(Context.SECURITY_CREDENTIALS)); + assertThat(env.get(Context.SECURITY_AUTHENTICATION)).isEqualTo("simple"); + assertThat(env.get(Context.SECURITY_PRINCIPAL)).isEqualTo("cn=John Doe"); + assertThat(env.get(Context.SECURITY_CREDENTIALS)).isEqualTo("pw"); } @Test @@ -47,7 +46,7 @@ public class SimpleDirContextAuthenticationStrategyTest { Hashtable env = new Hashtable(); tested.processContextAfterCreation(null, "cn=John Doe", "pw"); - assertTrue(env.isEmpty()); + assertThat(env.isEmpty()).isTrue(); } diff --git a/core/src/test/java/org/springframework/ldap/core/support/SingleContextSourceTest.java b/core/src/test/java/org/springframework/ldap/core/support/SingleContextSourceTest.java index 9fa00355..e23159f1 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/SingleContextSourceTest.java +++ b/core/src/test/java/org/springframework/ldap/core/support/SingleContextSourceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ import javax.naming.directory.DirContext; import java.lang.reflect.Proxy; -import static org.junit.Assert.assertSame; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; @@ -59,7 +59,7 @@ public class SingleContextSourceTest { @Override public Object executeWithContext(DirContext ctx) throws NamingException { Object targetContex = Whitebox.getInternalState(Proxy.getInvocationHandler(ctx), "target"); - assertSame(dirContextMock, targetContex); + assertThat(targetContex).isSameAs(dirContextMock); return false; } }); @@ -70,7 +70,7 @@ public class SingleContextSourceTest { @Override public Object executeWithContext(DirContext ctx) throws NamingException { Object targetContex = Whitebox.getInternalState(Proxy.getInvocationHandler(ctx), "target"); - assertSame(dirContextMock, targetContex); + assertThat(targetContex).isSameAs(dirContextMock); return false; } }); diff --git a/core/src/test/java/org/springframework/ldap/filter/AbstractFilterTest.java b/core/src/test/java/org/springframework/ldap/filter/AbstractFilterTest.java index a9b34902..d847c3fe 100644 --- a/core/src/test/java/org/springframework/ldap/filter/AbstractFilterTest.java +++ b/core/src/test/java/org/springframework/ldap/filter/AbstractFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ package org.springframework.ldap.filter; import org.junit.Test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Adam Skogman @@ -36,7 +36,7 @@ public class AbstractFilterTest { } }; - assertEquals("foo", af.encode()); + assertThat(af.encode()).isEqualTo("foo"); } @@ -52,7 +52,7 @@ public class AbstractFilterTest { } }; - assertEquals("foo", af.toString()); + assertThat(af.toString()).isEqualTo("foo"); } diff --git a/core/src/test/java/org/springframework/ldap/filter/AndFilterTest.java b/core/src/test/java/org/springframework/ldap/filter/AndFilterTest.java index baae8417..74a4c79b 100644 --- a/core/src/test/java/org/springframework/ldap/filter/AndFilterTest.java +++ b/core/src/test/java/org/springframework/ldap/filter/AndFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ package org.springframework.ldap.filter; import com.gargoylesoftware.base.testing.EqualsTester; import org.junit.Test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Adam Skogman @@ -30,14 +30,14 @@ public class AndFilterTest { public void testZero() { AndFilter aq = new AndFilter(); - assertEquals("", aq.encode()); + assertThat(aq.encode()).isEqualTo(""); } @Test public void testOne() { AndFilter aq = new AndFilter().and(new EqualsFilter("a", "b")); - assertEquals("(a=b)", aq.encode()); + assertThat(aq.encode()).isEqualTo("(a=b)"); } @Test @@ -45,7 +45,7 @@ public class AndFilterTest { AndFilter aq = new AndFilter().and(new EqualsFilter("a", "b")).and( new EqualsFilter("c", "d")); - assertEquals("(&(a=b)(c=d))", aq.encode()); + assertThat(aq.encode()).isEqualTo("(&(a=b)(c=d))"); } @Test @@ -53,7 +53,7 @@ public class AndFilterTest { AndFilter aq = new AndFilter().and(new EqualsFilter("a", "b")).and( new EqualsFilter("c", "d")).and(new EqualsFilter("e", "f")); - assertEquals("(&(a=b)(c=d)(e=f))", aq.encode()); + assertThat(aq.encode()).isEqualTo("(&(a=b)(c=d)(e=f))"); } @Test diff --git a/core/src/test/java/org/springframework/ldap/filter/EqualsFilterTest.java b/core/src/test/java/org/springframework/ldap/filter/EqualsFilterTest.java index ae14a24c..d4764650 100644 --- a/core/src/test/java/org/springframework/ldap/filter/EqualsFilterTest.java +++ b/core/src/test/java/org/springframework/ldap/filter/EqualsFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ package org.springframework.ldap.filter; import com.gargoylesoftware.base.testing.EqualsTester; import org.junit.Test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Adam Skogman @@ -34,7 +34,7 @@ public class EqualsFilterTest { StringBuffer buff = new StringBuffer(); eqq.encode(buff); - assertEquals("(foo=\\2abar\\28fie\\29)", buff.toString()); + assertThat(buff.toString()).isEqualTo("(foo=\\2abar\\28fie\\29)"); } @@ -46,7 +46,7 @@ public class EqualsFilterTest { StringBuffer buff = new StringBuffer(); eqq.encode(buff); - assertEquals("(foo=456)", buff.toString()); + assertThat(buff.toString()).isEqualTo("(foo=456)"); } diff --git a/core/src/test/java/org/springframework/ldap/filter/GreaterThanOrEqualsFilterTest.java b/core/src/test/java/org/springframework/ldap/filter/GreaterThanOrEqualsFilterTest.java index b1a2f052..e9839aad 100644 --- a/core/src/test/java/org/springframework/ldap/filter/GreaterThanOrEqualsFilterTest.java +++ b/core/src/test/java/org/springframework/ldap/filter/GreaterThanOrEqualsFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ package org.springframework.ldap.filter; import com.gargoylesoftware.base.testing.EqualsTester; import org.junit.Test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Mattias Hellborg Arthursson @@ -35,7 +35,7 @@ public class GreaterThanOrEqualsFilterTest { StringBuffer buff = new StringBuffer(); eqq.encode(buff); - assertEquals("(foo>=\\2abar\\28fie\\29)", buff.toString()); + assertThat(buff.toString()).isEqualTo("(foo>=\\2abar\\28fie\\29)"); } @@ -48,7 +48,7 @@ public class GreaterThanOrEqualsFilterTest { StringBuffer buff = new StringBuffer(); eqq.encode(buff); - assertEquals("(foo>=456)", buff.toString()); + assertThat(buff.toString()).isEqualTo("(foo>=456)"); } diff --git a/core/src/test/java/org/springframework/ldap/filter/HardcodedFilterTest.java b/core/src/test/java/org/springframework/ldap/filter/HardcodedFilterTest.java index 3e154ded..516d95e5 100644 --- a/core/src/test/java/org/springframework/ldap/filter/HardcodedFilterTest.java +++ b/core/src/test/java/org/springframework/ldap/filter/HardcodedFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ package org.springframework.ldap.filter; import com.gargoylesoftware.base.testing.EqualsTester; import org.junit.Test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Unit tests for the HardcodedFilter class. @@ -30,20 +30,20 @@ public class HardcodedFilterTest { @Test public void testHardcodedFilter() { HardcodedFilter filter = new HardcodedFilter("(foo=a*b)"); - assertEquals("(foo=a*b)", filter.encode()); + assertThat(filter.encode()).isEqualTo("(foo=a*b)"); NotFilter notFilter = new NotFilter(new HardcodedFilter("(foo=a*b)")); - assertEquals("(!(foo=a*b))", notFilter.encode()); + assertThat(notFilter.encode()).isEqualTo("(!(foo=a*b))"); AndFilter andFilter = new AndFilter(); andFilter.and(new HardcodedFilter("(foo=a*b)")); andFilter.and(new HardcodedFilter("(bar=a*b)")); - assertEquals("(&(foo=a*b)(bar=a*b))", andFilter.encode()); + assertThat(andFilter.encode()).isEqualTo("(&(foo=a*b)(bar=a*b))"); andFilter = new AndFilter(); andFilter.and(new HardcodedFilter("(foo=a*b)")); andFilter.and(new NotFilter(new HardcodedFilter("(bar=a*b)"))); - assertEquals("(&(foo=a*b)(!(bar=a*b)))", andFilter.encode()); + assertThat(andFilter.encode()).isEqualTo("(&(foo=a*b)(!(bar=a*b)))"); } @Test @@ -58,4 +58,4 @@ public class HardcodedFilterTest { new EqualsTester(originalObject, identicalObject, differentObject, subclassObject); } -} \ No newline at end of file +} diff --git a/core/src/test/java/org/springframework/ldap/filter/LessThanOrEqualsFilterTest.java b/core/src/test/java/org/springframework/ldap/filter/LessThanOrEqualsFilterTest.java index 7e7d0402..943c7cef 100644 --- a/core/src/test/java/org/springframework/ldap/filter/LessThanOrEqualsFilterTest.java +++ b/core/src/test/java/org/springframework/ldap/filter/LessThanOrEqualsFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ package org.springframework.ldap.filter; import com.gargoylesoftware.base.testing.EqualsTester; import org.junit.Test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Mattias Hellborg Arthursson @@ -35,7 +35,7 @@ public class LessThanOrEqualsFilterTest { StringBuffer buff = new StringBuffer(); eqq.encode(buff); - assertEquals("(foo<=\\2abar\\28fie\\29)", buff.toString()); + assertThat(buff.toString()).isEqualTo("(foo<=\\2abar\\28fie\\29)"); } @@ -47,7 +47,7 @@ public class LessThanOrEqualsFilterTest { StringBuffer buff = new StringBuffer(); eqq.encode(buff); - assertEquals("(foo<=456)", buff.toString()); + assertThat(buff.toString()).isEqualTo("(foo<=456)"); } diff --git a/core/src/test/java/org/springframework/ldap/filter/LikeFilterTest.java b/core/src/test/java/org/springframework/ldap/filter/LikeFilterTest.java index 1b45ff35..d92f64bf 100644 --- a/core/src/test/java/org/springframework/ldap/filter/LikeFilterTest.java +++ b/core/src/test/java/org/springframework/ldap/filter/LikeFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ package org.springframework.ldap.filter; import com.gargoylesoftware.base.testing.EqualsTester; import org.junit.Test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Anders Henja @@ -28,25 +28,25 @@ public class LikeFilterTest { @Test public void testEncodeValue_blank() { - assertEquals("", new LikeFilter("", null).getEncodedValue()); - assertEquals(" ", new LikeFilter("", " ").getEncodedValue()); + assertThat("").isEqualTo(new LikeFilter("", null).getEncodedValue()); + assertThat(" ").isEqualTo(new LikeFilter("", " ").getEncodedValue()); } @Test public void testEncodeValue_normal() { - assertEquals("foo", new LikeFilter("", "foo").getEncodedValue()); - assertEquals("foo*bar", new LikeFilter("", "foo*bar").getEncodedValue()); - assertEquals("*foo*bar*", new LikeFilter("", "*foo*bar*") + assertThat("foo").isEqualTo(new LikeFilter("", "foo").getEncodedValue()); + assertThat("foo*bar").isEqualTo(new LikeFilter("", "foo*bar").getEncodedValue()); + assertThat("*foo*bar*").isEqualTo(new LikeFilter("", "*foo*bar*") .getEncodedValue()); - assertEquals("**foo**bar**", new LikeFilter("", "**foo**bar**") + assertThat("**foo**bar**").isEqualTo(new LikeFilter("", "**foo**bar**") .getEncodedValue()); } @Test public void testEncodeValue_escape() { - assertEquals("*\\28*\\29*", new LikeFilter("", "*(*)*") + assertThat("*\\28*\\29*").isEqualTo(new LikeFilter("", "*(*)*") .getEncodedValue()); - assertEquals("*\\5c2a*", new LikeFilter("", "*\\2a*").getEncodedValue()); + assertThat("*\\5c2a*").isEqualTo(new LikeFilter("", "*\\2a*").getEncodedValue()); } @Test diff --git a/core/src/test/java/org/springframework/ldap/filter/NotFilterTest.java b/core/src/test/java/org/springframework/ldap/filter/NotFilterTest.java index 221f1651..b40495e3 100644 --- a/core/src/test/java/org/springframework/ldap/filter/NotFilterTest.java +++ b/core/src/test/java/org/springframework/ldap/filter/NotFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ package org.springframework.ldap.filter; import com.gargoylesoftware.base.testing.EqualsTester; import org.junit.Test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Unit tests for the NotFilter class. @@ -33,7 +33,7 @@ public class NotFilterTest { EqualsFilter filter = new EqualsFilter("a", "b"); NotFilter notFilter = new NotFilter(filter); - assertEquals("(!(a=b))", notFilter.encode()); + assertThat(notFilter.encode()).isEqualTo("(!(a=b))"); } @Test diff --git a/core/src/test/java/org/springframework/ldap/filter/NotPresentFilterTest.java b/core/src/test/java/org/springframework/ldap/filter/NotPresentFilterTest.java index ef6c8516..fd4f0ea2 100644 --- a/core/src/test/java/org/springframework/ldap/filter/NotPresentFilterTest.java +++ b/core/src/test/java/org/springframework/ldap/filter/NotPresentFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ package org.springframework.ldap.filter; import com.gargoylesoftware.base.testing.EqualsTester; import org.junit.Test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Unit tests for the NotPresentFilter class. @@ -30,20 +30,20 @@ public class NotPresentFilterTest { @Test public void testNotPresentFilter() { NotPresentFilter filter = new NotPresentFilter("foo"); - assertEquals("(!(foo=*))", filter.encode()); + assertThat(filter.encode()).isEqualTo("(!(foo=*))"); NotFilter notFilter = new NotFilter(new NotPresentFilter("foo")); - assertEquals("(!(!(foo=*)))", notFilter.encode()); + assertThat(notFilter.encode()).isEqualTo("(!(!(foo=*)))"); AndFilter andFilter = new AndFilter(); andFilter.and(new NotPresentFilter("foo")); andFilter.and(new NotPresentFilter("bar")); - assertEquals("(&(!(foo=*))(!(bar=*)))", andFilter.encode()); + assertThat(andFilter.encode()).isEqualTo("(&(!(foo=*))(!(bar=*)))"); andFilter = new AndFilter(); andFilter.and(new NotPresentFilter("foo")); andFilter.and(new NotFilter(new NotPresentFilter("bar"))); - assertEquals("(&(!(foo=*))(!(!(bar=*))))", andFilter.encode()); + assertThat(andFilter.encode()).isEqualTo("(&(!(foo=*))(!(!(bar=*))))"); } @Test @@ -58,4 +58,4 @@ public class NotPresentFilterTest { new EqualsTester(originalObject, identicalObject, differentObject, subclassObject); } -} \ No newline at end of file +} diff --git a/core/src/test/java/org/springframework/ldap/filter/OrFilterTest.java b/core/src/test/java/org/springframework/ldap/filter/OrFilterTest.java index f927bc78..54dea90d 100644 --- a/core/src/test/java/org/springframework/ldap/filter/OrFilterTest.java +++ b/core/src/test/java/org/springframework/ldap/filter/OrFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ package org.springframework.ldap.filter; import org.junit.Test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Unit tests for the OrFilter class. @@ -31,14 +31,14 @@ public class OrFilterTest { public void testZero() { OrFilter of = new OrFilter(); - assertEquals("", of.encode()); + assertThat(of.encode()).isEqualTo(""); } @Test public void testOne() { OrFilter of = new OrFilter().or(new EqualsFilter("a", "b")); - assertEquals("(a=b)", of.encode()); + assertThat(of.encode()).isEqualTo("(a=b)"); } @Test @@ -46,7 +46,7 @@ public class OrFilterTest { OrFilter of = new OrFilter().or(new EqualsFilter("a", "b")).or( new EqualsFilter("c", "d")); - assertEquals("(|(a=b)(c=d))", of.encode()); + assertThat(of.encode()).isEqualTo("(|(a=b)(c=d))"); } @Test @@ -54,7 +54,7 @@ public class OrFilterTest { OrFilter of = new OrFilter().or(new EqualsFilter("a", "b")).or( new EqualsFilter("c", "d")).or(new EqualsFilter("e", "f")); - assertEquals("(|(a=b)(c=d)(e=f))", of.encode()); + assertThat(of.encode()).isEqualTo("(|(a=b)(c=d)(e=f))"); } } diff --git a/core/src/test/java/org/springframework/ldap/filter/PresentFilterTest.java b/core/src/test/java/org/springframework/ldap/filter/PresentFilterTest.java index 209f047b..75951128 100644 --- a/core/src/test/java/org/springframework/ldap/filter/PresentFilterTest.java +++ b/core/src/test/java/org/springframework/ldap/filter/PresentFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ package org.springframework.ldap.filter; import com.gargoylesoftware.base.testing.EqualsTester; import org.junit.Test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Unit tests for the PresentFilter class. @@ -30,20 +30,20 @@ public class PresentFilterTest { @Test public void testPresentFilter() { PresentFilter filter = new PresentFilter("foo"); - assertEquals("(foo=*)", filter.encode()); + assertThat(filter.encode()).isEqualTo("(foo=*)"); NotFilter notFilter = new NotFilter(new PresentFilter("foo")); - assertEquals("(!(foo=*))", notFilter.encode()); + assertThat(notFilter.encode()).isEqualTo("(!(foo=*))"); AndFilter andFilter = new AndFilter(); andFilter.and(new PresentFilter("foo")); andFilter.and(new PresentFilter("bar")); - assertEquals("(&(foo=*)(bar=*))", andFilter.encode()); + assertThat(andFilter.encode()).isEqualTo("(&(foo=*)(bar=*))"); andFilter = new AndFilter(); andFilter.and(new PresentFilter("foo")); andFilter.and(new NotFilter(new PresentFilter("bar"))); - assertEquals("(&(foo=*)(!(bar=*)))", andFilter.encode()); + assertThat(andFilter.encode()).isEqualTo("(&(foo=*)(!(bar=*)))"); } @Test @@ -58,4 +58,4 @@ public class PresentFilterTest { new EqualsTester(originalObject, identicalObject, differentObject, subclassObject); } -} \ No newline at end of file +} diff --git a/core/src/test/java/org/springframework/ldap/filter/WhitespaceWildcardsFilterTest.java b/core/src/test/java/org/springframework/ldap/filter/WhitespaceWildcardsFilterTest.java index 128d8c4d..697734c7 100644 --- a/core/src/test/java/org/springframework/ldap/filter/WhitespaceWildcardsFilterTest.java +++ b/core/src/test/java/org/springframework/ldap/filter/WhitespaceWildcardsFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ package org.springframework.ldap.filter; import org.junit.Test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Unit tests for the WhitespaceWildcardsFilter class. @@ -31,13 +31,13 @@ public class WhitespaceWildcardsFilterTest { public void testEncodeValue_blank() { // blank - assertEquals("*", new WhitespaceWildcardsFilter("", null) + assertThat("*").isEqualTo(new WhitespaceWildcardsFilter("", null) .getEncodedValue()); - assertEquals("*", new WhitespaceWildcardsFilter("", " ") + assertThat("*").isEqualTo(new WhitespaceWildcardsFilter("", " ") .getEncodedValue()); - assertEquals("*", new WhitespaceWildcardsFilter("", " ") + assertThat("*").isEqualTo(new WhitespaceWildcardsFilter("", " ") .getEncodedValue()); - assertEquals("*", new WhitespaceWildcardsFilter("", "\t") + assertThat("*").isEqualTo(new WhitespaceWildcardsFilter("", "\t") .getEncodedValue()); } @@ -45,25 +45,24 @@ public class WhitespaceWildcardsFilterTest { @Test public void testEncodeValue_normal() { - assertEquals("*foo*", new WhitespaceWildcardsFilter("", "foo") + assertThat("*foo*").isEqualTo(new WhitespaceWildcardsFilter("", "foo") .getEncodedValue()); - assertEquals("*foo*bar*", new WhitespaceWildcardsFilter("", "foo bar") + assertThat("*foo*bar*").isEqualTo(new WhitespaceWildcardsFilter("", "foo bar") .getEncodedValue()); - assertEquals("*foo*bar*", - new WhitespaceWildcardsFilter("", " foo bar ") - .getEncodedValue()); - assertEquals("*foo*bar*", new WhitespaceWildcardsFilter("", - " \t foo \n bar \r ").getEncodedValue()); + assertThat(new WhitespaceWildcardsFilter("", " foo bar ") + .getEncodedValue()).isEqualTo("*foo*bar*"); + assertThat(new WhitespaceWildcardsFilter("", + " \t foo \n bar \r ").getEncodedValue()).isEqualTo("*foo*bar*"); } @Test public void testEncodeValue_escape() { - assertEquals("*\\28\\2a\\29*", new WhitespaceWildcardsFilter("", "(*)") + assertThat("*\\28\\2a\\29*").isEqualTo(new WhitespaceWildcardsFilter("", "(*)") .getEncodedValue()); - assertEquals("*\\2a*", new WhitespaceWildcardsFilter("", "*") + assertThat("*\\2a*").isEqualTo(new WhitespaceWildcardsFilter("", "*") .getEncodedValue()); - assertEquals("*\\5c*", new WhitespaceWildcardsFilter("", " \\ ") + assertThat("*\\5c*").isEqualTo(new WhitespaceWildcardsFilter("", " \\ ") .getEncodedValue()); } diff --git a/core/src/test/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapperTest.java b/core/src/test/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapperTest.java index 6914c92a..a6147488 100644 --- a/core/src/test/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapperTest.java +++ b/core/src/test/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapperTest.java @@ -1,30 +1,25 @@ package org.springframework.ldap.odm.core.impl; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.powermock.api.mockito.PowerMockito.spy; -import static org.powermock.api.mockito.PowerMockito.when; -import static org.springframework.ldap.query.LdapQueryBuilder.query; - import java.lang.reflect.Field; import javax.naming.Name; import org.junit.Before; import org.junit.Test; -import org.junit.matchers.JUnitMatchers; import org.junit.runner.RunWith; import org.mockito.internal.util.reflection.Whitebox; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; + import org.springframework.core.SpringVersion; import org.springframework.ldap.support.LdapUtils; import org.springframework.util.StringUtils; +import static org.assertj.core.api.Assertions.assertThat; +import static org.powermock.api.mockito.PowerMockito.spy; +import static org.powermock.api.mockito.PowerMockito.when; +import static org.springframework.ldap.query.LdapQueryBuilder.query; + /** * @author Mattias Hellborg Arthursson */ @@ -48,7 +43,7 @@ public class DefaultObjectDirectoryMapperTest { DefaultObjectDirectoryMapper mapper = new DefaultObjectDirectoryMapper(); // LDAP-300 - assertNotNull(Whitebox.getInternalState(mapper,"converterManager")); + assertThat(Whitebox.getInternalState(mapper,"converterManager")).isNotNull(); } @Test @@ -57,23 +52,23 @@ public class DefaultObjectDirectoryMapperTest { DefaultObjectDirectoryMapper.EntityData entityData = tested.getMetaDataMap().get(UnitTestPerson.class); - assertNotNull(entityData); - assertEquals(query(). + assertThat(entityData).isNotNull(); + assertThat(entityData.ocFilter).isEqualTo(query(). where("objectclass").is("inetOrgPerson") .and("objectclass").is("organizationalPerson") .and("objectclass").is("person") .and("objectclass").is("top") - .filter(), entityData.ocFilter); + .filter()); - assertEquals(7, entityData.metaData.size()); + assertThat(entityData.metaData).hasSize(7); AttributeMetaData idAttribute = entityData.metaData.getIdAttribute(); - assertEquals("dn", idAttribute.getField().getName()); - assertTrue(idAttribute.isId()); - assertFalse(idAttribute.isBinary()); - assertFalse(idAttribute.isDnAttribute()); - assertFalse(idAttribute.isTransient()); - assertFalse(idAttribute.isCollection()); + assertThat(idAttribute.getField().getName()).isEqualTo("dn"); + assertThat(idAttribute.isId()).isTrue(); + assertThat(idAttribute.isBinary()).isFalse(); + assertThat(idAttribute.isDnAttribute()).isFalse(); + assertThat(idAttribute.isTransient()).isFalse(); + assertThat(idAttribute.isCollection()).isFalse(); assertField(entityData, "fullName", "cn", "cn", false, false, false); assertField(entityData, "lastName", "sn", null, false, false, false); @@ -88,7 +83,7 @@ public class DefaultObjectDirectoryMapperTest { try { tested.manageClass(UnitTestPersonWithInvalidFieldType.class); } catch (InvalidEntryException expected) { - assertThat(expected.getMessage(), JUnitMatchers.containsString("Missing converter from")); + assertThat(expected.getMessage()).contains("Missing converter from"); } } @@ -103,7 +98,7 @@ public class DefaultObjectDirectoryMapperTest { Name calculatedId = tested.getCalculatedId(testPerson); - assertEquals(LdapUtils.newLdapName("cn=Some Person, ou=Some Company, c=Sweden"), calculatedId); + assertThat(calculatedId).isEqualTo(LdapUtils.newLdapName("cn=Some Person, ou=Some Company, c=Sweden")); } @Test(expected = MetaDataException.class) @@ -123,21 +118,21 @@ public class DefaultObjectDirectoryMapperTest { if (fieldName.equals(field.getName())) { AttributeMetaData attribute = entityData.metaData.getAttribute(field); if (StringUtils.hasLength(expectedAttributeName)) { - assertEquals(expectedAttributeName, attribute.getName().toString()); + assertThat(attribute.getName().toString()).isEqualTo(expectedAttributeName); } else { - assertNull(attribute.getName()); + assertThat(attribute.getName()).isNull(); } if (StringUtils.hasLength(expectedDnAttributeName)) { - assertTrue(attribute.isDnAttribute()); - assertEquals(expectedDnAttributeName, attribute.getDnAttribute().value()); + assertThat(attribute.isDnAttribute()).isTrue(); + assertThat(attribute.getDnAttribute().value()).isEqualTo(expectedDnAttributeName); } else { - assertFalse(attribute.isDnAttribute()); + assertThat(attribute.isDnAttribute()).isFalse(); } - assertEquals(expectedBinary, attribute.isBinary()); - assertEquals(expectedTransient, attribute.isTransient()); - assertEquals(expectedList, attribute.isCollection()); + assertThat(attribute.isBinary()).isEqualTo(expectedBinary); + assertThat(attribute.isTransient()).isEqualTo(expectedTransient); + assertThat(attribute.isCollection()).isEqualTo(expectedList); } } } diff --git a/core/src/test/java/org/springframework/ldap/pool/DelegatingContextTest.java b/core/src/test/java/org/springframework/ldap/pool/DelegatingContextTest.java index 2416ee26..b97be356 100644 --- a/core/src/test/java/org/springframework/ldap/pool/DelegatingContextTest.java +++ b/core/src/test/java/org/springframework/ldap/pool/DelegatingContextTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,11 +22,8 @@ import javax.naming.Context; import javax.naming.Name; import javax.naming.NamingException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -44,7 +41,7 @@ public class DelegatingContextTest extends AbstractPoolTestCase { new DelegatingContext(null, contextMock, DirContextType.READ_ONLY); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } try { @@ -52,14 +49,14 @@ public class DelegatingContextTest extends AbstractPoolTestCase { DirContextType.READ_ONLY); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } try { new DelegatingContext(keyedObjectPoolMock, contextMock, null); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @@ -70,11 +67,11 @@ public class DelegatingContextTest extends AbstractPoolTestCase { keyedObjectPoolMock, contextMock, DirContextType.READ_ONLY); final Context delegateContext = delegatingContext.getDelegateContext(); - assertEquals(contextMock, delegateContext); + assertThat(delegateContext).isEqualTo(contextMock); final Context innerDelegateContext = delegatingContext .getInnermostDelegateContext(); - assertEquals(contextMock, innerDelegateContext); + assertThat(innerDelegateContext).isEqualTo(contextMock); delegatingContext.assertOpen(); @@ -87,11 +84,11 @@ public class DelegatingContextTest extends AbstractPoolTestCase { final Context delegateContext2 = delegatingContext2 .getDelegateContext(); - assertEquals(delegatingContext, delegateContext2); + assertThat(delegateContext2).isEqualTo(delegatingContext); final Context innerDelegateContext2 = delegatingContext2 .getInnermostDelegateContext(); - assertEquals(contextMock, innerDelegateContext2); + assertThat(innerDelegateContext2).isEqualTo(contextMock); delegatingContext2.assertOpen(); @@ -100,11 +97,11 @@ public class DelegatingContextTest extends AbstractPoolTestCase { final Context delegateContext2closed = delegatingContext2 .getDelegateContext(); - assertNull(delegateContext2closed); + assertThat(delegateContext2closed).isNull(); final Context innerDelegateContext2closed = delegatingContext2 .getInnermostDelegateContext(); - assertNull(innerDelegateContext2closed); + assertThat(innerDelegateContext2closed).isNull(); try { delegatingContext2.assertOpen(); @@ -118,11 +115,11 @@ public class DelegatingContextTest extends AbstractPoolTestCase { final Context delegateContextclosed = delegatingContext .getDelegateContext(); - assertNull(delegateContextclosed); + assertThat(delegateContextclosed).isNull(); final Context innerDelegateContextclosed = delegatingContext .getInnermostDelegateContext(); - assertNull(innerDelegateContextclosed); + assertThat(innerDelegateContextclosed).isNull(); try { delegatingContext.assertOpen(); @@ -141,31 +138,31 @@ public class DelegatingContextTest extends AbstractPoolTestCase { // Wrap the Context once final DelegatingContext delegatingContext = new DelegatingContext( keyedObjectPoolMock, contextMock, DirContextType.READ_ONLY); - assertEquals(contextMock.toString(), delegatingContext.toString()); + assertThat(delegatingContext.toString()).isEqualTo(contextMock.toString()); delegatingContext.hashCode(); // Run it to make sure it doesn't fail - assertTrue(delegatingContext.equals(delegatingContext)); - assertFalse(delegatingContext.equals(new Object())); + assertThat(delegatingContext.equals(delegatingContext)).isTrue(); + assertThat(delegatingContext.equals(new Object())).isFalse(); final DelegatingContext delegatingContext2 = new DelegatingContext( keyedObjectPoolMock, contextMock, DirContextType.READ_ONLY); - assertTrue(delegatingContext.equals(delegatingContext2)); - assertTrue(delegatingContext2.equals(delegatingContext)); - assertTrue(delegatingContext.equals(contextMock)); + assertThat(delegatingContext.equals(delegatingContext2)).isTrue(); + assertThat(delegatingContext2.equals(delegatingContext)).isTrue(); + assertThat(delegatingContext.equals(contextMock)).isTrue(); // Close the contextMock and try again delegatingContext.close(); - assertEquals("Context is closed", delegatingContext.toString()); - assertEquals(0, delegatingContext.hashCode()); // Run it to make sure + assertThat(delegatingContext.toString()).isEqualTo("Context is closed"); + assertThat(delegatingContext.hashCode()).isEqualTo(0); // Run it to make sure // it doesn't fail - assertTrue(delegatingContext.equals(delegatingContext)); - assertFalse(delegatingContext.equals(new Object())); + assertThat(delegatingContext.equals(delegatingContext)).isTrue(); + assertThat(delegatingContext.equals(new Object())).isFalse(); - assertFalse(delegatingContext.equals(delegatingContext2)); - assertFalse(delegatingContext2.equals(delegatingContext)); - assertFalse(delegatingContext.equals(contextMock)); + assertThat(delegatingContext.equals(delegatingContext2)).isFalse(); + assertThat(delegatingContext2.equals(delegatingContext)).isFalse(); + assertThat(delegatingContext.equals(contextMock)).isFalse(); verify(keyedObjectPoolMock).returnObject(DirContextType.READ_ONLY, contextMock); } diff --git a/core/src/test/java/org/springframework/ldap/pool/DelegatingDirContextTest.java b/core/src/test/java/org/springframework/ldap/pool/DelegatingDirContextTest.java index 1f1c2f5d..320671d8 100644 --- a/core/src/test/java/org/springframework/ldap/pool/DelegatingDirContextTest.java +++ b/core/src/test/java/org/springframework/ldap/pool/DelegatingDirContextTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,11 +24,8 @@ import javax.naming.NamingException; import javax.naming.directory.Attributes; import javax.naming.directory.DirContext; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -45,14 +42,14 @@ public class DelegatingDirContextTest extends AbstractPoolTestCase { DirContextType.READ_ONLY); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } try { new DelegatingDirContext(keyedObjectPoolMock, dirContextMock, null); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @@ -65,15 +62,15 @@ public class DelegatingDirContextTest extends AbstractPoolTestCase { final Context delegateContext = delegatingDirContext .getDelegateContext(); - assertEquals(dirContextMock, delegateContext); + assertThat(delegateContext).isEqualTo(dirContextMock); final DirContext delegateDirContext = delegatingDirContext .getDelegateDirContext(); - assertEquals(dirContextMock, delegateDirContext); + assertThat(delegateDirContext).isEqualTo(dirContextMock); final DirContext innerDelegateDirContext = delegatingDirContext .getInnermostDelegateDirContext(); - assertEquals(dirContextMock, innerDelegateDirContext); + assertThat(innerDelegateDirContext).isEqualTo(dirContextMock); delegatingDirContext.assertOpen(); @@ -86,11 +83,11 @@ public class DelegatingDirContextTest extends AbstractPoolTestCase { final DirContext delegateDirContext2 = delegatingDirContext2 .getDelegateDirContext(); - assertEquals(delegatingDirContext, delegateDirContext2); + assertThat(delegateDirContext2).isEqualTo(delegatingDirContext); final DirContext innerDelegateDirContext2 = delegatingDirContext2 .getInnermostDelegateDirContext(); - assertEquals(dirContextMock, innerDelegateDirContext2); + assertThat(innerDelegateDirContext2).isEqualTo(dirContextMock); delegatingDirContext2.assertOpen(); @@ -99,11 +96,11 @@ public class DelegatingDirContextTest extends AbstractPoolTestCase { final DirContext delegateContext2closed = delegatingDirContext2 .getDelegateDirContext(); - assertNull(delegateContext2closed); + assertThat(delegateContext2closed).isNull(); final DirContext innerDelegateContext2closed = delegatingDirContext2 .getInnermostDelegateDirContext(); - assertNull(innerDelegateContext2closed); + assertThat(innerDelegateContext2closed).isNull(); try { delegatingDirContext2.assertOpen(); @@ -117,11 +114,11 @@ public class DelegatingDirContextTest extends AbstractPoolTestCase { final DirContext delegateDirContextClosed = delegatingDirContext .getDelegateDirContext(); - assertNull(delegateDirContextClosed); + assertThat(delegateDirContextClosed).isNull(); final DirContext innerDelegateDirContextClosed = delegatingDirContext .getInnermostDelegateDirContext(); - assertNull(innerDelegateDirContextClosed); + assertThat(innerDelegateDirContextClosed).isNull(); try { delegatingDirContext.assertOpen(); @@ -140,33 +137,33 @@ public class DelegatingDirContextTest extends AbstractPoolTestCase { // Wrap the DirContext once final DelegatingDirContext delegatingDirContext = new DelegatingDirContext( keyedObjectPoolMock, dirContextMock, DirContextType.READ_ONLY); - assertEquals(dirContextMock.toString(), delegatingDirContext.toString()); + assertThat(delegatingDirContext.toString()).isEqualTo(dirContextMock.toString()); delegatingDirContext.hashCode(); // Run it to make sure it doesn't // fail - assertTrue(delegatingDirContext.equals(delegatingDirContext)); - assertFalse(delegatingDirContext.equals(new Object())); + assertThat(delegatingDirContext.equals(delegatingDirContext)).isTrue(); + assertThat(delegatingDirContext.equals(new Object())).isFalse(); final DelegatingDirContext delegatingDirContext2 = new DelegatingDirContext( keyedObjectPoolMock, dirContextMock, DirContextType.READ_ONLY); - assertTrue(delegatingDirContext.equals(delegatingDirContext2)); - assertTrue(delegatingDirContext2.equals(delegatingDirContext)); - assertTrue(delegatingDirContext.equals(dirContextMock)); + assertThat(delegatingDirContext.equals(delegatingDirContext2)).isTrue(); + assertThat(delegatingDirContext2.equals(delegatingDirContext)).isTrue(); + assertThat(delegatingDirContext.equals(dirContextMock)).isTrue(); // Close the context and try again delegatingDirContext.close(); - assertEquals("DirContext is closed", delegatingDirContext.toString()); - assertEquals(0, delegatingDirContext.hashCode()); // Run it to make + assertThat(delegatingDirContext.toString()).isEqualTo("DirContext is closed"); + assertThat(delegatingDirContext.hashCode()).isEqualTo(0); // Run it to make // sure it doesn't // fail - assertTrue(delegatingDirContext.equals(delegatingDirContext)); - assertFalse(delegatingDirContext.equals(new Object())); + assertThat(delegatingDirContext.equals(delegatingDirContext)).isTrue(); + assertThat(delegatingDirContext.equals(new Object())).isFalse(); - assertFalse(delegatingDirContext.equals(delegatingDirContext2)); - assertFalse(delegatingDirContext2.equals(delegatingDirContext)); - assertFalse(delegatingDirContext.equals(dirContextMock)); + assertThat(delegatingDirContext.equals(delegatingDirContext2)).isFalse(); + assertThat(delegatingDirContext2.equals(delegatingDirContext)).isFalse(); + assertThat(delegatingDirContext.equals(dirContextMock)).isFalse(); verify(keyedObjectPoolMock).returnObject(DirContextType.READ_ONLY, dirContextMock); } @@ -384,4 +381,4 @@ public class DelegatingDirContextTest extends AbstractPoolTestCase { verify(keyedObjectPoolMock, times(1)).returnObject(DirContextType.READ_ONLY, dirContextMock); } -} \ No newline at end of file +} diff --git a/core/src/test/java/org/springframework/ldap/pool/DelegatingLdapContextTest.java b/core/src/test/java/org/springframework/ldap/pool/DelegatingLdapContextTest.java index 15c6b1ab..e4ef3631 100644 --- a/core/src/test/java/org/springframework/ldap/pool/DelegatingLdapContextTest.java +++ b/core/src/test/java/org/springframework/ldap/pool/DelegatingLdapContextTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,11 +22,8 @@ import javax.naming.NamingException; import javax.naming.directory.DirContext; import javax.naming.ldap.LdapContext; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -43,7 +40,7 @@ public class DelegatingLdapContextTest extends AbstractPoolTestCase { DirContextType.READ_ONLY); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } try { @@ -51,7 +48,7 @@ public class DelegatingLdapContextTest extends AbstractPoolTestCase { null); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @@ -63,15 +60,15 @@ public class DelegatingLdapContextTest extends AbstractPoolTestCase { final DirContext delegateDirContext = delegatingLdapContext .getDelegateDirContext(); - assertEquals(ldapContextMock, delegateDirContext); + assertThat(delegateDirContext).isEqualTo(ldapContextMock); final LdapContext delegateLdapContext = delegatingLdapContext .getDelegateLdapContext(); - assertEquals(ldapContextMock, delegateLdapContext); + assertThat(delegateLdapContext).isEqualTo(ldapContextMock); final LdapContext innerDelegateLdapContext = delegatingLdapContext .getInnermostDelegateLdapContext(); - assertEquals(ldapContextMock, innerDelegateLdapContext); + assertThat(innerDelegateLdapContext).isEqualTo(ldapContextMock); delegatingLdapContext.assertOpen(); @@ -84,11 +81,11 @@ public class DelegatingLdapContextTest extends AbstractPoolTestCase { final LdapContext delegateLdapContext2 = delegatingLdapContext2 .getDelegateLdapContext(); - assertEquals(delegatingLdapContext, delegateLdapContext2); + assertThat(delegateLdapContext2).isEqualTo(delegatingLdapContext); final LdapContext innerDelegateLdapContext2 = delegatingLdapContext2 .getInnermostDelegateLdapContext(); - assertEquals(ldapContextMock, innerDelegateLdapContext2); + assertThat(innerDelegateLdapContext2).isEqualTo(ldapContextMock); delegatingLdapContext2.assertOpen(); @@ -97,11 +94,11 @@ public class DelegatingLdapContextTest extends AbstractPoolTestCase { final LdapContext delegateContext2closed = delegatingLdapContext2 .getDelegateLdapContext(); - assertNull(delegateContext2closed); + assertThat(delegateContext2closed).isNull(); final LdapContext innerDelegateContext2closed = delegatingLdapContext2 .getInnermostDelegateLdapContext(); - assertNull(innerDelegateContext2closed); + assertThat(innerDelegateContext2closed).isNull(); try { delegatingLdapContext2.assertOpen(); @@ -115,11 +112,11 @@ public class DelegatingLdapContextTest extends AbstractPoolTestCase { final LdapContext delegateLdapContextClosed = delegatingLdapContext .getDelegateLdapContext(); - assertNull(delegateLdapContextClosed); + assertThat(delegateLdapContextClosed).isNull(); final LdapContext innerDelegateLdapContextClosed = delegatingLdapContext .getInnermostDelegateLdapContext(); - assertNull(innerDelegateLdapContextClosed); + assertThat(innerDelegateLdapContextClosed).isNull(); try { delegatingLdapContext.assertOpen(); @@ -138,33 +135,32 @@ public class DelegatingLdapContextTest extends AbstractPoolTestCase { // Wrap the LdapContext once final DelegatingLdapContext delegatingLdapContext = new DelegatingLdapContext( keyedObjectPoolMock, ldapContextMock, DirContextType.READ_ONLY); - assertEquals(ldapContextMock.toString(), - delegatingLdapContext.toString()); + assertThat(delegatingLdapContext.toString()).isEqualTo(ldapContextMock.toString()); delegatingLdapContext.hashCode(); // Run it to make sure it doesn't fail - assertTrue(delegatingLdapContext.equals(delegatingLdapContext)); - assertFalse(delegatingLdapContext.equals(new Object())); + assertThat(delegatingLdapContext.equals(delegatingLdapContext)).isTrue(); + assertThat(delegatingLdapContext.equals(new Object())).isFalse(); final DelegatingLdapContext delegatingLdapContext2 = new DelegatingLdapContext( keyedObjectPoolMock, ldapContextMock, DirContextType.READ_ONLY); - assertTrue(delegatingLdapContext.equals(delegatingLdapContext2)); - assertTrue(delegatingLdapContext2.equals(delegatingLdapContext)); - assertTrue(delegatingLdapContext.equals(ldapContextMock)); + assertThat(delegatingLdapContext.equals(delegatingLdapContext2)).isTrue(); + assertThat(delegatingLdapContext2.equals(delegatingLdapContext)).isTrue(); + assertThat(delegatingLdapContext.equals(ldapContextMock)).isTrue(); // Close the context and try again delegatingLdapContext.close(); - assertEquals("LdapContext is closed", delegatingLdapContext.toString()); - assertEquals(0, delegatingLdapContext.hashCode()); // Run it to make + assertThat(delegatingLdapContext.toString()).isEqualTo("LdapContext is closed"); + assertThat(delegatingLdapContext.hashCode()).isEqualTo(0); // Run it to make // sure it doesn't // fail - assertTrue(delegatingLdapContext.equals(delegatingLdapContext)); - assertFalse(delegatingLdapContext.equals(new Object())); + assertThat(delegatingLdapContext.equals(delegatingLdapContext)).isTrue(); + assertThat(delegatingLdapContext.equals(new Object())).isFalse(); - assertFalse(delegatingLdapContext.equals(delegatingLdapContext2)); - assertFalse(delegatingLdapContext2.equals(delegatingLdapContext)); - assertFalse(delegatingLdapContext.equals(ldapContextMock)); + assertThat(delegatingLdapContext.equals(delegatingLdapContext2)).isFalse(); + assertThat(delegatingLdapContext2.equals(delegatingLdapContext)).isFalse(); + assertThat(delegatingLdapContext.equals(ldapContextMock)).isFalse(); verify(keyedObjectPoolMock).returnObject(DirContextType.READ_ONLY, ldapContextMock); } diff --git a/core/src/test/java/org/springframework/ldap/pool/factory/DirContextPoolableObjectFactoryTest.java b/core/src/test/java/org/springframework/ldap/pool/factory/DirContextPoolableObjectFactoryTest.java index 2b04b8f9..45d7a7ee 100644 --- a/core/src/test/java/org/springframework/ldap/pool/factory/DirContextPoolableObjectFactoryTest.java +++ b/core/src/test/java/org/springframework/ldap/pool/factory/DirContextPoolableObjectFactoryTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,10 +27,8 @@ import javax.naming.directory.DirContext; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Proxy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -52,12 +50,12 @@ public class DirContextPoolableObjectFactoryTest extends AbstractPoolTestCase { catch (IllegalArgumentException iae) { // Expected } - + objectFactory.setContextSource(contextSourceMock); final ContextSource contextSource2 = objectFactory.getContextSource(); - assertEquals(contextSourceMock, contextSource2); - - + assertThat(contextSource2).isEqualTo(contextSourceMock); + + try { objectFactory.setDirContextValidator(null); fail("DirContextPoolableObjectFactory.setDirContextValidator should have thrown an IllegalArgumentException"); @@ -65,10 +63,10 @@ public class DirContextPoolableObjectFactoryTest extends AbstractPoolTestCase { catch (IllegalArgumentException iae) { // Expected } - + objectFactory.setDirContextValidator(dirContextValidatorMock); final DirContextValidator dirContextValidator2 = objectFactory.getDirContextValidator(); - assertEquals(dirContextValidatorMock, dirContextValidator2); + assertThat(dirContextValidator2).isEqualTo(dirContextValidatorMock); } @Test @@ -79,23 +77,23 @@ public class DirContextPoolableObjectFactoryTest extends AbstractPoolTestCase { objectFactory.makeObject(DirContextType.READ_ONLY); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } - + objectFactory.setContextSource(contextSourceMock); - + try { objectFactory.makeObject(null); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @Test public void testMakeObjectReadOnly() throws Exception { final DirContextPoolableObjectFactory objectFactory = new DirContextPoolableObjectFactory(); - + DirContext readOnlyContextMock = mock(DirContext.class); when(contextSourceMock.getReadOnlyContext()).thenReturn(readOnlyContextMock); @@ -103,13 +101,13 @@ public class DirContextPoolableObjectFactoryTest extends AbstractPoolTestCase { final Object createdDirContext = objectFactory.makeObject(DirContextType.READ_ONLY); InvocationHandler invocationHandler = Proxy.getInvocationHandler(createdDirContext); - assertEquals(readOnlyContextMock, Whitebox.getInternalState(invocationHandler, "target")); + assertThat(readOnlyContextMock).isEqualTo(Whitebox.getInternalState(invocationHandler, "target")); } @Test public void testMakeObjectReadWrite() throws Exception { final DirContextPoolableObjectFactory objectFactory = new DirContextPoolableObjectFactory(); - + DirContext readWriteContextMock = mock(DirContext.class); when(contextSourceMock.getReadWriteContext()).thenReturn(readWriteContextMock); @@ -118,7 +116,7 @@ public class DirContextPoolableObjectFactoryTest extends AbstractPoolTestCase { final Object createdDirContext = objectFactory.makeObject(DirContextType.READ_WRITE); InvocationHandler invocationHandler = Proxy.getInvocationHandler(createdDirContext); - assertEquals(readWriteContextMock, Whitebox.getInternalState(invocationHandler, "target")); + assertThat(readWriteContextMock).isEqualTo(Whitebox.getInternalState(invocationHandler, "target")); } @Test @@ -129,37 +127,37 @@ public class DirContextPoolableObjectFactoryTest extends AbstractPoolTestCase { objectFactory.validateObject(DirContextType.READ_ONLY, dirContextMock); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } - + objectFactory.setDirContextValidator(dirContextValidatorMock); - + try { objectFactory.validateObject(null, dirContextMock); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } - + try { objectFactory.validateObject(new Object(), dirContextMock); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } - + try { objectFactory.validateObject(DirContextType.READ_ONLY, null); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } - + try { objectFactory.validateObject(DirContextType.READ_ONLY, new Object()); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @@ -171,46 +169,46 @@ public class DirContextPoolableObjectFactoryTest extends AbstractPoolTestCase { final DirContextPoolableObjectFactory objectFactory = new DirContextPoolableObjectFactory(); objectFactory.setDirContextValidator(dirContextValidatorMock); - + final boolean valid = objectFactory.validateObject(DirContextType.READ_ONLY, dirContextMock); - assertTrue(valid); - + assertThat(valid).isTrue(); + //Check exception in validator DirContextValidator secondDirContextValidatorMock = mock(DirContextValidator.class); when(secondDirContextValidatorMock.validateDirContext(DirContextType.READ_ONLY, dirContextMock)) .thenThrow(new RuntimeException("Failed to validate")); objectFactory.setDirContextValidator(secondDirContextValidatorMock); - + final boolean valid2 = objectFactory.validateObject(DirContextType.READ_ONLY, dirContextMock); - assertFalse(valid2); + assertThat(valid2).isFalse(); } @Test public void testDestroyObjectAssertions() throws Exception { final DirContextPoolableObjectFactory objectFactory = new DirContextPoolableObjectFactory(); - + try { objectFactory.destroyObject(DirContextType.READ_ONLY, null); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } - + try { objectFactory.validateObject(DirContextType.READ_ONLY, new Object()); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @Test public void testDestroyObject() throws Exception { final DirContextPoolableObjectFactory objectFactory = new DirContextPoolableObjectFactory(); - + objectFactory.destroyObject(DirContextType.READ_ONLY, dirContextMock); - + DirContext throwingDirContextMock = Mockito.mock(DirContext.class); doThrow(new RuntimeException("Failed to close")) diff --git a/core/src/test/java/org/springframework/ldap/pool/factory/MutablePoolingContextSourceTest.java b/core/src/test/java/org/springframework/ldap/pool/factory/MutablePoolingContextSourceTest.java index f861dcc4..f06e271b 100644 --- a/core/src/test/java/org/springframework/ldap/pool/factory/MutablePoolingContextSourceTest.java +++ b/core/src/test/java/org/springframework/ldap/pool/factory/MutablePoolingContextSourceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import org.springframework.ldap.pool.MutableDelegatingLdapContext; import javax.naming.directory.DirContext; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; /** @@ -42,6 +42,6 @@ public class MutablePoolingContextSourceTest extends AbstractPoolTestCase { // Get a context final DirContext result = poolingContextSource.getReadOnlyContext(); - assertEquals(MutableDelegatingLdapContext.class, result.getClass()); + assertThat(result.getClass()).isEqualTo(MutableDelegatingLdapContext.class); } } diff --git a/core/src/test/java/org/springframework/ldap/pool/factory/PoolingContextSourceTest.java b/core/src/test/java/org/springframework/ldap/pool/factory/PoolingContextSourceTest.java index c11ab2b1..e40435f0 100644 --- a/core/src/test/java/org/springframework/ldap/pool/factory/PoolingContextSourceTest.java +++ b/core/src/test/java/org/springframework/ldap/pool/factory/PoolingContextSourceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,8 +25,8 @@ import org.springframework.ldap.pool.validation.DirContextValidator; import javax.naming.directory.DirContext; import javax.naming.ldap.LdapContext; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -48,7 +48,7 @@ public class PoolingContextSourceTest extends AbstractPoolTestCase { } poolingContextSource.setContextSource(contextSourceMock); final ContextSource contextSource2 = poolingContextSource.getContextSource(); - assertEquals(contextSourceMock, contextSource2); + assertThat(contextSource2).isEqualTo(contextSourceMock); try { poolingContextSource.setDirContextValidator(null); @@ -59,61 +59,61 @@ public class PoolingContextSourceTest extends AbstractPoolTestCase { } poolingContextSource.setDirContextValidator(dirContextValidatorMock); final DirContextValidator dirContextValidator2 = poolingContextSource.getDirContextValidator(); - assertEquals(dirContextValidatorMock, dirContextValidator2); + assertThat(dirContextValidator2).isEqualTo(dirContextValidatorMock); poolingContextSource.setMaxActive(1000); final int maxActive = poolingContextSource.getMaxActive(); - assertEquals(1000, maxActive); + assertThat(maxActive).isEqualTo(1000); poolingContextSource.setMaxIdle(500); final int maxIdle = poolingContextSource.getMaxIdle(); - assertEquals(500, maxIdle); + assertThat(maxIdle).isEqualTo(500); poolingContextSource.setMaxTotal(5000); final int maxTotal = poolingContextSource.getMaxTotal(); - assertEquals(5000, maxTotal); + assertThat(maxTotal).isEqualTo(5000); poolingContextSource.setMaxWait(2000L); final long maxWait = poolingContextSource.getMaxWait(); - assertEquals(2000L, maxWait); + assertThat(maxWait).isEqualTo(2000L); poolingContextSource.setMinEvictableIdleTimeMillis(60000L); final long minEvictableIdleTimeMillis = poolingContextSource.getMinEvictableIdleTimeMillis(); - assertEquals(60000L, minEvictableIdleTimeMillis); + assertThat(minEvictableIdleTimeMillis).isEqualTo(60000L); poolingContextSource.setMinIdle(100); final int minIdle = poolingContextSource.getMinIdle(); - assertEquals(100, minIdle); + assertThat(minIdle).isEqualTo(100); poolingContextSource.setNumTestsPerEvictionRun(5); final int numTestsPerEvictionRun = poolingContextSource.getNumTestsPerEvictionRun(); - assertEquals(5, numTestsPerEvictionRun); + assertThat(numTestsPerEvictionRun).isEqualTo(5); poolingContextSource.setTestOnBorrow(true); final boolean testOnBorrow = poolingContextSource.getTestOnBorrow(); - assertEquals(true, testOnBorrow); + assertThat(testOnBorrow).isEqualTo(true); poolingContextSource.setTestOnReturn(true); final boolean testOnReturn = poolingContextSource.getTestOnReturn(); - assertEquals(true, testOnReturn); + assertThat(testOnReturn).isEqualTo(true); poolingContextSource.setTestWhileIdle(true); final boolean testWhileIdle = poolingContextSource.getTestWhileIdle(); - assertEquals(true, testWhileIdle); + assertThat(testWhileIdle).isEqualTo(true); poolingContextSource.setTimeBetweenEvictionRunsMillis(120000L); final long timeBetweenEvictionRunsMillis = poolingContextSource.getTimeBetweenEvictionRunsMillis(); - assertEquals(120000L, timeBetweenEvictionRunsMillis); + assertThat(timeBetweenEvictionRunsMillis).isEqualTo(120000L); poolingContextSource.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK); final byte whenExhaustedAction = poolingContextSource.getWhenExhaustedAction(); - assertEquals(GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK, whenExhaustedAction); + assertThat(whenExhaustedAction).isEqualTo(GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK); final int numActive = poolingContextSource.getNumActive(); - assertEquals(0, numActive); + assertThat(numActive).isEqualTo(0); final int numIdle = poolingContextSource.getNumIdle(); - assertEquals(0, numIdle); + assertThat(numIdle).isEqualTo(0); } @Test @@ -127,36 +127,36 @@ public class PoolingContextSourceTest extends AbstractPoolTestCase { //Get a context final DirContext readOnlyContext1 = poolingContextSource.getReadOnlyContext(); - assertEquals(readOnlyContext1, dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic - assertEquals(1, poolingContextSource.getNumActive()); - assertEquals(0, poolingContextSource.getNumIdle()); + assertThat(readOnlyContext1).isEqualTo(dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic + assertThat(poolingContextSource.getNumActive()).isEqualTo(1); + assertThat(poolingContextSource.getNumIdle()).isEqualTo(0); //Close the context readOnlyContext1.close(); - assertEquals(0, poolingContextSource.getNumActive()); - assertEquals(1, poolingContextSource.getNumIdle()); + assertThat(poolingContextSource.getNumActive()).isEqualTo(0); + assertThat(poolingContextSource.getNumIdle()).isEqualTo(1); //Get the context again final DirContext readOnlyContext2 = poolingContextSource.getReadOnlyContext(); - assertEquals(readOnlyContext2, dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic - assertEquals(1, poolingContextSource.getNumActive()); - assertEquals(0, poolingContextSource.getNumIdle()); + assertThat(readOnlyContext2).isEqualTo(dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic + assertThat(poolingContextSource.getNumActive()).isEqualTo(1); + assertThat(poolingContextSource.getNumIdle()).isEqualTo(0); //Get a new context final DirContext readOnlyContext3 = poolingContextSource.getReadOnlyContext(); - assertEquals(readOnlyContext3, secondDirContextMock); //Order reversed because the 'wrapper' has the needed equals logic - assertEquals(2, poolingContextSource.getNumActive()); - assertEquals(0, poolingContextSource.getNumIdle()); + assertThat(readOnlyContext3).isEqualTo(secondDirContextMock); //Order reversed because the 'wrapper' has the needed equals logic + assertThat(poolingContextSource.getNumActive()).isEqualTo(2); + assertThat(poolingContextSource.getNumIdle()).isEqualTo(0); //Close context readOnlyContext2.close(); - assertEquals(1, poolingContextSource.getNumActive()); - assertEquals(1, poolingContextSource.getNumIdle()); + assertThat(poolingContextSource.getNumActive()).isEqualTo(1); + assertThat(poolingContextSource.getNumIdle()).isEqualTo(1); //Close context readOnlyContext3.close(); - assertEquals(0, poolingContextSource.getNumActive()); - assertEquals(2, poolingContextSource.getNumIdle()); + assertThat(poolingContextSource.getNumActive()).isEqualTo(0); + assertThat(poolingContextSource.getNumIdle()).isEqualTo(2); } @Test @@ -170,36 +170,36 @@ public class PoolingContextSourceTest extends AbstractPoolTestCase { //Get a context final DirContext readOnlyContext1 = poolingContextSource.getReadWriteContext(); - assertEquals(readOnlyContext1, dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic - assertEquals(1, poolingContextSource.getNumActive()); - assertEquals(0, poolingContextSource.getNumIdle()); + assertThat(readOnlyContext1).isEqualTo(dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic + assertThat(poolingContextSource.getNumActive()).isEqualTo(1); + assertThat(poolingContextSource.getNumIdle()).isEqualTo(0); //Close the context readOnlyContext1.close(); - assertEquals(0, poolingContextSource.getNumActive()); - assertEquals(1, poolingContextSource.getNumIdle()); + assertThat(poolingContextSource.getNumActive()).isEqualTo(0); + assertThat(poolingContextSource.getNumIdle()).isEqualTo(1); //Get the context again final DirContext readOnlyContext2 = poolingContextSource.getReadWriteContext(); - assertEquals(readOnlyContext2, dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic - assertEquals(1, poolingContextSource.getNumActive()); - assertEquals(0, poolingContextSource.getNumIdle()); + assertThat(readOnlyContext2).isEqualTo(dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic + assertThat(poolingContextSource.getNumActive()).isEqualTo(1); + assertThat(poolingContextSource.getNumIdle()).isEqualTo(0); //Get a new context final DirContext readOnlyContext3 = poolingContextSource.getReadWriteContext(); - assertEquals(readOnlyContext3, secondDirContextMock); //Order reversed because the 'wrapper' has the needed equals logic - assertEquals(2, poolingContextSource.getNumActive()); - assertEquals(0, poolingContextSource.getNumIdle()); + assertThat(readOnlyContext3).isEqualTo(secondDirContextMock); //Order reversed because the 'wrapper' has the needed equals logic + assertThat(poolingContextSource.getNumActive()).isEqualTo(2); + assertThat(poolingContextSource.getNumIdle()).isEqualTo(0); //Close context readOnlyContext2.close(); - assertEquals(1, poolingContextSource.getNumActive()); - assertEquals(1, poolingContextSource.getNumIdle()); + assertThat(poolingContextSource.getNumActive()).isEqualTo(1); + assertThat(poolingContextSource.getNumIdle()).isEqualTo(1); //Close context readOnlyContext3.close(); - assertEquals(0, poolingContextSource.getNumActive()); - assertEquals(2, poolingContextSource.getNumIdle()); + assertThat(poolingContextSource.getNumActive()).isEqualTo(0); + assertThat(poolingContextSource.getNumIdle()).isEqualTo(2); } @Test @@ -230,35 +230,35 @@ public class PoolingContextSourceTest extends AbstractPoolTestCase { //Get a context final DirContext readOnlyContext1 = poolingContextSource.getReadOnlyContext(); - assertEquals(readOnlyContext1, ldapContextMock); //Order reversed because the 'wrapper' has the needed equals logic - assertEquals(1, poolingContextSource.getNumActive()); - assertEquals(0, poolingContextSource.getNumIdle()); + assertThat(readOnlyContext1).isEqualTo(ldapContextMock); //Order reversed because the 'wrapper' has the needed equals logic + assertThat(poolingContextSource.getNumActive()).isEqualTo(1); + assertThat(poolingContextSource.getNumIdle()).isEqualTo(0); //Close the context readOnlyContext1.close(); - assertEquals(0, poolingContextSource.getNumActive()); - assertEquals(1, poolingContextSource.getNumIdle()); + assertThat(poolingContextSource.getNumActive()).isEqualTo(0); + assertThat(poolingContextSource.getNumIdle()).isEqualTo(1); //Get the context again final DirContext readOnlyContext2 = poolingContextSource.getReadOnlyContext(); - assertEquals(readOnlyContext2, ldapContextMock); //Order reversed because the 'wrapper' has the needed equals logic - assertEquals(1, poolingContextSource.getNumActive()); - assertEquals(0, poolingContextSource.getNumIdle()); + assertThat(readOnlyContext2).isEqualTo(ldapContextMock); //Order reversed because the 'wrapper' has the needed equals logic + assertThat(poolingContextSource.getNumActive()).isEqualTo(1); + assertThat(poolingContextSource.getNumIdle()).isEqualTo(0); //Get a new context final DirContext readOnlyContext3 = poolingContextSource.getReadOnlyContext(); - assertEquals(readOnlyContext3, secondLdapContextMock); //Order reversed because the 'wrapper' has the needed equals logic - assertEquals(2, poolingContextSource.getNumActive()); - assertEquals(0, poolingContextSource.getNumIdle()); + assertThat(readOnlyContext3).isEqualTo(secondLdapContextMock); //Order reversed because the 'wrapper' has the needed equals logic + assertThat(poolingContextSource.getNumActive()).isEqualTo(2); + assertThat(poolingContextSource.getNumIdle()).isEqualTo(0); //Close context readOnlyContext2.close(); - assertEquals(1, poolingContextSource.getNumActive()); - assertEquals(1, poolingContextSource.getNumIdle()); + assertThat(poolingContextSource.getNumActive()).isEqualTo(1); + assertThat(poolingContextSource.getNumIdle()).isEqualTo(1); //Close context readOnlyContext3.close(); - assertEquals(0, poolingContextSource.getNumActive()); - assertEquals(2, poolingContextSource.getNumIdle()); + assertThat(poolingContextSource.getNumActive()).isEqualTo(0); + assertThat(poolingContextSource.getNumIdle()).isEqualTo(2); } } diff --git a/core/src/test/java/org/springframework/ldap/pool/validation/DefaultDirContextValidatorTest.java b/core/src/test/java/org/springframework/ldap/pool/validation/DefaultDirContextValidatorTest.java index 44756718..eddf8f19 100644 --- a/core/src/test/java/org/springframework/ldap/pool/validation/DefaultDirContextValidatorTest.java +++ b/core/src/test/java/org/springframework/ldap/pool/validation/DefaultDirContextValidatorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,10 +24,8 @@ import javax.naming.NamingException; import javax.naming.directory.DirContext; import javax.naming.directory.SearchControls; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -51,21 +49,21 @@ public class DefaultDirContextValidatorTest { @Test public void testSearchScopeOneLevelScopeSetInConstructorIsUsed() throws Exception { DefaultDirContextValidator tested = new DefaultDirContextValidator(SearchControls.ONELEVEL_SCOPE); - assertEquals("ONELEVEL_SCOPE, ", SearchControls.ONELEVEL_SCOPE, tested.getSearchControls().getSearchScope()); + assertThat(tested.getSearchControls().getSearchScope()).as("ONELEVEL_SCOPE, ").isEqualTo(SearchControls.ONELEVEL_SCOPE); } // LDAP-189 @Test public void testSearchScopeSubTreeScopeSetInConstructorIsUsed() throws Exception { DefaultDirContextValidator tested = new DefaultDirContextValidator(SearchControls.SUBTREE_SCOPE); - assertEquals("SUBTREE_SCOPE, ", SearchControls.SUBTREE_SCOPE, tested.getSearchControls().getSearchScope()); + assertThat(tested.getSearchControls().getSearchScope()).as("SUBTREE_SCOPE, ").isEqualTo(SearchControls.SUBTREE_SCOPE); } // LDAP-189 @Test public void testSearchScopeObjectScopeSetInConstructorIsUsed() throws Exception { DefaultDirContextValidator tested = new DefaultDirContextValidator(SearchControls.OBJECT_SCOPE); - assertEquals("OBJECT_SCOPE, ", SearchControls.OBJECT_SCOPE, tested.getSearchControls().getSearchScope()); + assertThat(tested.getSearchControls().getSearchScope()).as("OBJECT_SCOPE, ").isEqualTo(SearchControls.OBJECT_SCOPE); } @Test @@ -74,28 +72,28 @@ public class DefaultDirContextValidatorTest { dirContextValidator.setBase("baseName"); final String baseName = dirContextValidator.getBase(); - assertEquals("baseName", baseName); + assertThat(baseName).isEqualTo("baseName"); try { dirContextValidator.setFilter(null); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } dirContextValidator.setFilter("filter"); final String filter = dirContextValidator.getFilter(); - assertEquals("filter", filter); + assertThat(filter).isEqualTo("filter"); try { dirContextValidator.setSearchControls(null); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } final SearchControls sc = new SearchControls(); dirContextValidator.setSearchControls(sc); final SearchControls sc2 = dirContextValidator.getSearchControls(); - assertEquals(sc, sc2); + assertThat(sc2).isEqualTo(sc); } @Test @@ -107,14 +105,14 @@ public class DefaultDirContextValidatorTest { null); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } try { dirContextValidator.validateDirContext(null, dirContextMock); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @@ -133,7 +131,7 @@ public class DefaultDirContextValidatorTest { final boolean valid = dirContextValidator.validateDirContext( DirContextType.READ_ONLY, dirContextMock); - assertTrue(valid); + assertThat(valid).isTrue(); } @Test @@ -152,7 +150,7 @@ public class DefaultDirContextValidatorTest { final boolean valid = dirContextValidator.validateDirContext( DirContextType.READ_ONLY, dirContextMock); - assertFalse(valid); + assertThat(valid).isFalse(); } @Test @@ -170,6 +168,6 @@ public class DefaultDirContextValidatorTest { final boolean valid = dirContextValidator.validateDirContext( DirContextType.READ_ONLY, dirContextMock); - assertFalse(valid); + assertThat(valid).isFalse(); } } diff --git a/core/src/test/java/org/springframework/ldap/pool2/DelegatingContextTest.java b/core/src/test/java/org/springframework/ldap/pool2/DelegatingContextTest.java index 9588d875..bc3548ba 100644 --- a/core/src/test/java/org/springframework/ldap/pool2/DelegatingContextTest.java +++ b/core/src/test/java/org/springframework/ldap/pool2/DelegatingContextTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2015 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,12 @@ import javax.naming.Context; import javax.naming.Name; import javax.naming.NamingException; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; /** * @author Eric Dalquist =John Doe)", result.filter().encode()); + assertThat(result.filter().encode()).isEqualTo("(cn>=John Doe)"); } @Test public void buildLessThanOrEquals() { LdapQuery result = query().where("cn").lte("John Doe"); - assertEquals("(cn<=John Doe)", result.filter().encode()); + assertThat(result.filter().encode()).isEqualTo("(cn<=John Doe)"); } @Test public void buildLike() { LdapQuery result = query().where("cn").like("J*hn Doe"); - assertEquals("(cn=J*hn Doe)", result.filter().encode()); + assertThat(result.filter().encode()).isEqualTo("(cn=J*hn Doe)"); } @@ -49,21 +48,21 @@ public class LdapQueryBuilderTest { public void buildWhitespaceWildcards() { LdapQuery result = query().where("cn").whitespaceWildcardsLike("John Doe"); - assertEquals("(cn=*John*Doe*)", result.filter().encode()); + assertThat(result.filter().encode()).isEqualTo("(cn=*John*Doe*)"); } @Test public void buildPresent() { LdapQuery result = query().where("cn").isPresent(); - assertEquals("(cn=*)", result.filter().encode()); + assertThat(result.filter().encode()).isEqualTo("(cn=*)"); } @Test public void buildHardcodedFilter() { LdapQuery result = query().filter("(cn=Person*)"); - assertEquals("(cn=Person*)", result.filter().encode()); + assertThat(result.filter().encode()).isEqualTo("(cn=Person*)"); } @Test(expected = IllegalStateException.class) @@ -84,7 +83,7 @@ public class LdapQueryBuilderTest { public void buildFilterFormat() { LdapQuery result = query().filter("(|(cn={0})(cn={1}))", "Person*", "Parson*"); - assertEquals("(|(cn=Person\\2a)(cn=Parson\\2a))", result.filter().encode()); + assertThat(result.filter().encode()).isEqualTo("(|(cn=Person\\2a)(cn=Parson\\2a))"); } @Test @@ -96,18 +95,18 @@ public class LdapQueryBuilderTest { .countLimit(221) .where("objectclass").is("person").and("cn").is("John Doe"); - assertEquals(LdapUtils.newLdapName("dc=261consulting, dc=com"), query.base()); - assertEquals(SearchScope.ONELEVEL, query.searchScope()); - assertEquals(Integer.valueOf(200), query.timeLimit()); - assertEquals(Integer.valueOf(221), query.countLimit()); - assertEquals("(&(objectclass=person)(cn=John Doe))", query.filter().encode()); + assertThat(query.base()).isEqualTo(LdapUtils.newLdapName("dc=261consulting, dc=com")); + assertThat(query.searchScope()).isEqualTo(SearchScope.ONELEVEL); + assertThat(query.timeLimit()).isEqualTo(Integer.valueOf(200)); + assertThat(query.countLimit()).isEqualTo(Integer.valueOf(221)); + assertThat(query.filter().encode()).isEqualTo("(&(objectclass=person)(cn=John Doe))"); } @Test public void buildSimpleOr() { LdapQuery result = query().where("objectclass").is("person").or("cn").is("John Doe"); - assertEquals("(|(objectclass=person)(cn=John Doe))", result.filter().encode()); + assertThat(result.filter().encode()).isEqualTo("(|(objectclass=person)(cn=John Doe))"); } @Test @@ -116,13 +115,13 @@ public class LdapQueryBuilderTest { .and("cn").is("John Doe") .or(query().where("sn").is("Doe")); - assertEquals("(|(&(objectclass=person)(cn=John Doe))(sn=Doe))", result.filter().encode()); + assertThat(result.filter().encode()).isEqualTo("(|(&(objectclass=person)(cn=John Doe))(sn=Doe))"); } @Test public void buildOrNegatedSubQueries() { LdapQuery result = query().where("objectclass").not().is("person").or("sn").not().is("Doe"); - assertEquals("(|(!(objectclass=person))(!(sn=Doe)))", result.filter().encode()); + assertThat(result.filter().encode()).isEqualTo("(|(!(objectclass=person))(!(sn=Doe)))"); } @Test @@ -132,7 +131,7 @@ public class LdapQueryBuilderTest { .and(query() .where("sn").is("Doe") .or("sn").like("Die")); - assertEquals("(&(objectclass=person)(|(sn=Doe)(sn=Die)))", result.filter().encode()); + assertThat(result.filter().encode()).isEqualTo("(&(objectclass=person)(|(sn=Doe)(sn=Die)))"); } @Test(expected = IllegalStateException.class) diff --git a/core/src/test/java/org/springframework/ldap/repository/SimpleLdapRepositoryTest.java b/core/src/test/java/org/springframework/ldap/repository/SimpleLdapRepositoryTest.java index 1cbd0c6c..b21f9208 100644 --- a/core/src/test/java/org/springframework/ldap/repository/SimpleLdapRepositoryTest.java +++ b/core/src/test/java/org/springframework/ldap/repository/SimpleLdapRepositoryTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2005-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.ldap.repository; import org.junit.Before; @@ -18,11 +34,7 @@ import javax.naming.ldap.LdapName; import java.util.Arrays; import java.util.Iterator; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; @@ -54,10 +66,10 @@ public class SimpleLdapRepositoryTest { long count = tested.count(); - assertEquals(0, count); + assertThat(count).isEqualTo(0); LdapQuery query = ldapQuery.getValue(); - assertEquals(filterMock, query.filter()); - assertArrayEquals(new String[]{"objectclass"}, query.attributes()); + assertThat(query.filter()).isEqualTo(filterMock); + assertThat(query.attributes()).isEqualTo(new String[]{"objectclass"}); } @Test @@ -147,7 +159,7 @@ public class SimpleLdapRepositoryTest { Object actualResult = tested.findOne(expectedName); - assertSame(expectedResult, actualResult); + assertThat(actualResult).isSameAs(expectedResult); } @Test @@ -158,7 +170,7 @@ public class SimpleLdapRepositoryTest { Object actualResult = tested.findOne(expectedName); - assertNull(actualResult); + assertThat(actualResult).isNull(); } @Test @@ -175,10 +187,10 @@ public class SimpleLdapRepositoryTest { Iterable actualResult = tested.findAll(Arrays.asList(expectedName1, expectedName2)); Iterator iterator = actualResult.iterator(); - assertSame(expectedResult1, iterator.next()); - assertSame(expectedResult2, iterator.next()); + assertThat(iterator.next()).isSameAs(expectedResult1); + assertThat(iterator.next()).isSameAs(expectedResult2); - assertFalse(iterator.hasNext()); + assertThat(iterator.hasNext()).isFalse(); } @Test @@ -194,9 +206,9 @@ public class SimpleLdapRepositoryTest { Iterable actualResult = tested.findAll(Arrays.asList(expectedName1, expectedName2)); Iterator iterator = actualResult.iterator(); - assertSame(expectedResult2, iterator.next()); + assertThat(iterator.next()).isSameAs(expectedResult2); - assertFalse(iterator.hasNext()); + assertThat(iterator.hasNext()).isFalse(); } } diff --git a/core/src/test/java/org/springframework/ldap/repository/config/AnnotationConfigTest.java b/core/src/test/java/org/springframework/ldap/repository/config/AnnotationConfigTest.java index e4fb65be..990a3758 100644 --- a/core/src/test/java/org/springframework/ldap/repository/config/AnnotationConfigTest.java +++ b/core/src/test/java/org/springframework/ldap/repository/config/AnnotationConfigTest.java @@ -4,7 +4,7 @@ import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.ldap.config.DummyLdapRepository; -import static org.junit.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Mattias Hellborg Arthursson @@ -16,6 +16,6 @@ public class AnnotationConfigTest { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-annotation-config.xml"); DummyLdapRepository repository = ctx.getBean(DummyLdapRepository.class); - assertNotNull(repository); + assertThat(repository).isNotNull(); } } diff --git a/core/src/test/java/org/springframework/ldap/repository/query/PartTreeLdapRepositoryQueryTest.java b/core/src/test/java/org/springframework/ldap/repository/query/PartTreeLdapRepositoryQueryTest.java index 2901a270..71a24d0f 100644 --- a/core/src/test/java/org/springframework/ldap/repository/query/PartTreeLdapRepositoryQueryTest.java +++ b/core/src/test/java/org/springframework/ldap/repository/query/PartTreeLdapRepositoryQueryTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2005-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.ldap.repository.query; import org.junit.Before; @@ -15,7 +31,7 @@ import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; import java.lang.reflect.Method; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Mattias Hellborg Arthursson @@ -165,7 +181,7 @@ public class PartTreeLdapRepositoryQueryTest extends AbstractJUnit4SpringContext LdapQuery query = tested.createQuery(expectedParams); String base = query.base().toString(); - assertEquals(expectedBase, base); - assertEquals(expectedFilter, query.filter().encode()); + assertThat(base).isEqualTo(expectedBase); + assertThat(query.filter().encode()).isEqualTo(expectedFilter); } } diff --git a/core/src/test/java/org/springframework/ldap/repository/support/QueryDslFilterGeneratorTest.java b/core/src/test/java/org/springframework/ldap/repository/support/QueryDslFilterGeneratorTest.java index daa72bac..05fc78d3 100644 --- a/core/src/test/java/org/springframework/ldap/repository/support/QueryDslFilterGeneratorTest.java +++ b/core/src/test/java/org/springframework/ldap/repository/support/QueryDslFilterGeneratorTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2005-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.ldap.repository.support; import com.querydsl.core.types.Expression; @@ -8,7 +24,7 @@ import org.springframework.ldap.odm.core.ObjectDirectoryMapper; import org.springframework.ldap.odm.core.impl.DefaultObjectDirectoryMapper; import org.springframework.ldap.odm.core.impl.UnitTestPerson; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Mattias Hellborg Arthursson @@ -30,21 +46,21 @@ public class QueryDslFilterGeneratorTest { public void testEqualsFilter() { Expression expression = person.fullName.eq("John Doe"); Filter result = tested.handle(expression); - assertEquals("(cn=John Doe)", result.toString()); + assertThat(result.toString()).isEqualTo("(cn=John Doe)"); } @Test public void testAndFilter() { Expression expression = person.fullName.eq("John Doe").and(person.lastName.eq("Doe")); Filter result = tested.handle(expression); - assertEquals("(&(cn=John Doe)(sn=Doe))", result.toString()); + assertThat(result.toString()).isEqualTo("(&(cn=John Doe)(sn=Doe))"); } @Test public void testOrFilter() { Expression expression = person.fullName.eq("John Doe").or(person.lastName.eq("Doe")); Filter result = tested.handle(expression); - assertEquals("(|(cn=John Doe)(sn=Doe))", result.toString()); + assertThat(result.toString()).isEqualTo("(|(cn=John Doe)(sn=Doe))"); } @Test @@ -53,55 +69,55 @@ public class QueryDslFilterGeneratorTest { .and(person.lastName.eq("Doe").or(person.lastName.eq("Die"))); Filter result = tested.handle(expression); - assertEquals("(&(cn=John Doe)(|(sn=Doe)(sn=Die)))", result.toString()); + assertThat(result.toString()).isEqualTo("(&(cn=John Doe)(|(sn=Doe)(sn=Die)))"); } @Test public void testNot() { Expression expression = person.fullName.eq("John Doe").not(); Filter result = tested.handle(expression); - assertEquals("(!(cn=John Doe))", result.toString()); + assertThat(result.toString()).isEqualTo("(!(cn=John Doe))"); } @Test public void testIsLike() { Expression expression = person.fullName.like("kalle*"); Filter result = tested.handle(expression); - assertEquals("(cn=kalle*)", result.toString()); + assertThat(result.toString()).isEqualTo("(cn=kalle*)"); } @Test public void testStartsWith() { Expression expression = person.fullName.startsWith("kalle"); Filter result = tested.handle(expression); - assertEquals("(cn=kalle*)", result.toString()); + assertThat(result.toString()).isEqualTo("(cn=kalle*)"); } @Test public void testEndsWith() { Expression expression = person.fullName.endsWith("kalle"); Filter result = tested.handle(expression); - assertEquals("(cn=*kalle)", result.toString()); + assertThat(result.toString()).isEqualTo("(cn=*kalle)"); } @Test public void testContains() { Expression expression = person.fullName.contains("kalle"); Filter result = tested.handle(expression); - assertEquals("(cn=*kalle*)", result.toString()); + assertThat(result.toString()).isEqualTo("(cn=*kalle*)"); } @Test public void testNotNull() { Expression expression = person.fullName.isNotNull(); Filter result = tested.handle(expression); - assertEquals("(cn=*)", result.toString()); + assertThat(result.toString()).isEqualTo("(cn=*)"); } @Test public void testNull() { Expression expression = person.fullName.isNull(); Filter result = tested.handle(expression); - assertEquals("(!(cn=*))", result.toString()); + assertThat(result.toString()).isEqualTo("(!(cn=*))"); } } diff --git a/core/src/test/java/org/springframework/ldap/support/LdapEncoderTest.java b/core/src/test/java/org/springframework/ldap/support/LdapEncoderTest.java index 1c9f87c9..d270a299 100644 --- a/core/src/test/java/org/springframework/ldap/support/LdapEncoderTest.java +++ b/core/src/test/java/org/springframework/ldap/support/LdapEncoderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ package org.springframework.ldap.support; import org.junit.Test; import org.springframework.ldap.BadLdapGrammarException; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Unit test for the LdapEncode class. @@ -31,7 +31,7 @@ public class LdapEncoderTest { @Test public void testFilterEncode() { String correct = "\\2aa\\2ab\\28c\\29d\\2a\\5c"; - assertEquals(correct, LdapEncoder.filterEncode("*a*b(c)d*\\")); + assertThat(LdapEncoder.filterEncode("*a*b(c)d*\\")).isEqualTo(correct); } @@ -40,7 +40,7 @@ public class LdapEncoderTest { String res = LdapEncoder.nameEncode("# foo ,+\"\\<>; "); - assertEquals("\\# foo \\,\\+\\\"\\\\\\<\\>\\;\\ ", res); + assertThat(res).isEqualTo("\\# foo \\,\\+\\\"\\\\\\<\\>\\;\\ "); } @Test @@ -49,7 +49,7 @@ public class LdapEncoderTest { String res = LdapEncoder .nameDecode("\\# foo \\,\\+\\\"\\\\\\<\\>\\;\\ "); - assertEquals("# foo ,+\"\\<>; ", res); + assertThat(res).isEqualTo("# foo ,+\"\\<>; "); } @Test(expected = BadLdapGrammarException.class) diff --git a/core/src/test/java/org/springframework/ldap/support/LdapNameBuilderTest.java b/core/src/test/java/org/springframework/ldap/support/LdapNameBuilderTest.java index a03ad5b0..f59877b6 100644 --- a/core/src/test/java/org/springframework/ldap/support/LdapNameBuilderTest.java +++ b/core/src/test/java/org/springframework/ldap/support/LdapNameBuilderTest.java @@ -2,7 +2,7 @@ package org.springframework.ldap.support; import org.junit.Test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Mattias Hellborg Arthursson @@ -12,43 +12,43 @@ public class LdapNameBuilderTest { @Test public void testAddComponentToEmpty() { LdapNameBuilder tested = LdapNameBuilder.newInstance().add("dc", "com").add("dc", "261consulting"); - assertEquals("dc=261consulting,dc=com", tested.build().toString()); + assertThat(tested.build().toString()).isEqualTo("dc=261consulting,dc=com"); } @Test public void testAddComponentToBaseString() { LdapNameBuilder tested = LdapNameBuilder.newInstance("dc=com").add("dc", "261consulting"); - assertEquals("dc=261consulting,dc=com", tested.build().toString()); + assertThat(tested.build().toString()).isEqualTo("dc=261consulting,dc=com"); } @Test public void testAddComponentToBaseName() { LdapNameBuilder tested = LdapNameBuilder.newInstance(LdapUtils.newLdapName("dc=com")).add("dc", "261consulting"); - assertEquals("dc=261consulting,dc=com", tested.build().toString()); + assertThat(tested.build().toString()).isEqualTo("dc=261consulting,dc=com"); } @Test public void testAddStringNameToBaseString() { LdapNameBuilder tested = LdapNameBuilder.newInstance("dc=261consulting,dc=com").add("ou=people"); - assertEquals("ou=people,dc=261consulting,dc=com", tested.build().toString()); + assertThat(tested.build().toString()).isEqualTo("ou=people,dc=261consulting,dc=com"); } @Test public void testAddNameToBaseString() { LdapNameBuilder tested = LdapNameBuilder.newInstance("dc=261consulting,dc=com").add(LdapUtils.newLdapName("ou=people")); - assertEquals("ou=people,dc=261consulting,dc=com", tested.build().toString()); + assertThat(tested.build().toString()).isEqualTo("ou=people,dc=261consulting,dc=com"); } @Test public void testAddNameToEmpty() { LdapNameBuilder tested = LdapNameBuilder.newInstance().add(LdapUtils.newLdapName("ou=people")); - assertEquals("ou=people", tested.build().toString()); + assertThat(tested.build().toString()).isEqualTo("ou=people"); } @Test public void testAddEmptyToEmpty() { LdapNameBuilder tested = LdapNameBuilder.newInstance().add(""); - assertEquals("", tested.build().toString()); + assertThat(tested.build().toString()).isEqualTo(""); } } diff --git a/core/src/test/java/org/springframework/ldap/support/LdapUtilsTest.java b/core/src/test/java/org/springframework/ldap/support/LdapUtilsTest.java index a0f42017..90919135 100644 --- a/core/src/test/java/org/springframework/ldap/support/LdapUtilsTest.java +++ b/core/src/test/java/org/springframework/ldap/support/LdapUtilsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,10 +28,8 @@ import javax.naming.directory.BasicAttributes; import javax.naming.ldap.LdapName; import java.util.LinkedList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -60,9 +58,9 @@ public class LdapUtilsTest { LinkedList list = new LinkedList(); LdapUtils.collectAttributeValues(attributes, expectedAttributeName, list); - assertEquals(2, list.size()); - assertEquals("value1", list.get(0)); - assertEquals("value2", list.get(1)); + assertThat(list).hasSize(2); + assertThat(list.get(0)).isEqualTo("value1"); + assertThat(list.get(1)).isEqualTo("value2"); } @Test @@ -75,7 +73,7 @@ public class LdapUtilsTest { LdapUtils.collectAttributeValues(attributes, expectedAttributeName, list); fail("NoSuchAttributeException expected"); } catch (NoSuchAttributeException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @@ -115,7 +113,7 @@ public class LdapUtilsTest { (byte) 0x82, (byte) 0x05, (byte) 0x1e, (byte) 0x6c, (byte) 0x28, (byte) 0x06, (byte) 0x00, (byte) 0x00}; String result = LdapUtils.convertBinarySidToString(sid); - assertEquals("S-1-5-21-2562418665-3218585558-1813906818-1576", result); + assertThat(result).isEqualTo("S-1-5-21-2562418665-3218585558-1813906818-1576"); } /** @@ -131,7 +129,7 @@ public class LdapUtilsTest { (byte) 0xe7, (byte) 0x7c, (byte) 0x87, (byte) 0x70, (byte) 0x09, (byte) 0x1c, (byte) 0x01, (byte) 0x00}; String result = LdapUtils.convertBinarySidToString(sid); - assertEquals("S-1-5-21-2127521184-1604012920-1887927527-72713", result); + assertThat(result).isEqualTo("S-1-5-21-2127521184-1604012920-1887927527-72713"); } /** @@ -147,51 +145,51 @@ public class LdapUtilsTest { (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00}; String result = LdapUtils.convertBinarySidToString(sid); - assertEquals("S-1-5-21-1-2-3-4", result); + assertThat(result).isEqualTo("S-1-5-21-1-2-3-4"); } @Test public void testSmallNumberToBytesBigEndian() throws Exception { byte[] result = LdapUtils.numberToBytes("5", 6, true); - assertEquals(6, result.length); - assertEquals(0, result[0]); - assertEquals(0, result[1]); - assertEquals(0, result[2]); - assertEquals(0, result[3]); - assertEquals(0, result[4]); - assertEquals(5, result[5]); + assertThat(result.length).isEqualTo(6); + assertThat(result[0]).isEqualTo((byte)0); + assertThat(result[1]).isEqualTo((byte)0); + assertThat(result[2]).isEqualTo((byte)0); + assertThat(result[3]).isEqualTo((byte)0); + assertThat(result[4]).isEqualTo((byte)0); + assertThat(result[5]).isEqualTo((byte)5); } @Test public void testLargeNumberToBytesBigEndian() throws Exception { byte[] result = LdapUtils.numberToBytes("1183728", 6, true); - assertEquals(6, result.length); - assertEquals(0, result[0]); - assertEquals(0, result[1]); - assertEquals(0, result[2]); - assertEquals(18, result[3]); - assertEquals(15, result[4]); - assertEquals(-16, result[5]); + assertThat(result.length).isEqualTo(6); + assertThat(result[0]).isEqualTo((byte)0); + assertThat(result[1]).isEqualTo((byte)0); + assertThat(result[2]).isEqualTo((byte)0); + assertThat(result[3]).isEqualTo((byte)18); + assertThat(result[4]).isEqualTo((byte)15); + assertThat(result[5]).isEqualTo((byte)-16); } @Test public void testSmallNumberToBytesLittleEndian() throws Exception { byte[] result = LdapUtils.numberToBytes("21", 4, false); - assertEquals(4, result.length); - assertEquals(21, result[0]); - assertEquals(0, result[1]); - assertEquals(0, result[2]); - assertEquals(0, result[3]); + assertThat(result.length).isEqualTo(4); + assertThat(result[0]).isEqualTo((byte)21); + assertThat(result[1]).isEqualTo((byte)0); + assertThat(result[2]).isEqualTo((byte)0); + assertThat(result[3]).isEqualTo((byte)0); } @Test public void testLargeNumberToBytesLittleEndian() throws Exception { byte[] result = LdapUtils.numberToBytes("2127521184", 4, false); - assertEquals(4, result.length); - assertEquals(-96, result[0]); - assertEquals(101, result[1]); - assertEquals(-49, result[2]); - assertEquals(126, result[3]); + assertThat(result.length).isEqualTo(4); + assertThat(result[0]).isEqualTo((byte)-96); + assertThat(result[1]).isEqualTo((byte)101); + assertThat(result[2]).isEqualTo((byte)-49); + assertThat(result[3]).isEqualTo((byte)126); } /** @@ -207,9 +205,9 @@ public class LdapUtilsTest { (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00}; byte[] result = LdapUtils.convertStringSidToBinary("S-1-5-21-1-2-3-4"); - assertTrue("incorrect length of array", ArrayUtils.isSameLength(expectedSid, result)); + assertThat(ArrayUtils.isSameLength(expectedSid, result)).isTrue(); for (int i = 0; i < result.length; i++) { - assertEquals("i=" + i + ",", expectedSid[i], result[i]); + assertThat(expectedSid[i]).isEqualTo(result[i]); } } @@ -226,9 +224,9 @@ public class LdapUtilsTest { (byte) 0x82, (byte) 0x05, (byte) 0x1e, (byte) 0x6c, (byte) 0x28, (byte) 0x06, (byte) 0x00, (byte) 0x00}; byte[] result = LdapUtils.convertStringSidToBinary("S-1-5-21-2562418665-3218585558-1813906818-1576"); - assertTrue("incorrect length of array", ArrayUtils.isSameLength(expectedSid, result)); + assertThat(ArrayUtils.isSameLength(expectedSid, result)).as("incorrect length of array").isTrue(); for (int i = 0; i < result.length; i++) { - assertEquals("i=" + i + ",", expectedSid[i], result[i]); + assertThat(expectedSid[i]).isEqualTo(result[i]); } } @@ -237,19 +235,19 @@ public class LdapUtilsTest { LdapName ldapName = new LdapName(EXPECTED_DN_STRING); LdapName result = LdapUtils.newLdapName(ldapName); - assertEquals(ldapName, result); + assertThat(result).isEqualTo(ldapName); } @Test public void testNewLdapNameFromCompositeName() throws InvalidNameException { LdapName result = LdapUtils.newLdapName(new CompositeName(EXPECTED_DN_STRING)); - assertEquals(new LdapName(EXPECTED_DN_STRING), result); + assertThat(result).isEqualTo(new LdapName(EXPECTED_DN_STRING)); } @Test public void testEmptyLdapName() { LdapName ldapName = LdapUtils.emptyLdapName(); - assertEquals("", ldapName.toString()); + assertThat(ldapName.toString()).isEqualTo(""); } @Test @@ -257,8 +255,8 @@ public class LdapUtilsTest { LdapName ldapName = new LdapName(EXPECTED_DN_STRING); LdapName result = LdapUtils.removeFirst(ldapName, new LdapName("OU=I,OU=M")); - assertNotSame(ldapName, result); - assertEquals(new LdapName("cn=john.doe, OU=Users,OU=SE,OU=G"), result); + assertThat(result).isNotSameAs(ldapName); + assertThat(result).isEqualTo(new LdapName("cn=john.doe, OU=Users,OU=SE,OU=G")); } @Test @@ -266,8 +264,8 @@ public class LdapUtilsTest { LdapName ldapName = new LdapName(EXPECTED_DN_STRING); LdapName result = LdapUtils.removeFirst(ldapName, new LdapName("OU=oooooo,OU=M")); - assertNotSame(ldapName, result); - assertEquals(ldapName, result); + assertThat(result).isNotSameAs(ldapName); + assertThat(result).isEqualTo(ldapName); } @Test @@ -275,174 +273,306 @@ public class LdapUtilsTest { LdapName ldapName = new LdapName(EXPECTED_DN_STRING); LdapName result = LdapUtils.removeFirst(ldapName, LdapUtils.emptyLdapName()); - assertNotSame(ldapName, result); - assertEquals(ldapName, result); + assertThat(result).isNotSameAs(ldapName); + assertThat(result).isEqualTo(ldapName); } @Test public void testGetValueNamed() throws InvalidNameException { LdapName ldapName = new LdapName(EXPECTED_DN_STRING); - assertEquals("john.doe", LdapUtils.getValue(ldapName, "cn")); + assertThat("john.doe").isEqualTo(LdapUtils.getValue(ldapName, "cn")); } @Test public void testGetValueNamedReturnesFirstFound() throws InvalidNameException { LdapName ldapName = new LdapName(EXPECTED_DN_STRING); - assertEquals("M", LdapUtils.getValue(ldapName, "ou")); + assertThat("M").isEqualTo(LdapUtils.getValue(ldapName, "ou")); } @Test public void testGetValueNamedWithMultivalue() throws InvalidNameException { LdapName ldapName = new LdapName(EXPECTED_MULTIVALUE_DN_STRING); - assertEquals("GR", LdapUtils.getValue(ldapName, "o")); + assertThat("GR").isEqualTo(LdapUtils.getValue(ldapName, "o")); } @Test public void testGetValueIndexed() throws InvalidNameException { LdapName ldapName = new LdapName(EXPECTED_DN_STRING); - assertEquals("G", LdapUtils.getValue(ldapName, 2)); + assertThat("G").isEqualTo(LdapUtils.getValue(ldapName, 2)); } @Test public void testGetStringValueIndexed() throws InvalidNameException { LdapName ldapName = new LdapName(EXPECTED_DN_STRING); - assertEquals("I", LdapUtils.getValue(ldapName, 1)); + assertThat("I").isEqualTo(LdapUtils.getValue(ldapName, 1)); } @Test public void testConvertLdapExceptions() { // Test the Exceptions in the javax.naming package - assertEquals(org.springframework.ldap.AttributeInUseException.class, - LdapUtils.convertLdapException(new javax.naming.directory.AttributeInUseException()).getClass()); - assertEquals(org.springframework.ldap.AttributeModificationException.class, - LdapUtils.convertLdapException(new javax.naming.directory.AttributeModificationException()).getClass()); - assertEquals(org.springframework.ldap.CannotProceedException.class, - LdapUtils.convertLdapException(new javax.naming.CannotProceedException()).getClass()); - assertEquals(org.springframework.ldap.CommunicationException.class, - LdapUtils.convertLdapException(new javax.naming.CommunicationException()).getClass()); - assertEquals(org.springframework.ldap.ConfigurationException.class, - LdapUtils.convertLdapException(new javax.naming.ConfigurationException()).getClass()); - assertEquals(org.springframework.ldap.ContextNotEmptyException.class, - LdapUtils.convertLdapException(new javax.naming.ContextNotEmptyException()).getClass()); - assertEquals(org.springframework.ldap.InsufficientResourcesException.class, - LdapUtils.convertLdapException(new javax.naming.InsufficientResourcesException()).getClass()); - assertEquals(org.springframework.ldap.InterruptedNamingException.class, - LdapUtils.convertLdapException(new javax.naming.InterruptedNamingException()).getClass()); - assertEquals(org.springframework.ldap.InvalidAttributeIdentifierException.class, - LdapUtils.convertLdapException(new javax.naming.directory.InvalidAttributeIdentifierException()).getClass()); - assertEquals(org.springframework.ldap.InvalidAttributesException.class, - LdapUtils.convertLdapException(new javax.naming.directory.InvalidAttributesException()).getClass()); - assertEquals(org.springframework.ldap.InvalidAttributeValueException.class, - LdapUtils.convertLdapException(new javax.naming.directory.InvalidAttributeValueException()).getClass()); - assertEquals(org.springframework.ldap.InvalidNameException.class, - LdapUtils.convertLdapException(new javax.naming.InvalidNameException()).getClass()); - assertEquals(org.springframework.ldap.InvalidSearchControlsException.class, - LdapUtils.convertLdapException(new javax.naming.directory.InvalidSearchControlsException()).getClass()); - assertEquals(org.springframework.ldap.InvalidSearchFilterException.class, - LdapUtils.convertLdapException(new javax.naming.directory.InvalidSearchFilterException()).getClass()); - assertEquals(org.springframework.ldap.SizeLimitExceededException.class, - LdapUtils.convertLdapException(new javax.naming.SizeLimitExceededException()).getClass()); - assertEquals(org.springframework.ldap.TimeLimitExceededException.class, - LdapUtils.convertLdapException(new javax.naming.TimeLimitExceededException()).getClass()); - assertEquals(org.springframework.ldap.LimitExceededException.class, - LdapUtils.convertLdapException(new javax.naming.LimitExceededException()).getClass()); - assertEquals(org.springframework.ldap.LinkLoopException.class, - LdapUtils.convertLdapException(new javax.naming.LinkLoopException()).getClass()); - assertEquals(org.springframework.ldap.MalformedLinkException.class, - LdapUtils.convertLdapException(new javax.naming.MalformedLinkException()).getClass()); - assertEquals(org.springframework.ldap.LinkException.class, - LdapUtils.convertLdapException(new javax.naming.LinkException()).getClass()); - assertEquals(org.springframework.ldap.NameAlreadyBoundException.class, - LdapUtils.convertLdapException(new javax.naming.NameAlreadyBoundException()).getClass()); - assertEquals(org.springframework.ldap.NameNotFoundException.class, - LdapUtils.convertLdapException(new javax.naming.NameNotFoundException()).getClass()); - assertEquals(org.springframework.ldap.NoPermissionException.class, - LdapUtils.convertLdapException(new javax.naming.NoPermissionException()).getClass()); - assertEquals(org.springframework.ldap.AuthenticationException.class, - LdapUtils.convertLdapException(new javax.naming.AuthenticationException()).getClass()); - assertEquals(org.springframework.ldap.AuthenticationNotSupportedException.class, - LdapUtils.convertLdapException(new javax.naming.AuthenticationNotSupportedException()).getClass()); - assertEquals(org.springframework.ldap.NoInitialContextException.class, - LdapUtils.convertLdapException(new javax.naming.NoInitialContextException()).getClass()); - assertEquals(org.springframework.ldap.NoSuchAttributeException.class, - LdapUtils.convertLdapException(new javax.naming.directory.NoSuchAttributeException()).getClass()); - assertEquals(org.springframework.ldap.NotContextException.class, - LdapUtils.convertLdapException(new javax.naming.NotContextException()).getClass()); - assertEquals(org.springframework.ldap.OperationNotSupportedException.class, - LdapUtils.convertLdapException(new javax.naming.OperationNotSupportedException()).getClass()); - assertEquals(org.springframework.ldap.PartialResultException.class, - LdapUtils.convertLdapException(new javax.naming.PartialResultException()).getClass()); - assertEquals(org.springframework.ldap.SchemaViolationException.class, - LdapUtils.convertLdapException(new javax.naming.directory.SchemaViolationException()).getClass()); - assertEquals(org.springframework.ldap.ServiceUnavailableException.class, - LdapUtils.convertLdapException(new javax.naming.ServiceUnavailableException()).getClass()); + assertThat( + LdapUtils.convertLdapException( + new javax.naming.directory.AttributeInUseException()).getClass()) + .isEqualTo(org.springframework.ldap.AttributeInUseException.class); + assertThat( + LdapUtils.convertLdapException( + new javax.naming.directory.AttributeModificationException()) + .getClass()).isEqualTo( + org.springframework.ldap.AttributeModificationException.class); + assertThat( + LdapUtils.convertLdapException(new javax.naming.CannotProceedException()) + .getClass()).isEqualTo( + org.springframework.ldap.CannotProceedException.class); + assertThat( + LdapUtils.convertLdapException(new javax.naming.CommunicationException()) + .getClass()).isEqualTo( + org.springframework.ldap.CommunicationException.class); + assertThat( + LdapUtils.convertLdapException(new javax.naming.ConfigurationException()) + .getClass()).isEqualTo( + org.springframework.ldap.ConfigurationException.class); + assertThat( + LdapUtils.convertLdapException( + new javax.naming.ContextNotEmptyException()).getClass()) + .isEqualTo(org.springframework.ldap.ContextNotEmptyException.class); + assertThat( + LdapUtils.convertLdapException( + new javax.naming.InsufficientResourcesException()).getClass()) + .isEqualTo(org.springframework.ldap.InsufficientResourcesException.class); + assertThat( + LdapUtils.convertLdapException( + new javax.naming.InterruptedNamingException()).getClass()) + .isEqualTo(org.springframework.ldap.InterruptedNamingException.class); + assertThat( + LdapUtils.convertLdapException( + new javax.naming.directory.InvalidAttributeIdentifierException()) + .getClass()).isEqualTo( + org.springframework.ldap.InvalidAttributeIdentifierException.class); + assertThat( + LdapUtils.convertLdapException( + new javax.naming.directory.InvalidAttributesException()) + .getClass()).isEqualTo( + org.springframework.ldap.InvalidAttributesException.class); + assertThat( + LdapUtils.convertLdapException( + new javax.naming.directory.InvalidAttributeValueException()) + .getClass()).isEqualTo( + org.springframework.ldap.InvalidAttributeValueException.class); + assertThat( + LdapUtils.convertLdapException(new javax.naming.InvalidNameException()) + .getClass()).isEqualTo( + org.springframework.ldap.InvalidNameException.class); + assertThat( + LdapUtils.convertLdapException( + new javax.naming.directory.InvalidSearchControlsException()) + .getClass()).isEqualTo( + org.springframework.ldap.InvalidSearchControlsException.class); + assertThat( + LdapUtils.convertLdapException( + new javax.naming.directory.InvalidSearchFilterException()) + .getClass()).isEqualTo( + org.springframework.ldap.InvalidSearchFilterException.class); + assertThat( + LdapUtils.convertLdapException( + new javax.naming.SizeLimitExceededException()).getClass()) + .isEqualTo(org.springframework.ldap.SizeLimitExceededException.class); + assertThat( + LdapUtils.convertLdapException( + new javax.naming.TimeLimitExceededException()).getClass()) + .isEqualTo(org.springframework.ldap.TimeLimitExceededException.class); + assertThat( + LdapUtils.convertLdapException(new javax.naming.LimitExceededException()) + .getClass()).isEqualTo( + org.springframework.ldap.LimitExceededException.class); + assertThat( + LdapUtils.convertLdapException(new javax.naming.LinkLoopException()) + .getClass()).isEqualTo( + org.springframework.ldap.LinkLoopException.class); + assertThat( + LdapUtils.convertLdapException(new javax.naming.MalformedLinkException()) + .getClass()).isEqualTo( + org.springframework.ldap.MalformedLinkException.class); + assertThat( + LdapUtils.convertLdapException(new javax.naming.LinkException()) + .getClass()).isEqualTo( + org.springframework.ldap.LinkException.class); + assertThat( + LdapUtils.convertLdapException( + new javax.naming.NameAlreadyBoundException()).getClass()) + .isEqualTo(org.springframework.ldap.NameAlreadyBoundException.class); + assertThat( + LdapUtils.convertLdapException(new javax.naming.NameNotFoundException()) + .getClass()).isEqualTo( + org.springframework.ldap.NameNotFoundException.class); + assertThat( + LdapUtils.convertLdapException(new javax.naming.NoPermissionException()) + .getClass()).isEqualTo( + org.springframework.ldap.NoPermissionException.class); + assertThat( + LdapUtils + .convertLdapException(new javax.naming.AuthenticationException()) + .getClass()).isEqualTo( + org.springframework.ldap.AuthenticationException.class); + assertThat( + LdapUtils.convertLdapException( + new javax.naming.AuthenticationNotSupportedException()) + .getClass()).isEqualTo( + org.springframework.ldap.AuthenticationNotSupportedException.class); + assertThat( + LdapUtils.convertLdapException( + new javax.naming.NoInitialContextException()).getClass()) + .isEqualTo(org.springframework.ldap.NoInitialContextException.class); + assertThat( + LdapUtils.convertLdapException( + new javax.naming.directory.NoSuchAttributeException()).getClass()) + .isEqualTo(org.springframework.ldap.NoSuchAttributeException.class); + assertThat( + LdapUtils.convertLdapException(new javax.naming.NotContextException()) + .getClass()).isEqualTo( + org.springframework.ldap.NotContextException.class); + assertThat( + LdapUtils.convertLdapException( + new javax.naming.OperationNotSupportedException()).getClass()) + .isEqualTo(org.springframework.ldap.OperationNotSupportedException.class); + assertThat( + LdapUtils.convertLdapException(new javax.naming.PartialResultException()) + .getClass()).isEqualTo( + org.springframework.ldap.PartialResultException.class); + assertThat( + LdapUtils.convertLdapException( + new javax.naming.directory.SchemaViolationException()).getClass()) + .isEqualTo(org.springframework.ldap.SchemaViolationException.class); + assertThat( + LdapUtils.convertLdapException( + new javax.naming.ServiceUnavailableException()).getClass()) + .isEqualTo(org.springframework.ldap.ServiceUnavailableException.class); // Test Exceptions that extend javax.naming packaage extensions - assertEquals(org.springframework.ldap.AttributeInUseException.class, - LdapUtils.convertLdapException(new MockAttributeInUseException()).getClass()); - assertEquals(org.springframework.ldap.AttributeModificationException.class, - LdapUtils.convertLdapException(new MockAttributeModificationException()).getClass()); - assertEquals(org.springframework.ldap.CannotProceedException.class, - LdapUtils.convertLdapException(new MockCannotProceedException()).getClass()); - assertEquals(org.springframework.ldap.CommunicationException.class, - LdapUtils.convertLdapException(new MockCommunicationException()).getClass()); - assertEquals(org.springframework.ldap.ConfigurationException.class, - LdapUtils.convertLdapException(new MockConfigurationException()).getClass()); - assertEquals(org.springframework.ldap.ContextNotEmptyException.class, - LdapUtils.convertLdapException(new MockContextNotEmptyException()).getClass()); - assertEquals(org.springframework.ldap.InsufficientResourcesException.class, - LdapUtils.convertLdapException(new MockInsufficientResourcesException()).getClass()); - assertEquals(org.springframework.ldap.InterruptedNamingException.class, - LdapUtils.convertLdapException(new MockInterruptedNamingException()).getClass()); - assertEquals(org.springframework.ldap.InvalidAttributeIdentifierException.class, - LdapUtils.convertLdapException(new MockInvalidAttributeIdentifierException()).getClass()); - assertEquals(org.springframework.ldap.InvalidAttributesException.class, - LdapUtils.convertLdapException(new MockInvalidAttributesException()).getClass()); - assertEquals(org.springframework.ldap.InvalidAttributeValueException.class, - LdapUtils.convertLdapException(new MockInvalidAttributeValueException()).getClass()); - assertEquals(org.springframework.ldap.InvalidNameException.class, - LdapUtils.convertLdapException(new MockInvalidNameException()).getClass()); - assertEquals(org.springframework.ldap.InvalidSearchControlsException.class, - LdapUtils.convertLdapException(new MockInvalidSearchControlsException()).getClass()); - assertEquals(org.springframework.ldap.InvalidSearchFilterException.class, - LdapUtils.convertLdapException(new MockInvalidSearchFilterException()).getClass()); - assertEquals(org.springframework.ldap.SizeLimitExceededException.class, - LdapUtils.convertLdapException(new MockSizeLimitExceededException()).getClass()); - assertEquals(org.springframework.ldap.TimeLimitExceededException.class, - LdapUtils.convertLdapException(new MockTimeLimitExceededException()).getClass()); - assertEquals(org.springframework.ldap.LimitExceededException.class, - LdapUtils.convertLdapException(new MockLimitExceededException()).getClass()); - assertEquals(org.springframework.ldap.LinkLoopException.class, - LdapUtils.convertLdapException(new MockLinkLoopException()).getClass()); - assertEquals(org.springframework.ldap.MalformedLinkException.class, - LdapUtils.convertLdapException(new MockMalformedLinkException()).getClass()); - assertEquals(org.springframework.ldap.LinkException.class, - LdapUtils.convertLdapException(new MockLinkException()).getClass()); - assertEquals(org.springframework.ldap.NameAlreadyBoundException.class, - LdapUtils.convertLdapException(new MockNameAlreadyBoundException()).getClass()); - assertEquals(org.springframework.ldap.NameNotFoundException.class, - LdapUtils.convertLdapException(new MockNameNotFoundException()).getClass()); - assertEquals(org.springframework.ldap.NoPermissionException.class, - LdapUtils.convertLdapException(new MockNoPermissionException()).getClass()); - assertEquals(org.springframework.ldap.AuthenticationException.class, - LdapUtils.convertLdapException(new MockAuthenticationException()).getClass()); - assertEquals(org.springframework.ldap.AuthenticationNotSupportedException.class, - LdapUtils.convertLdapException(new MockAuthenticationNotSupportedException()).getClass()); - assertEquals(org.springframework.ldap.NoInitialContextException.class, - LdapUtils.convertLdapException(new MockNoInitialContextException()).getClass()); - assertEquals(org.springframework.ldap.NoSuchAttributeException.class, - LdapUtils.convertLdapException(new MockNoSuchAttributeException()).getClass()); - assertEquals(org.springframework.ldap.NotContextException.class, - LdapUtils.convertLdapException(new MockNotContextException()).getClass()); - assertEquals(org.springframework.ldap.OperationNotSupportedException.class, - LdapUtils.convertLdapException(new MockOperationNotSupportedException()).getClass()); - assertEquals(org.springframework.ldap.PartialResultException.class, - LdapUtils.convertLdapException(new MockPartialResultException()).getClass()); - assertEquals(org.springframework.ldap.SchemaViolationException.class, - LdapUtils.convertLdapException(new MockSchemaViolationException()).getClass()); - assertEquals(org.springframework.ldap.ServiceUnavailableException.class, - LdapUtils.convertLdapException(new MockServiceUnavailableException()).getClass()); + assertThat( + LdapUtils.convertLdapException(new MockAttributeInUseException()) + .getClass()).isEqualTo( + org.springframework.ldap.AttributeInUseException.class); + assertThat( + LdapUtils.convertLdapException(new MockAttributeModificationException()) + .getClass()).isEqualTo( + org.springframework.ldap.AttributeModificationException.class); + assertThat( + LdapUtils.convertLdapException(new MockCannotProceedException()) + .getClass()).isEqualTo( + org.springframework.ldap.CannotProceedException.class); + assertThat( + LdapUtils.convertLdapException(new MockCommunicationException()) + .getClass()).isEqualTo( + org.springframework.ldap.CommunicationException.class); + assertThat( + LdapUtils.convertLdapException(new MockConfigurationException()) + .getClass()).isEqualTo( + org.springframework.ldap.ConfigurationException.class); + assertThat( + LdapUtils.convertLdapException(new MockContextNotEmptyException()) + .getClass()).isEqualTo( + org.springframework.ldap.ContextNotEmptyException.class); + assertThat( + LdapUtils.convertLdapException(new MockInsufficientResourcesException()) + .getClass()).isEqualTo( + org.springframework.ldap.InsufficientResourcesException.class); + assertThat( + LdapUtils.convertLdapException(new MockInterruptedNamingException()) + .getClass()).isEqualTo( + org.springframework.ldap.InterruptedNamingException.class); + assertThat( + LdapUtils.convertLdapException( + new MockInvalidAttributeIdentifierException()).getClass()) + .isEqualTo( + org.springframework.ldap.InvalidAttributeIdentifierException.class); + assertThat( + LdapUtils.convertLdapException(new MockInvalidAttributesException()) + .getClass()).isEqualTo( + org.springframework.ldap.InvalidAttributesException.class); + assertThat( + LdapUtils.convertLdapException(new MockInvalidAttributeValueException()) + .getClass()).isEqualTo( + org.springframework.ldap.InvalidAttributeValueException.class); + assertThat( + LdapUtils.convertLdapException(new MockInvalidNameException()).getClass()) + .isEqualTo(org.springframework.ldap.InvalidNameException.class); + assertThat( + LdapUtils.convertLdapException(new MockInvalidSearchControlsException()) + .getClass()).isEqualTo( + org.springframework.ldap.InvalidSearchControlsException.class); + assertThat( + LdapUtils.convertLdapException(new MockInvalidSearchFilterException()) + .getClass()).isEqualTo( + org.springframework.ldap.InvalidSearchFilterException.class); + assertThat( + LdapUtils.convertLdapException(new MockSizeLimitExceededException()) + .getClass()).isEqualTo( + org.springframework.ldap.SizeLimitExceededException.class); + assertThat( + LdapUtils.convertLdapException(new MockTimeLimitExceededException()) + .getClass()).isEqualTo( + org.springframework.ldap.TimeLimitExceededException.class); + assertThat( + LdapUtils.convertLdapException(new MockLimitExceededException()) + .getClass()).isEqualTo( + org.springframework.ldap.LimitExceededException.class); + assertThat(LdapUtils.convertLdapException(new MockLinkLoopException()).getClass()) + .isEqualTo(org.springframework.ldap.LinkLoopException.class); + assertThat( + LdapUtils.convertLdapException(new MockMalformedLinkException()) + .getClass()).isEqualTo( + org.springframework.ldap.MalformedLinkException.class); + assertThat(LdapUtils.convertLdapException(new MockLinkException()).getClass()) + .isEqualTo(org.springframework.ldap.LinkException.class); + assertThat( + LdapUtils.convertLdapException(new MockNameAlreadyBoundException()) + .getClass()).isEqualTo( + org.springframework.ldap.NameAlreadyBoundException.class); + assertThat( + LdapUtils.convertLdapException(new MockNameNotFoundException()) + .getClass()).isEqualTo( + org.springframework.ldap.NameNotFoundException.class); + assertThat( + LdapUtils.convertLdapException(new MockNoPermissionException()) + .getClass()).isEqualTo( + org.springframework.ldap.NoPermissionException.class); + assertThat( + LdapUtils.convertLdapException(new MockAuthenticationException()) + .getClass()).isEqualTo( + org.springframework.ldap.AuthenticationException.class); + assertThat( + LdapUtils.convertLdapException( + new MockAuthenticationNotSupportedException()).getClass()) + .isEqualTo( + org.springframework.ldap.AuthenticationNotSupportedException.class); + assertThat( + LdapUtils.convertLdapException(new MockNoInitialContextException()) + .getClass()).isEqualTo( + org.springframework.ldap.NoInitialContextException.class); + assertThat( + LdapUtils.convertLdapException(new MockNoSuchAttributeException()) + .getClass()).isEqualTo( + org.springframework.ldap.NoSuchAttributeException.class); + assertThat( + LdapUtils.convertLdapException(new MockNotContextException()).getClass()) + .isEqualTo(org.springframework.ldap.NotContextException.class); + assertThat( + LdapUtils.convertLdapException(new MockOperationNotSupportedException()) + .getClass()).isEqualTo( + org.springframework.ldap.OperationNotSupportedException.class); + assertThat( + LdapUtils.convertLdapException(new MockPartialResultException()) + .getClass()).isEqualTo( + org.springframework.ldap.PartialResultException.class); + assertThat( + LdapUtils.convertLdapException(new MockSchemaViolationException()) + .getClass()).isEqualTo( + org.springframework.ldap.SchemaViolationException.class); + assertThat( + LdapUtils.convertLdapException(new MockServiceUnavailableException()) + .getClass()).isEqualTo( + org.springframework.ldap.ServiceUnavailableException.class); } public class MockAttributeInUseException extends javax.naming.directory.AttributeInUseException { diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/BindOperationRecorderTest.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/BindOperationRecorderTest.java index 8837c899..bbf00e65 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/BindOperationRecorderTest.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/BindOperationRecorderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import org.springframework.transaction.compensating.CompensatingTransactionOpera import javax.naming.directory.BasicAttributes; import javax.naming.ldap.LdapName; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; @@ -51,11 +51,11 @@ public class BindOperationRecorderTest { .recordOperation(new Object[] { expectedDn, expectedObject, expectedAttributes }); - assertTrue(operation instanceof BindOperationExecutor); + assertThat(operation instanceof BindOperationExecutor).isTrue(); BindOperationExecutor rollbackOperation = (BindOperationExecutor) operation; - assertSame(expectedDn, rollbackOperation.getDn()); - assertSame(ldapOperationsMock, rollbackOperation.getLdapOperations()); - assertSame(expectedObject, rollbackOperation.getOriginalObject()); + assertThat(rollbackOperation.getDn()).isSameAs(expectedDn); + assertThat(rollbackOperation.getLdapOperations()).isSameAs(ldapOperationsMock); + assertThat(rollbackOperation.getOriginalObject()).isSameAs(expectedObject); assertSame(expectedAttributes, rollbackOperation .getOriginalAttributes()); } @@ -73,10 +73,10 @@ public class BindOperationRecorderTest { .recordOperation(new Object[] { expectedDn, expectedObject, expectedAttributes }); - assertTrue(operation instanceof BindOperationExecutor); + assertThat(operation instanceof BindOperationExecutor).isTrue(); BindOperationExecutor rollbackOperation = (BindOperationExecutor) operation; - assertEquals(expectedDn, rollbackOperation.getDn().toString()); - assertSame(ldapOperationsMock, rollbackOperation.getLdapOperations()); + assertThat(rollbackOperation.getDn().toString()).isEqualTo(expectedDn); + assertThat(rollbackOperation.getLdapOperations()).isSameAs(ldapOperationsMock); } @Test(expected = IllegalArgumentException.class) diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/LdapCompensatingTransactionOperationFactoryTest.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/LdapCompensatingTransactionOperationFactoryTest.java index 6d803c58..be6722f2 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/LdapCompensatingTransactionOperationFactoryTest.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/LdapCompensatingTransactionOperationFactoryTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,9 +22,7 @@ import org.springframework.transaction.compensating.CompensatingTransactionOpera import javax.naming.directory.DirContext; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; public class LdapCompensatingTransactionOperationFactoryTest { @@ -46,7 +44,7 @@ public class LdapCompensatingTransactionOperationFactoryTest { renamingStrategyMock) { LdapOperations createLdapOperationsInstance(DirContext ctx) { - assertEquals(dirContextMock, ctx); + assertThat(ctx).isEqualTo(dirContextMock); return ldapOperationsMock; } }; @@ -57,50 +55,46 @@ public class LdapCompensatingTransactionOperationFactoryTest { CompensatingTransactionOperationRecorder result = tested .createRecordingOperation(dirContextMock, "bind"); - assertTrue(result instanceof BindOperationRecorder); + assertThat(result instanceof BindOperationRecorder).isTrue(); BindOperationRecorder bindOperationRecorder = (BindOperationRecorder) result; - assertSame(ldapOperationsMock, bindOperationRecorder - .getLdapOperations()); + assertThat(bindOperationRecorder.getLdapOperations()).isSameAs(ldapOperationsMock); } @Test public void testGetRecordingOperation_Rebind() throws Exception { CompensatingTransactionOperationRecorder result = tested .createRecordingOperation(dirContextMock, "rebind"); - assertTrue(result instanceof RebindOperationRecorder); + assertThat(result instanceof RebindOperationRecorder).isTrue(); RebindOperationRecorder rebindOperationRecorder = (RebindOperationRecorder) result; - assertSame(ldapOperationsMock, rebindOperationRecorder - .getLdapOperations()); - assertSame(renamingStrategyMock, rebindOperationRecorder - .getRenamingStrategy()); + assertThat(rebindOperationRecorder.getLdapOperations()).isSameAs(ldapOperationsMock); + assertThat(rebindOperationRecorder.getRenamingStrategy()).isSameAs(renamingStrategyMock); } @Test public void testGetRecordingOperation_Rename() throws Exception { CompensatingTransactionOperationRecorder result = tested .createRecordingOperation(dirContextMock, "rename"); - assertTrue(result instanceof RenameOperationRecorder); + assertThat(result instanceof RenameOperationRecorder).isTrue(); RenameOperationRecorder recordingOperation = (RenameOperationRecorder) result; - assertSame(ldapOperationsMock, recordingOperation.getLdapOperations()); + assertThat(recordingOperation.getLdapOperations()).isSameAs(ldapOperationsMock); } @Test public void testGetRecordingOperation_ModifyAttributes() throws Exception { CompensatingTransactionOperationRecorder result = tested .createRecordingOperation(dirContextMock, "modifyAttributes"); - assertTrue(result instanceof ModifyAttributesOperationRecorder); + assertThat(result instanceof ModifyAttributesOperationRecorder).isTrue(); ModifyAttributesOperationRecorder recordingOperation = (ModifyAttributesOperationRecorder) result; - assertSame(ldapOperationsMock, recordingOperation.getLdapOperations()); + assertThat(recordingOperation.getLdapOperations()).isSameAs(ldapOperationsMock); } @Test public void testGetRecordingOperation_Unbind() throws Exception { CompensatingTransactionOperationRecorder result = tested .createRecordingOperation(dirContextMock, "unbind"); - assertTrue(result instanceof UnbindOperationRecorder); + assertThat(result instanceof UnbindOperationRecorder).isTrue(); UnbindOperationRecorder recordingOperation = (UnbindOperationRecorder) result; - assertSame(ldapOperationsMock, recordingOperation.getLdapOperations()); - assertSame(renamingStrategyMock, recordingOperation - .getRenamingStrategy()); + assertThat(recordingOperation.getLdapOperations()).isSameAs(ldapOperationsMock); + assertThat(recordingOperation.getRenamingStrategy()).isSameAs(renamingStrategyMock); } } diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationRecorderTest.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationRecorderTest.java index b9bf4203..8320fccf 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationRecorderTest.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationRecorderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,9 +32,7 @@ import javax.naming.directory.DirContext; import javax.naming.directory.ModificationItem; import javax.naming.ldap.LdapName; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -71,8 +69,8 @@ public class ModifyAttributesOperationRecorderTest { protected ModificationItem getCompensatingModificationItem( Attributes originalAttributes, ModificationItem modificationItem) { - assertSame(expectedAttributes, originalAttributes); - assertSame(incomingItem, modificationItem); + assertThat(originalAttributes).isSameAs(expectedAttributes); + assertThat(modificationItem).isSameAs(incomingItem); return compensatingItem; } }; @@ -92,16 +90,15 @@ public class ModifyAttributesOperationRecorderTest { .recordOperation(new Object[]{expectedName, incomingMods}); // Verify outcome - assertTrue(operation instanceof ModifyAttributesOperationExecutor); + assertThat(operation instanceof ModifyAttributesOperationExecutor).isTrue(); ModifyAttributesOperationExecutor rollbackOperation = (ModifyAttributesOperationExecutor) operation; - assertSame(expectedName, rollbackOperation.getDn()); - assertSame(ldapOperationsMock, rollbackOperation.getLdapOperations()); + assertThat(rollbackOperation.getDn()).isSameAs(expectedName); + assertThat(rollbackOperation.getLdapOperations()).isSameAs(ldapOperationsMock); ModificationItem[] actualModifications = rollbackOperation.getActualModifications(); - assertEquals(incomingMods.length, actualModifications.length); - assertEquals(incomingMods[0], actualModifications[0]); - assertEquals(1, rollbackOperation.getCompensatingModifications().length); - assertSame(compensatingItem, rollbackOperation - .getCompensatingModifications()[0]); + assertThat(actualModifications.length).isEqualTo(incomingMods.length); + assertThat(actualModifications[0]).isEqualTo(incomingMods[0]); + assertThat(rollbackOperation.getCompensatingModifications().length).isEqualTo(1); + assertThat(rollbackOperation.getCompensatingModifications()[0]).isSameAs(compensatingItem); } @Test @@ -121,12 +118,12 @@ public class ModifyAttributesOperationRecorderTest { attributes, originalItem); // Verify result - assertEquals(DirContext.ADD_ATTRIBUTE, result.getModificationOp()); + assertThat(result.getModificationOp()).isEqualTo(DirContext.ADD_ATTRIBUTE); Attribute resultAttribute = result.getAttribute(); - assertEquals("someattr", resultAttribute.getID()); + assertThat(resultAttribute.getID()).isEqualTo("someattr"); Object object = resultAttribute.get(0); - assertEquals("value1", object); - assertEquals("value2", resultAttribute.get(1)); + assertThat(object).isEqualTo("value1"); + assertThat(resultAttribute.get(1)).isEqualTo("value2"); } @Test @@ -150,12 +147,12 @@ public class ModifyAttributesOperationRecorderTest { attributes, originalItem); // Verify result - assertEquals(DirContext.ADD_ATTRIBUTE, result.getModificationOp()); + assertThat(result.getModificationOp()).isEqualTo(DirContext.ADD_ATTRIBUTE); Attribute resultAttribute = result.getAttribute(); - assertEquals("someattr", resultAttribute.getID()); + assertThat(resultAttribute.getID()).isEqualTo("someattr"); Object object = resultAttribute.get(0); - assertEquals("value1", object); - assertEquals("value2", resultAttribute.get(1)); + assertThat(object).isEqualTo("value1"); + assertThat(resultAttribute.get(1)).isEqualTo("value2"); } @Test @@ -178,12 +175,12 @@ public class ModifyAttributesOperationRecorderTest { attributes, originalItem); // Verify result - assertEquals(DirContext.REPLACE_ATTRIBUTE, result.getModificationOp()); + assertThat(result.getModificationOp()).isEqualTo(DirContext.REPLACE_ATTRIBUTE); Attribute resultAttribute = result.getAttribute(); - assertEquals("someattr", resultAttribute.getID()); + assertThat(resultAttribute.getID()).isEqualTo("someattr"); Object object = resultAttribute.get(0); - assertEquals("value1", object); - assertEquals("value2", resultAttribute.get(1)); + assertThat(object).isEqualTo("value1"); + assertThat(resultAttribute.get(1)).isEqualTo("value2"); } @Test @@ -202,10 +199,10 @@ public class ModifyAttributesOperationRecorderTest { attributes, originalItem); // Verify result - assertEquals(DirContext.REMOVE_ATTRIBUTE, result.getModificationOp()); + assertThat(result.getModificationOp()).isEqualTo(DirContext.REMOVE_ATTRIBUTE); Attribute resultAttribute = result.getAttribute(); - assertEquals("someattr", resultAttribute.getID()); - assertEquals(0, resultAttribute.size()); + assertThat(resultAttribute.getID()).isEqualTo("someattr"); + assertThat(resultAttribute.size()).isEqualTo(0); } @Test @@ -224,10 +221,10 @@ public class ModifyAttributesOperationRecorderTest { attributes, originalItem); // Verify result - assertEquals(DirContext.REMOVE_ATTRIBUTE, result.getModificationOp()); + assertThat(result.getModificationOp()).isEqualTo(DirContext.REMOVE_ATTRIBUTE); Attribute resultAttribute = result.getAttribute(); - assertEquals("someattr", resultAttribute.getID()); - assertEquals(0, resultAttribute.size()); + assertThat(resultAttribute.getID()).isEqualTo("someattr"); + assertThat(resultAttribute.size()).isEqualTo(0); } @Test @@ -250,10 +247,10 @@ public class ModifyAttributesOperationRecorderTest { attributes, originalItem); // Verify result - assertEquals(DirContext.REPLACE_ATTRIBUTE, result.getModificationOp()); + assertThat(result.getModificationOp()).isEqualTo(DirContext.REPLACE_ATTRIBUTE); Attribute resultAttribute = result.getAttribute(); - assertEquals("someattr", resultAttribute.getID()); - assertEquals("value1", result.getAttribute().get(0)); - assertEquals("value2", result.getAttribute().get(1)); + assertThat(resultAttribute.getID()).isEqualTo("someattr"); + assertThat(result.getAttribute().get(0)).isEqualTo("value1"); + assertThat(result.getAttribute().get(1)).isEqualTo("value2"); } } diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/RebindOperationRecorderTest.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/RebindOperationRecorderTest.java index 4b6e5484..b6180312 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/RebindOperationRecorderTest.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/RebindOperationRecorderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,8 +24,7 @@ import org.springframework.transaction.compensating.CompensatingTransactionOpera import javax.naming.directory.BasicAttributes; import javax.naming.ldap.LdapName; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -60,13 +59,12 @@ public class RebindOperationRecorderTest { CompensatingTransactionOperationExecutor result = tested .recordOperation(new Object[] { expectedDn, expectedObject, expectedAttributes }); - assertTrue(result instanceof RebindOperationExecutor); + assertThat(result instanceof RebindOperationExecutor).isTrue(); RebindOperationExecutor rollbackOperation = (RebindOperationExecutor) result; - assertSame(ldapOperationsMock, rollbackOperation.getLdapOperations()); - assertSame(expectedDn, rollbackOperation.getOriginalDn()); - assertSame(expectedTempDn, rollbackOperation.getTemporaryDn()); - assertSame(expectedObject, rollbackOperation.getOriginalObject()); - assertSame(expectedAttributes, rollbackOperation - .getOriginalAttributes()); + assertThat(rollbackOperation.getLdapOperations()).isSameAs(ldapOperationsMock); + assertThat(rollbackOperation.getOriginalDn()).isSameAs(expectedDn); + assertThat(rollbackOperation.getTemporaryDn()).isSameAs(expectedTempDn); + assertThat(rollbackOperation.getOriginalObject()).isSameAs(expectedObject); + assertThat(rollbackOperation.getOriginalAttributes()).isSameAs(expectedAttributes); } } diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/RenameOperationRecorderTest.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/RenameOperationRecorderTest.java index c0f4ef74..eb937371 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/RenameOperationRecorderTest.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/RenameOperationRecorderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +20,7 @@ import org.junit.Test; import org.springframework.ldap.core.LdapOperations; import org.springframework.transaction.compensating.CompensatingTransactionOperationExecutor; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; public class RenameOperationRecorderTest { @@ -43,10 +41,10 @@ public class RenameOperationRecorderTest { CompensatingTransactionOperationExecutor operation = tested .recordOperation(new Object[] { "ou=someou", "ou=newou" }); - assertTrue(operation instanceof RenameOperationExecutor); + assertThat(operation instanceof RenameOperationExecutor).isTrue(); RenameOperationExecutor rollbackOperation = (RenameOperationExecutor) operation; - assertSame(ldapOperationsMock, rollbackOperation.getLdapOperations()); - assertEquals("ou=newou", rollbackOperation.getNewDn().toString()); - assertEquals("ou=someou", rollbackOperation.getOriginalDn().toString()); + assertThat(rollbackOperation.getLdapOperations()).isSameAs(ldapOperationsMock); + assertThat(rollbackOperation.getNewDn().toString()).isEqualTo("ou=newou"); + assertThat(rollbackOperation.getOriginalDn().toString()).isEqualTo("ou=someou"); } } diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/UnbindOperationRecorderTest.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/UnbindOperationRecorderTest.java index b47723e6..acc554b1 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/UnbindOperationRecorderTest.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/UnbindOperationRecorderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +23,7 @@ import org.springframework.transaction.compensating.CompensatingTransactionOpera import javax.naming.ldap.LdapName; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -57,11 +56,11 @@ public class UnbindOperationRecorderTest { .recordOperation(new Object[] { expectedDn }); // Verify result - assertTrue(operation instanceof UnbindOperationExecutor); + assertThat(operation instanceof UnbindOperationExecutor).isTrue(); UnbindOperationExecutor rollbackOperation = (UnbindOperationExecutor) operation; - assertSame(ldapOperationsMock, rollbackOperation.getLdapOperations()); - assertSame(expectedDn, rollbackOperation.getOriginalDn()); - assertSame(expectedTempName, rollbackOperation.getTemporaryDn()); + assertThat(rollbackOperation.getLdapOperations()).isSameAs(ldapOperationsMock); + assertThat(rollbackOperation.getOriginalDn()).isSameAs(expectedDn); + assertThat(rollbackOperation.getTemporaryDn()).isSameAs(expectedTempName); } } diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/ContextSourceTransactionManagerTest.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/ContextSourceTransactionManagerTest.java index b9299ab1..99628ed9 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/ContextSourceTransactionManagerTest.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/ContextSourceTransactionManagerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,11 +36,8 @@ import javax.naming.directory.DirContext; import javax.sql.DataSource; import java.sql.Connection; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -78,10 +75,10 @@ public class ContextSourceTransactionManagerTest { public void testDoGetTransaction() { Object result = tested.doGetTransaction(); - assertNotNull(result); - assertTrue(result instanceof CompensatingTransactionObject); + assertThat(result).isNotNull(); + assertThat(result instanceof CompensatingTransactionObject).isTrue(); CompensatingTransactionObject transactionObject = (CompensatingTransactionObject) result; - assertNull(transactionObject.getHolder()); + assertThat(transactionObject.getHolder()).isNull(); } @Test @@ -89,7 +86,7 @@ public class ContextSourceTransactionManagerTest { CompensatingTransactionHolderSupport expectedContextHolder = new DirContextHolder(null, null); TransactionSynchronizationManager.bindResource(contextSourceMock, expectedContextHolder); Object result = tested.doGetTransaction(); - assertSame(expectedContextHolder, ((CompensatingTransactionObject) result).getHolder()); + assertThat(((CompensatingTransactionObject) result).getHolder()).isSameAs(expectedContextHolder); } @Test @@ -101,7 +98,7 @@ public class ContextSourceTransactionManagerTest { DirContextHolder foundContextHolder = (DirContextHolder) TransactionSynchronizationManager .getResource(contextSourceMock); - assertSame(contextMock, foundContextHolder.getCtx()); + assertThat(foundContextHolder.getCtx()).isSameAs(contextMock); } @Test @@ -124,8 +121,8 @@ public class ContextSourceTransactionManagerTest { tested.doCleanupAfterCompletion(new CompensatingTransactionObject(expectedContextHolder)); - assertNull(TransactionSynchronizationManager.getResource(contextSourceMock)); - assertNull(expectedContextHolder.getTransactionOperationManager()); + assertThat(TransactionSynchronizationManager.getResource(contextSourceMock)).isNull(); + assertThat(expectedContextHolder.getTransactionOperationManager()).isNull(); verify(contextMock).close(); } @@ -138,7 +135,7 @@ public class ContextSourceTransactionManagerTest { ContextSource result = tested.getContextSource(); // Verify result - assertSame(contextSourceMock, result); + assertThat(result).isSameAs(contextSourceMock); } @Test @@ -191,7 +188,7 @@ public class ContextSourceTransactionManagerTest { fail("Exception should be thrown"); } catch (CannotCreateTransactionException expected) { - assertSame("Should be thrown exception", connectException, expected.getCause()); + assertThat(expected.getCause()).as("Should be thrown exception").isSameAs(connectException); } verify(connectionMock).rollback(); diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/TransactionAwareContextSourceProxyTest.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/TransactionAwareContextSourceProxyTest.java index 7fb3e084..e5362dd8 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/TransactionAwareContextSourceProxyTest.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/TransactionAwareContextSourceProxyTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,9 +23,7 @@ import org.springframework.ldap.core.DirContextProxy; import javax.naming.directory.DirContext; import javax.naming.ldap.LdapContext; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -55,11 +53,9 @@ public class TransactionAwareContextSourceProxyTest { DirContext result = tested.getReadWriteContext(); - assertNotNull("Result should not be null", result); - assertTrue("Should be an LdapContext instance", - result instanceof LdapContext); - assertTrue("Should be a DirContextProxy instance", - result instanceof DirContextProxy); + assertThat(result).isNotNull(); + assertThat(result instanceof LdapContext).isTrue(); + assertThat(result instanceof DirContextProxy).isTrue(); } @Test @@ -68,13 +64,10 @@ public class TransactionAwareContextSourceProxyTest { DirContext result = tested.getReadWriteContext(); - assertNotNull("Result should not be null", result); - assertTrue("Should be a DirContext instance", - result instanceof DirContext); - assertFalse("Should not be an LdapContext instance", - result instanceof LdapContext); - assertTrue("Should be a DirContextProxy instance", - result instanceof DirContextProxy); + assertThat(result).as("Result should not be null").isNotNull(); + assertThat(result instanceof DirContext).isTrue(); + assertThat(result instanceof LdapContext).isFalse(); + assertThat(result instanceof DirContextProxy).isTrue(); } @Test @@ -83,10 +76,8 @@ public class TransactionAwareContextSourceProxyTest { DirContext result = tested.getReadOnlyContext(); - assertNotNull("Result should not be null", result); - assertTrue("Should be an LdapContext instance", - result instanceof LdapContext); - assertTrue("Should be a DirContextProxy instance", - result instanceof DirContextProxy); + assertThat(result).as("Result should not be null").isNotNull(); + assertThat(result instanceof LdapContext).isTrue(); + assertThat(result instanceof DirContextProxy).isTrue(); } } diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/support/DefaultTempEntryRenamingStrategyTest.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/support/DefaultTempEntryRenamingStrategyTest.java index b5f11f75..2a8fabda 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/support/DefaultTempEntryRenamingStrategyTest.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/support/DefaultTempEntryRenamingStrategyTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,7 @@ import org.springframework.ldap.support.LdapUtils; import javax.naming.Name; import javax.naming.ldap.LdapName; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; +import static org.assertj.core.api.Assertions.assertThat; public class DefaultTempEntryRenamingStrategyTest { @@ -33,9 +32,8 @@ public class DefaultTempEntryRenamingStrategyTest { DefaultTempEntryRenamingStrategy tested = new DefaultTempEntryRenamingStrategy(); Name result = tested.getTemporaryName(expectedOriginalName); - assertEquals("cn=john doe_temp,ou=somecompany,c=SE", result - .toString()); - assertNotSame(expectedOriginalName, result); + assertThat(result.toString()).isEqualTo("cn=john doe_temp,ou=somecompany,c=SE"); + assertThat(result).isNotSameAs(expectedOriginalName); } @Test @@ -45,8 +43,7 @@ public class DefaultTempEntryRenamingStrategyTest { DefaultTempEntryRenamingStrategy tested = new DefaultTempEntryRenamingStrategy(); Name result = tested.getTemporaryName(expectedOriginalName); - assertEquals("cn=john doe+sn=doe_temp,ou=somecompany,c=SE", result - .toString()); + assertThat(result.toString()).isEqualTo("cn=john doe+sn=doe_temp,ou=somecompany,c=SE"); } diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/support/DifferentSubtreeTempEntryRenamingStrategyTest.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/support/DifferentSubtreeTempEntryRenamingStrategyTest.java index 8dde4b40..60eeab6c 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/support/DifferentSubtreeTempEntryRenamingStrategyTest.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/support/DifferentSubtreeTempEntryRenamingStrategyTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import org.springframework.ldap.support.LdapUtils; import javax.naming.Name; import javax.naming.ldap.LdapName; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class DifferentSubtreeTempEntryRenamingStrategyTest { @Test @@ -37,8 +37,7 @@ public class DifferentSubtreeTempEntryRenamingStrategyTest { Name result = tested.getTemporaryName(originalName); // Verify result - assertEquals("cn=john doe" + nextSequenceNo + ",ou=tempEntries", - result.toString()); + assertThat(result.toString()).isEqualTo("cn=john doe" + nextSequenceNo + ",ou=tempEntries"); } } diff --git a/core/src/test/java/org/springframework/ldap/util/ListComparatorTest.java b/core/src/test/java/org/springframework/ldap/util/ListComparatorTest.java index 3821f5b0..cfad5b0f 100644 --- a/core/src/test/java/org/springframework/ldap/util/ListComparatorTest.java +++ b/core/src/test/java/org/springframework/ldap/util/ListComparatorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,7 @@ import org.springframework.ldap.support.ListComparator; import java.util.Arrays; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for ListComparator. @@ -45,7 +44,7 @@ public class ListComparatorTest { List list2 = Arrays.asList(0, 0); int result = tested.compare(list1, list2); - assertEquals(0, result); + assertThat(result).isEqualTo(0); } @Test @@ -54,7 +53,7 @@ public class ListComparatorTest { List list2 = Arrays.asList(0, 1); int result = tested.compare(list1, list2); - assertTrue(result < 0); + assertThat(result < 0).isTrue(); } @Test @@ -63,7 +62,7 @@ public class ListComparatorTest { List list2 = Arrays.asList(0, 0); int result = tested.compare(list1, list2); - assertTrue(result > 0); + assertThat(result > 0).isTrue(); } @Test @@ -72,7 +71,7 @@ public class ListComparatorTest { List list2 = Arrays.asList(0, 0); int result = tested.compare(list1, list2); - assertTrue(result > 0); + assertThat(result > 0).isTrue(); } @Test @@ -81,6 +80,6 @@ public class ListComparatorTest { List list2 = Arrays.asList(0, 0, 0); int result = tested.compare(list1, list2); - assertTrue(result < 0); + assertThat(result < 0).isTrue(); } } diff --git a/core/src/test/java/org/springframework/transaction/compensating/support/DefaultCompensatingTransactionOperationManagerTest.java b/core/src/test/java/org/springframework/transaction/compensating/support/DefaultCompensatingTransactionOperationManagerTest.java index 64ed29da..646d4cfb 100644 --- a/core/src/test/java/org/springframework/transaction/compensating/support/DefaultCompensatingTransactionOperationManagerTest.java +++ b/core/src/test/java/org/springframework/transaction/compensating/support/DefaultCompensatingTransactionOperationManagerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,8 +24,7 @@ import org.springframework.transaction.compensating.CompensatingTransactionOpera import java.util.Stack; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -60,8 +59,8 @@ public class DefaultCompensatingTransactionOperationManagerTest { verify(operationExecutorMock).performOperation(); Stack result = tested.getOperationExecutors(); - assertFalse(result.isEmpty()); - assertSame(operationExecutorMock, result.peek()); + assertThat(result.isEmpty()).isFalse(); + assertThat(result.peek()).isSameAs(operationExecutorMock); } @Test diff --git a/gradle/java.gradle b/gradle/java.gradle index 0f7ffe03..a13ecee5 100644 --- a/gradle/java.gradle +++ b/gradle/java.gradle @@ -21,6 +21,7 @@ ext.queryDslVersion = '4.0.9' ext.slf4jVersion = '1.7.12' ext.powerMockVersion = '1.6.2' ext.commonsPool2Version = '2.4.2' +ext.assertjVersion= '2.3.0' ext.powerMockDependencies = [ "org.powermock:powermock-core:$powerMockVersion", @@ -45,4 +46,4 @@ ext.apachedsDependencies = [ repositories { mavenCentral() maven { url 'https://repo.spring.io/libs-snapshot' } -} \ No newline at end of file +} diff --git a/ldif/ldif-batch/build.gradle b/ldif/ldif-batch/build.gradle index a8c782da..d2a90ad6 100644 --- a/ldif/ldif-batch/build.gradle +++ b/ldif/ldif-batch/build.gradle @@ -13,6 +13,7 @@ dependencies { "org.springframework:spring-context:$springVersion", "org.springframework:spring-aop:$springVersion", "org.springframework:spring-test:$springVersion", + "org.assertj:assertj-core:$assertjVersion" testCompile("org.springframework.batch:spring-batch-test:$springBatchVersion") { exclude group: "org.springframework", module: "spring-test" @@ -27,4 +28,4 @@ project.tasks.withType(Test).all { t-> if(name.startsWith('springIo')) { exclude '**/Batch20*.class' } -} \ No newline at end of file +} diff --git a/ldif/ldif-batch/src/test/java/org/springframework/ldap/ldif/batch/LdifReaderTest.java b/ldif/ldif-batch/src/test/java/org/springframework/ldap/ldif/batch/LdifReaderTest.java index b2926a0e..c9a2f71a 100644 --- a/ldif/ldif-batch/src/test/java/org/springframework/ldap/ldif/batch/LdifReaderTest.java +++ b/ldif/ldif-batch/src/test/java/org/springframework/ldap/ldif/batch/LdifReaderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,21 +27,20 @@ import org.springframework.batch.test.AbstractJobTests; import org.springframework.batch.test.AssertFile; import org.springframework.core.io.Resource; import org.springframework.core.io.UrlResource; -import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.Assert; import java.net.MalformedURLException; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.fail; @RunWith(SpringJUnit4ClassRunner.class) public abstract class LdifReaderTest extends AbstractJobTests { private static Logger log = LoggerFactory.getLogger(LdifReaderTest.class); - + private Resource expected; private Resource actual; - + public LdifReaderTest() { try { expected = new UrlResource("file:src/test/resources/expectedOutput.ldif"); @@ -50,34 +49,34 @@ public abstract class LdifReaderTest extends AbstractJobTests { log.error("Unexpected error", e); } } - + @Before public void checkFiles() { Assert.isTrue(expected.exists(), "Expected does not exist."); } - + @Test public void testValidRun() { try { JobExecution jobExecution = this.launchStep("step1"); - + //Ensure job completed successfully. Assert.isTrue(jobExecution.getExitStatus().equals(ExitStatus.COMPLETED), "Step Execution did not complete normally: " + jobExecution.getExitStatus()); //Check output. Assert.isTrue(actual.exists(), "Actual does not exist."); AssertFile.assertFileEquals(expected.getFile(), actual.getFile()); - + } catch (Exception e) { e.printStackTrace(); - fail(); + fail(e.getMessage()); } } @Test public void testResourceNotExists() { JobExecution jobExecution = this.launchStep("step2"); - + Assert.isTrue(jobExecution.getExitStatus().getExitCode().equals("FAILED"), "The job exit status is not FAILED."); Assert.isTrue(jobExecution.getExitStatus().getExitDescription().contains("Failed to initialize the reader"), "The job failed for the wrong reason."); } diff --git a/ldif/ldif-batch/src/test/java/org/springframework/ldap/ldif/batch/MappingLdifReaderTest.java b/ldif/ldif-batch/src/test/java/org/springframework/ldap/ldif/batch/MappingLdifReaderTest.java index aca03ccb..84736e17 100644 --- a/ldif/ldif-batch/src/test/java/org/springframework/ldap/ldif/batch/MappingLdifReaderTest.java +++ b/ldif/ldif-batch/src/test/java/org/springframework/ldap/ldif/batch/MappingLdifReaderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,21 +27,20 @@ import org.springframework.batch.test.AbstractJobTests; import org.springframework.batch.test.AssertFile; import org.springframework.core.io.Resource; import org.springframework.core.io.UrlResource; -import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.Assert; import java.net.MalformedURLException; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.fail; @RunWith(SpringJUnit4ClassRunner.class) public abstract class MappingLdifReaderTest extends AbstractJobTests { private static Logger log = LoggerFactory.getLogger(MappingLdifReaderTest.class); - + private Resource expected; private Resource actual; - + public MappingLdifReaderTest() { try { expected = new UrlResource("file:src/test/resources/expectedOutput.ldif"); @@ -50,34 +49,34 @@ public abstract class MappingLdifReaderTest extends AbstractJobTests { log.error("Unexpected error", e); } } - + @Before public void checkFiles() { Assert.isTrue(expected.exists(), "Expected does not exist."); } - + @Test public void testValidRun() { try { JobExecution jobExecution = this.launchStep("step1"); - + //Ensure job completed successfully. Assert.isTrue(jobExecution.getExitStatus().equals(ExitStatus.COMPLETED), "Step Execution did not complete normally: " + jobExecution.getExitStatus()); //Check output. Assert.isTrue(actual.exists(), "Actual does not exist."); AssertFile.assertFileEquals(expected.getFile(), actual.getFile()); - + } catch (Exception e) { e.printStackTrace(); - fail(); + fail(e.getMessage()); } } @Test public void testResourceNotExists() { JobExecution jobExecution = this.launchStep("step2"); - + Assert.isTrue(jobExecution.getExitStatus().getExitCode().equals("FAILED"), "The job exit status is not FAILED."); Assert.isTrue(jobExecution.getExitStatus().getExitDescription().contains("Failed to initialize the reader"), "The job failed for the wrong reason."); } diff --git a/ldif/ldif-core/build.gradle b/ldif/ldif-core/build.gradle index 7cdfe5a7..eef19a5d 100644 --- a/ldif/ldif-core/build.gradle +++ b/ldif/ldif-core/build.gradle @@ -3,10 +3,11 @@ dependencies { compile project(":spring-ldap-core") testCompile "junit:junit:$junitVersion", - "commons-io:commons-io:$commonsIoVersion" + "commons-io:commons-io:$commonsIoVersion", + "org.assertj:assertj-core:$assertjVersion" testCompile ("log4j:log4j:$log4jVersion") { exclude group: 'javax.jms' exclude group: 'com.sun.jdmk' exclude group: 'com.sun.jmx' } -} \ No newline at end of file +} diff --git a/ldif/ldif-core/src/test/java/org/springframework/ldap/ldif/DefaultAttributeValidationPolicyTest.java b/ldif/ldif-core/src/test/java/org/springframework/ldap/ldif/DefaultAttributeValidationPolicyTest.java index 37dc66e3..2bbee93e 100644 --- a/ldif/ldif-core/src/test/java/org/springframework/ldap/ldif/DefaultAttributeValidationPolicyTest.java +++ b/ldif/ldif-core/src/test/java/org/springframework/ldap/ldif/DefaultAttributeValidationPolicyTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,10 +32,8 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Parses a preselected set of attributes to test the full spectrum of functionality @@ -136,30 +134,30 @@ public class DefaultAttributeValidationPolicyTest { try { LdapAttribute attribute = (LdapAttribute) policy.parse(line); - assertTrue("IDs do not match: [expected: " + attribute.getID() + ", obtained: " + id + "]", id.equalsIgnoreCase(attribute.getID())); + assertThat(id.equalsIgnoreCase(attribute.getID())).as("IDs do not match: [expected: " + attribute.getID() + ", obtained: " + id + "]").isTrue(); String[] expected = !StringUtils.hasLength(options) ? new String[] {} : options.replaceFirst(";","").split(";"); Arrays.sort(expected); String[] obtained = attribute.getOptions().toArray(new String[] {}); Arrays.sort(obtained); - assertArrayEquals("Options do not match: ", expected, obtained); + assertThat(obtained).as("Options do not match: ").isEqualTo(expected); switch(type) { case STRING: - assertTrue("Value is not a string.", attribute.get() instanceof String); - assertEquals("Values do not match: ", value, attribute.get()); + assertThat(attribute.get() instanceof String).as("Value is not a string.").isTrue(); + assertThat(attribute.get()).as("Values do not match: ").isEqualTo(value); break; case BASE64: byte[] bytes = LdapEncoder.parseBase64Binary(value); - assertTrue("Value is not a byte[].", attribute.get() instanceof byte[]); - assertArrayEquals("Values do not match: ", bytes, (byte[]) attribute.get()); + assertThat(attribute.get() instanceof byte[]).as("Value is not a byte[].").isTrue(); + assertThat((byte[]) attribute.get()).as("Values do not match: ").isEqualTo(bytes); break; case URL: URI url = new URI(value); - assertTrue("Value is not a URL.", attribute.get() instanceof URI); - assertEquals("Values do not match: ", url, attribute.get()); + assertThat(attribute.get() instanceof URI).as("Value is not a URL.").isTrue(); + assertThat(attribute.get()).as("Values do not match: ").isEqualTo(url); break; } diff --git a/ldif/ldif-core/src/test/java/org/springframework/ldap/ldif/Ldap233LdifParserTest.java b/ldif/ldif-core/src/test/java/org/springframework/ldap/ldif/Ldap233LdifParserTest.java index 513ee196..cd1c6a41 100644 --- a/ldif/ldif-core/src/test/java/org/springframework/ldap/ldif/Ldap233LdifParserTest.java +++ b/ldif/ldif-core/src/test/java/org/springframework/ldap/ldif/Ldap233LdifParserTest.java @@ -1,52 +1,52 @@ -/* - * Copyright 2005-2013 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.ldap.ldif; - -import org.apache.commons.io.FileUtils; -import org.junit.Test; -import org.springframework.ldap.ldif.parser.LdifParser; -import org.springframework.ldap.schema.BasicSchemaSpecification; - -import java.io.File; -import java.io.IOException; - -import static org.junit.Assert.assertNull; - -/** - * @author Mattias Hellborg Arthursson - */ -public class Ldap233LdifParserTest { - - /** - * This previously went into endless loop. - * - * @throws IOException - */ - @Test - public void ldap233Test() throws IOException { - File testFile = File.createTempFile("ldapTest", ".ldif"); - FileUtils.write(testFile, "This is just some random text"); - - LdifParser parser = new LdifParser(testFile); - parser.setRecordSpecification(new BasicSchemaSpecification()); - parser.open(); - assertNull(parser.getRecord()); - - testFile.delete(); - } - -} +/* + * Copyright 2005-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.ldap.ldif; + +import org.apache.commons.io.FileUtils; +import org.junit.Test; +import org.springframework.ldap.ldif.parser.LdifParser; +import org.springframework.ldap.schema.BasicSchemaSpecification; + +import java.io.File; +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Mattias Hellborg Arthursson + */ +public class Ldap233LdifParserTest { + + /** + * This previously went into endless loop. + * + * @throws IOException + */ + @Test + public void ldap233Test() throws IOException { + File testFile = File.createTempFile("ldapTest", ".ldif"); + FileUtils.write(testFile, "This is just some random text"); + + LdifParser parser = new LdifParser(testFile); + parser.setRecordSpecification(new BasicSchemaSpecification()); + parser.open(); + assertThat(parser.getRecord()).isNull(); + + testFile.delete(); + } + +} diff --git a/ldif/ldif-core/src/test/java/org/springframework/ldap/ldif/LdifParserTest.java b/ldif/ldif-core/src/test/java/org/springframework/ldap/ldif/LdifParserTest.java index 2ed5a325..654527f9 100644 --- a/ldif/ldif-core/src/test/java/org/springframework/ldap/ldif/LdifParserTest.java +++ b/ldif/ldif-core/src/test/java/org/springframework/ldap/ldif/LdifParserTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,12 +28,12 @@ import org.springframework.ldap.schema.BasicSchemaSpecification; import java.io.IOException; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Unit test for LdifParser. - * + * * Test results in complete end to end test of all LdifParser functionality: * 1.) Open a file * 2.) Read lines and compose an attribute. @@ -41,17 +41,17 @@ import static org.junit.Assert.fail; * 4.) Repeat until end of record (Identify end of record). * 5.) Return a valid LdapAttributes object. * 6.) Close file upon completion. - * + * * Provided test file is comprised of sample LDIFs from RFC2849 and exhausts the full range of * the functionality prescribed by RFC2849 for the LDAP Data Interchange Format (LDIF). - * + * * @author Keith Barlow - * + * */ public class LdifParserTest { private static Logger log = LoggerFactory.getLogger(LdifParserTest.class); - + private LdifParser parser; /** @@ -63,7 +63,7 @@ public class LdifParserTest { parser = new LdifParser(new ClassPathResource("test.ldif")); parser.setRecordSpecification(new BasicSchemaSpecification()); } - + /** * Setup: opens file. */ @@ -75,44 +75,46 @@ public class LdifParserTest { fail(e.getMessage()); } } - + /** * Executes test: reads all records from LDIF file and validates an LdapAttributes object is successfully created. */ @Test public void parseLdif() { int count = 0; - + try { LdapAttributes attributes; - + while (parser.hasMoreRecords()) { try { attributes = parser.getRecord(); log.info("attributes:\n" + attributes); if (attributes != null) { - assertTrue("A dn is required.", attributes.getDN() != null); - assertTrue("Object class is required.", attributes.get("objectclass") != null); + assertThat(attributes.getDN() != null).isTrue(); + assertThat(attributes.get("objectclass") != null).isTrue(); count++; } } catch (InvalidAttributeFormatException e) { log.error("Invalid attribute", e); - if (count != 6) fail(); + if (count != 6) { + fail(e.getMessage()); + } } - + log.debug("hasMoreRecords: " + parser.hasMoreRecords()); } - + log.info("record count: " + count); - //assertTrue("An incorrect number of records were parsed.", count == 8); - + //assertThat(count == 8).as("An incorrect number of records were parsed.").isTrue(); + log.info("Done!"); - + } catch (IOException e) { fail(e.getMessage()); } } - + /** * Cleanup: closes file. */ diff --git a/odm/src/test/java/org/springframework/ldap/odm/test/utils/RunnableTest.java b/odm/src/test/java/org/springframework/ldap/odm/test/utils/RunnableTest.java old mode 100755 new mode 100644 diff --git a/samples/odm/build.gradle b/samples/odm/build.gradle index 0fa1910e..588f22e8 100644 --- a/samples/odm/build.gradle +++ b/samples/odm/build.gradle @@ -12,5 +12,6 @@ dependencies { runtime 'ch.qos.logback:logback-classic:1.0.13' testCompile "org.springframework:spring-test:$springVersion", - "junit:junit:$junitVersion" -} \ No newline at end of file + "junit:junit:$junitVersion", + "org.assertj:assertj-core:$assertjVersion" +} diff --git a/samples/odm/src/test/java/org/springframework/ldap/samples/odm/dao/PersonDaoSampleIntegrationTest.java b/samples/odm/src/test/java/org/springframework/ldap/samples/odm/dao/PersonDaoSampleIntegrationTest.java index bd45edb8..c2aafd86 100644 --- a/samples/odm/src/test/java/org/springframework/ldap/samples/odm/dao/PersonDaoSampleIntegrationTest.java +++ b/samples/odm/src/test/java/org/springframework/ldap/samples/odm/dao/PersonDaoSampleIntegrationTest.java @@ -1,132 +1,129 @@ -/* - * Copyright 2005-2013 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.ldap.samples.odm.dao; - -import org.junit.Before; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.ldap.NameNotFoundException; -import org.springframework.ldap.samples.plain.dao.PersonDao; -import org.springframework.ldap.samples.plain.domain.Person; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; - -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -/** - * Abstract base class for PersonDao integration tests. - * - * @author Mattias Hellborg Arthursson - * @author Ulrik Sandberg - */ -@ContextConfiguration("/config/testContext.xml") -public class PersonDaoSampleIntegrationTest extends - AbstractJUnit4SpringContextTests { - - protected Person person; - - @Autowired - private PersonDao personDao; - - @Before - public void preparePerson() throws Exception { - person = new Person(); - person.setCountry("Sweden"); - person.setCompany("company1"); - person.setFullName("Some Person"); - person.setLastName("Person"); - person - .setDescription("Sweden, Company1, Some Person"); - person.setPhone("+46 555-123456"); - } - - /** - * Having a single test method test create, update and delete is not exactly - * the ideal way of testing, since they depend on each other. A better way - * would be to separate the tests and load a test fixture before each - * operation, in order to guarantee the expected state every time. See the - * ldaptemplate-person sample for the correct way to do this. - */ - @Test - public void testCreateUpdateDelete() { - try { - person.setFullName("Another Person"); - personDao.create(person); - personDao.findByPrimaryKey( - "Sweden", "company1", - "Another Person"); - // if we got here, create succeeded - - person.setDescription("Another description"); - personDao.update(person); - Person result = personDao - .findByPrimaryKey( - "Sweden", "company1", - "Another Person"); - assertEquals( - "Another description", result - .getDescription()); - } catch(Exception e){ - e.printStackTrace(); - } - finally { - personDao.delete(person); - try { - personDao.findByPrimaryKey( - "Sweden", "company1", - "Another Person"); - fail("NameNotFoundException (when using Spring LDAP) or RuntimeException (when using traditional) expected"); - } catch (NameNotFoundException expected) { - // expected - } catch (RuntimeException expected) { - // expected - } - } - } - - @Test - public void testGetAllPersonNames() { - List result = personDao.getAllPersonNames(); - assertEquals(2, result.size()); - String first = result.get(0); - assertEquals("Some Person", first); - } - - @Test - public void testFindAll() { - List result = personDao.findAll(); - assertEquals(2, result.size()); - Person first = result.get(0); - assertEquals("Some Person", first - .getFullName()); - } - - @Test - public void testFindByPrimaryKey() { - Person result = personDao.findByPrimaryKey( - "Sweden", "company1", "Some Person"); - - assertEquals("Sweden", result.getCountry()); - assertEquals("company1", result.getCompany()); - assertEquals("Sweden, Company1, Some Person", result.getDescription()); - assertEquals("+46 555-123456", result.getPhone()); - assertEquals("Some Person", result.getFullName()); - assertEquals("Person", result.getLastName()); - } -} +/* + * Copyright 2005-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.ldap.samples.odm.dao; + +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.ldap.NameNotFoundException; +import org.springframework.ldap.samples.plain.dao.PersonDao; +import org.springframework.ldap.samples.plain.domain.Person; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + +/** + * Abstract base class for PersonDao integration tests. + * + * @author Mattias Hellborg Arthursson + * @author Ulrik Sandberg + */ +@ContextConfiguration("/config/testContext.xml") +public class PersonDaoSampleIntegrationTest extends + AbstractJUnit4SpringContextTests { + + protected Person person; + + @Autowired + private PersonDao personDao; + + @Before + public void preparePerson() throws Exception { + person = new Person(); + person.setCountry("Sweden"); + person.setCompany("company1"); + person.setFullName("Some Person"); + person.setLastName("Person"); + person + .setDescription("Sweden, Company1, Some Person"); + person.setPhone("+46 555-123456"); + } + + /** + * Having a single test method test create, update and delete is not exactly + * the ideal way of testing, since they depend on each other. A better way + * would be to separate the tests and load a test fixture before each + * operation, in order to guarantee the expected state every time. See the + * ldaptemplate-person sample for the correct way to do this. + */ + @Test + public void testCreateUpdateDelete() { + try { + person.setFullName("Another Person"); + personDao.create(person); + personDao.findByPrimaryKey( + "Sweden", "company1", + "Another Person"); + // if we got here, create succeeded + + person.setDescription("Another description"); + personDao.update(person); + Person result = personDao + .findByPrimaryKey( + "Sweden", "company1", + "Another Person"); + assertThat(result.getDescription()).isEqualTo("Another description"); + } catch(Exception e){ + e.printStackTrace(); + } + finally { + personDao.delete(person); + try { + personDao.findByPrimaryKey( + "Sweden", "company1", + "Another Person"); + fail("NameNotFoundException (when using Spring LDAP) or RuntimeException (when using traditional) expected"); + } catch (NameNotFoundException expected) { + // expected + } catch (RuntimeException expected) { + // expected + } + } + } + + @Test + public void testGetAllPersonNames() { + List result = personDao.getAllPersonNames(); + assertThat(result).hasSize(2); + String first = result.get(0); + assertThat(first).isEqualTo("Some Person"); + } + + @Test + public void testFindAll() { + List result = personDao.findAll(); + assertThat(result).hasSize(2); + Person first = result.get(0); + assertThat(first.getFullName()).isEqualTo("Some Person"); + } + + @Test + public void testFindByPrimaryKey() { + Person result = personDao.findByPrimaryKey( + "Sweden", "company1", "Some Person"); + + assertThat(result.getCountry()).isEqualTo("Sweden"); + assertThat(result.getCompany()).isEqualTo("company1"); + assertThat(result.getDescription()).isEqualTo("Sweden, Company1, Some Person"); + assertThat(result.getPhone()).isEqualTo("+46 555-123456"); + assertThat(result.getFullName()).isEqualTo("Some Person"); + assertThat(result.getLastName()).isEqualTo("Person"); + } +} diff --git a/samples/odm/src/test/java/org/springframework/ldap/samples/utils/LdapTreeBuilderIntegrationTest.java b/samples/odm/src/test/java/org/springframework/ldap/samples/utils/LdapTreeBuilderIntegrationTest.java index e29ad216..4072a47a 100644 --- a/samples/odm/src/test/java/org/springframework/ldap/samples/utils/LdapTreeBuilderIntegrationTest.java +++ b/samples/odm/src/test/java/org/springframework/ldap/samples/utils/LdapTreeBuilderIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; -import static junit.framework.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; @ContextConfiguration(locations = { "/config/testContext.xml" }) public class LdapTreeBuilderIntegrationTest extends AbstractJUnit4SpringContextTests { @@ -63,8 +63,8 @@ public class LdapTreeBuilderIntegrationTest extends AbstractJUnit4SpringContextT public void visit(DirContextOperations node, int currentDepth) { LdapName next = keyIterator.next(); - assertEquals(next, node.getDn()); - assertEquals(names.get(next).intValue(), currentDepth); + assertThat(node.getDn()).isEqualTo(next); + assertThat(currentDepth).isEqualTo(names.get(next).intValue()); } } diff --git a/samples/plain/build.gradle b/samples/plain/build.gradle index 0fa1910e..588f22e8 100644 --- a/samples/plain/build.gradle +++ b/samples/plain/build.gradle @@ -12,5 +12,6 @@ dependencies { runtime 'ch.qos.logback:logback-classic:1.0.13' testCompile "org.springframework:spring-test:$springVersion", - "junit:junit:$junitVersion" -} \ No newline at end of file + "junit:junit:$junitVersion", + "org.assertj:assertj-core:$assertjVersion" +} diff --git a/samples/plain/src/test/java/org/springframework/ldap/samples/plain/dao/PersonDaoSampleIntegrationTest.java b/samples/plain/src/test/java/org/springframework/ldap/samples/plain/dao/PersonDaoSampleIntegrationTest.java index a8ef025e..14b49d92 100644 --- a/samples/plain/src/test/java/org/springframework/ldap/samples/plain/dao/PersonDaoSampleIntegrationTest.java +++ b/samples/plain/src/test/java/org/springframework/ldap/samples/plain/dao/PersonDaoSampleIntegrationTest.java @@ -1,122 +1,119 @@ -/* - * Copyright 2005-2013 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.ldap.samples.plain.dao; - -import org.junit.Before; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.ldap.NameNotFoundException; -import org.springframework.ldap.samples.plain.domain.Person; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; - -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -/** - * Abstract base class for PersonDao integration tests. - * - * @author Mattias Hellborg Arthursson - * @author Ulrik Sandberg - */ -@ContextConfiguration("/config/testContext.xml") -public class PersonDaoSampleIntegrationTest extends - AbstractJUnit4SpringContextTests { - - protected Person person; - - @Autowired - private PersonDao personDao; - - @Before - public void preparePerson() throws Exception { - person = new Person(); - person.setCountry("Sweden"); - person.setCompany("company1"); - person.setFullName("Some Person"); - person.setLastName("Person"); - person - .setDescription("Sweden, Company1, Some Person"); - person.setPhone("+46 555-123456"); - } - - /** - * Having a single test method test create, update and delete is not exactly - * the ideal way of testing, since they depend on each other. A better way - * would be to separate the tests and load a test fixture before each - * operation, in order to guarantee the expected state every time. See the - * ldaptemplate-person sample for the correct way to do this. - */ - @Test - public void testCreateUpdateDelete() { - try { - person.setFullName("Another Person"); - personDao.create(person); - personDao.findByPrimaryKey( - "Sweden", "company1", - "Another Person"); - // if we got here, create succeeded - - person.setDescription("Another description"); - personDao.update(person); - Person result = personDao - .findByPrimaryKey( - "Sweden", "company1", - "Another Person"); - assertEquals( - "Another description", result - .getDescription()); - } finally { - personDao.delete(person); - try { - personDao.findByPrimaryKey( - "Sweden", "company1", - "Another Person"); - fail("NameNotFoundException (when using Spring LDAP) or RuntimeException (when using traditional) expected"); - } catch (NameNotFoundException expected) { - // expected - } catch (RuntimeException expected) { - // expected - } - } - } - - @Test - public void testGetAllPersonNames() { - List result = personDao.getAllPersonNames(); - assertEquals(2, result.size()); - String first = (String) result.get(0); - assertEquals("Some Person", first); - } - - @Test - public void testFindAll() { - List result = personDao.findAll(); - assertEquals(2, result.size()); - Person first = (Person) result.get(0); - assertEquals("Some Person", first - .getFullName()); - } - - @Test - public void testFindByPrimaryKey() { - Person result = personDao.findByPrimaryKey( - "Sweden", "company1", "Some Person"); - assertEquals(person, result); - } -} +/* + * Copyright 2005-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.ldap.samples.plain.dao; + +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.ldap.NameNotFoundException; +import org.springframework.ldap.samples.plain.domain.Person; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + +/** + * Abstract base class for PersonDao integration tests. + * + * @author Mattias Hellborg Arthursson + * @author Ulrik Sandberg + */ +@ContextConfiguration("/config/testContext.xml") +public class PersonDaoSampleIntegrationTest extends + AbstractJUnit4SpringContextTests { + + protected Person person; + + @Autowired + private PersonDao personDao; + + @Before + public void preparePerson() throws Exception { + person = new Person(); + person.setCountry("Sweden"); + person.setCompany("company1"); + person.setFullName("Some Person"); + person.setLastName("Person"); + person + .setDescription("Sweden, Company1, Some Person"); + person.setPhone("+46 555-123456"); + } + + /** + * Having a single test method test create, update and delete is not exactly + * the ideal way of testing, since they depend on each other. A better way + * would be to separate the tests and load a test fixture before each + * operation, in order to guarantee the expected state every time. See the + * ldaptemplate-person sample for the correct way to do this. + */ + @Test + public void testCreateUpdateDelete() { + try { + person.setFullName("Another Person"); + personDao.create(person); + personDao.findByPrimaryKey( + "Sweden", "company1", + "Another Person"); + // if we got here, create succeeded + + person.setDescription("Another description"); + personDao.update(person); + Person result = personDao + .findByPrimaryKey( + "Sweden", "company1", + "Another Person"); + assertThat(result.getDescription()).isEqualTo("Another description"); + } finally { + personDao.delete(person); + try { + personDao.findByPrimaryKey( + "Sweden", "company1", + "Another Person"); + fail("NameNotFoundException (when using Spring LDAP) or RuntimeException (when using traditional) expected"); + } catch (NameNotFoundException expected) { + // expected + } catch (RuntimeException expected) { + // expected + } + } + } + + @Test + public void testGetAllPersonNames() { + List result = personDao.getAllPersonNames(); + assertThat(result).hasSize(2); + String first = (String) result.get(0); + assertThat(first).isEqualTo("Some Person"); + } + + @Test + public void testFindAll() { + List result = personDao.findAll(); + assertThat(result).hasSize(2); + Person first = (Person) result.get(0); + assertThat(first.getFullName()).isEqualTo("Some Person"); + } + + @Test + public void testFindByPrimaryKey() { + Person result = personDao.findByPrimaryKey( + "Sweden", "company1", "Some Person"); + assertThat(result).isEqualTo(person); + } +} diff --git a/samples/plain/src/test/java/org/springframework/ldap/samples/utils/LdapTreeBuilderIntegrationTest.java b/samples/plain/src/test/java/org/springframework/ldap/samples/utils/LdapTreeBuilderIntegrationTest.java index e29ad216..4072a47a 100644 --- a/samples/plain/src/test/java/org/springframework/ldap/samples/utils/LdapTreeBuilderIntegrationTest.java +++ b/samples/plain/src/test/java/org/springframework/ldap/samples/utils/LdapTreeBuilderIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; -import static junit.framework.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; @ContextConfiguration(locations = { "/config/testContext.xml" }) public class LdapTreeBuilderIntegrationTest extends AbstractJUnit4SpringContextTests { @@ -63,8 +63,8 @@ public class LdapTreeBuilderIntegrationTest extends AbstractJUnit4SpringContextT public void visit(DirContextOperations node, int currentDepth) { LdapName next = keyIterator.next(); - assertEquals(next, node.getDn()); - assertEquals(names.get(next).intValue(), currentDepth); + assertThat(node.getDn()).isEqualTo(next); + assertThat(currentDepth).isEqualTo(names.get(next).intValue()); } } diff --git a/sandbox/build.gradle b/sandbox/build.gradle index 459ca601..0f969201 100644 --- a/sandbox/build.gradle +++ b/sandbox/build.gradle @@ -7,5 +7,6 @@ dependencies { testCompile "junit:junit:$junitVersion", "org.mockito:mockito-core:$mockitoVersion", - "gsbase:gsbase:$gsbaseVersion" -} \ No newline at end of file + "gsbase:gsbase:$gsbaseVersion", + "org.assertj:assertj-core:$assertjVersion" +} diff --git a/sandbox/src/test/java/org/springframework/ldap/control/VirtualListViewControlDirContextProcessorTest.java b/sandbox/src/test/java/org/springframework/ldap/control/VirtualListViewControlDirContextProcessorTest.java index cdb64245..96ad098d 100644 --- a/sandbox/src/test/java/org/springframework/ldap/control/VirtualListViewControlDirContextProcessorTest.java +++ b/sandbox/src/test/java/org/springframework/ldap/control/VirtualListViewControlDirContextProcessorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,9 +29,8 @@ import javax.naming.ldap.Control; import javax.naming.ldap.LdapContext; import java.io.IOException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -64,8 +63,8 @@ public class VirtualListViewControlDirContextProcessorTest { new VirtualListViewResultsCookie(new byte[0], 0, 0)); VirtualListViewControl result = (VirtualListViewControl) tested .createRequestControl(); - assertNotNull(result); - assertEquals(OID_REQUEST, result.getID()); + assertThat(result).isNotNull(); + assertThat(result.getID()).isEqualTo(OID_REQUEST); // verify that the values have been encoded as we expect int expectedBeforeCount = 0; @@ -89,8 +88,8 @@ public class VirtualListViewControlDirContextProcessorTest { tested.setOffsetPercentage(true); VirtualListViewControl result = (VirtualListViewControl) tested .createRequestControl(); - assertNotNull(result); - assertEquals(OID_REQUEST, result.getID()); + assertThat(result).isNotNull(); + assertThat(result.getID()).isEqualTo(OID_REQUEST); int expectedBeforeCount = 2; int expectedAfterCount = 2; @@ -125,14 +124,12 @@ public class VirtualListViewControlDirContextProcessorTest { } catch (OperationNotSupportedException expected) { Throwable cause = expected.getCause(); - assertEquals(javax.naming.OperationNotSupportedException.class, - cause.getClass()); - assertEquals("[LDAP: error code 53 - Unwilling To Perform]", cause - .getMessage()); + assertThat(cause.getClass()).isEqualTo(javax.naming.OperationNotSupportedException.class); + assertThat(cause.getMessage()).isEqualTo("[LDAP: error code 53 - Unwilling To Perform]"); } - assertNotNull(tested.getCookie()); - assertEquals(0, tested.getCookie().getCookie().length); + assertThat(tested.getCookie()).isNotNull(); + assertThat(tested.getCookie().getCookie().length).isEqualTo(0); } @Test @@ -180,11 +177,10 @@ public class VirtualListViewControlDirContextProcessorTest { case 0: // byOffset int actualOffset = ber.parseInt(); int actualContentCount = ber.parseInt(); - assertEquals("beforeCount,", expectedBeforeCount, actualBeforeCount); - assertEquals("afterCount,", expectedAfterCount, actualAfterCount); - assertEquals("offset,", expectedOffset, actualOffset); - assertEquals("contentCount,", expectedContentCount, - actualContentCount); + assertThat(expectedBeforeCount).isEqualTo(actualBeforeCount); + assertThat(expectedAfterCount).isEqualTo(actualAfterCount); + assertThat(expectedOffset).isEqualTo(actualOffset); + assertThat(actualContentCount).isEqualTo(expectedContentCount); break; case 1: // greaterThanOrEqual @@ -210,7 +206,7 @@ public class VirtualListViewControlDirContextProcessorTest { if (expectedContextId != null && actualContextId == null) { fail("expected <" + expectedContextId + ">, got "); } - assertEquals(expectedContextId.length, actualContextId.length); + assertThat(actualContextId.length).isEqualTo(expectedContextId.length); } private void assertEncodedResponse(byte[] encodedValue, @@ -218,18 +214,16 @@ public class VirtualListViewControlDirContextProcessorTest { int expectedContentCount, int expectedVirtualListViewResult, byte[] expectedContextId) throws Exception { dumpEncodedValue("VirtualListViewResponse\n", encodedValue); - assertEquals(expectedEncodingLength, encodedValue.length); + assertThat(encodedValue.length).isEqualTo(expectedEncodingLength); BerDecoder ber = new BerDecoder(encodedValue, 0, encodedValue.length); ber.parseSeq(null); int actualTargetPosition = ber.parseInt(); int actualContentCount = ber.parseInt(); int actualVirtualListViewResult = ber.parseEnumeration(); - assertEquals("targetPosition,", expectedTargetPosition, - actualTargetPosition); - assertEquals("contentCount,", expectedContentCount, actualContentCount); - assertEquals("virtualListViewResult,", expectedVirtualListViewResult, - actualVirtualListViewResult); + assertThat(actualTargetPosition).isEqualTo(expectedTargetPosition); + assertThat(actualContentCount).as("contentCount,").isEqualTo(expectedContentCount); + assertThat(actualVirtualListViewResult).isEqualTo(expectedVirtualListViewResult); byte[] bs = ber.parseOctetString(Ber.ASN_OCTET_STR, null); assertContextId(expectedContextId, bs); } diff --git a/test/integration-tests-ad/build.gradle b/test/integration-tests-ad/build.gradle index d408f7df..bb8f1aa8 100644 --- a/test/integration-tests-ad/build.gradle +++ b/test/integration-tests-ad/build.gradle @@ -10,7 +10,8 @@ dependencies { testCompile "org.springframework:spring-test:$springVersion", "junit:junit:$junitVersion", - "org.slf4j:slf4j-log4j12:$slf4jVersion" + "org.slf4j:slf4j-log4j12:$slf4jVersion", + "org.assertj:assertj-core:$assertjVersion" } diff --git a/test/integration-tests-ad/src/test/java/org/springframework/ldap/itest/ad/IncrementalAttributeMapperITest.java b/test/integration-tests-ad/src/test/java/org/springframework/ldap/itest/ad/IncrementalAttributeMapperITest.java index 127f345e..45fc388f 100644 --- a/test/integration-tests-ad/src/test/java/org/springframework/ldap/itest/ad/IncrementalAttributeMapperITest.java +++ b/test/integration-tests-ad/src/test/java/org/springframework/ldap/itest/ad/IncrementalAttributeMapperITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,12 +40,8 @@ import javax.naming.directory.ModificationItem; import java.io.UnsupportedEncodingException; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * @author Mattias Hellborg Arthursson @@ -159,36 +155,36 @@ public class IncrementalAttributeMapperITest extends AbstractJUnit4SpringContext // The 'member' attribute consists of > 1500 entries and will not be returned without range specifier. DirContextOperations ctx = ldapTemplate.lookupContext(testgroupDn); - assertNull(ctx.getStringAttribute("member")); + assertThat(ctx.getStringAttribute("member")).isNull(); DefaultIncrementalAttributesMapper attributeMapper = new DefaultIncrementalAttributesMapper(new String[]{"member", "cn"}); - assertTrue("There should be more results to get", attributeMapper.hasMore()); + assertThat(attributeMapper.hasMore()).as("There should be more results to get").isTrue(); String[] attributesArray = attributeMapper.getAttributesForLookup(); - assertEquals(2, attributesArray.length); - assertEquals("member", attributesArray[0]); - assertEquals("cn", attributesArray[1]); + assertThat(attributesArray.length).isEqualTo(2); + assertThat(attributesArray[0]).isEqualTo("member"); + assertThat(attributesArray[1]).isEqualTo("cn"); // First iteration - there should now be more members left, but all cn values should have been collected. ldapTemplate.lookup(testgroupDn, attributesArray, attributeMapper); - assertTrue("There should be more results to get", attributeMapper.hasMore()); + assertThat(attributeMapper.hasMore()).as("There should be more results to get").isTrue(); // Only member attribute should be requested in this query. attributesArray = attributeMapper.getAttributesForLookup(); - assertEquals(1, attributesArray.length); - assertEquals("member;Range=1500-*", attributesArray[0]); + assertThat(attributesArray.length).isEqualTo(1); + assertThat(attributesArray[0]).isEqualTo("member;Range=1500-*"); // Second iteration - all data should now have been collected. ldapTemplate.lookup(testgroupDn, attributeMapper.getAttributesForLookup(), attributeMapper); - assertFalse("There should be no more results to get", attributeMapper.hasMore()); + assertThat(attributeMapper.hasMore()).as("There should be no more results to get").isFalse(); List memberValues = attributeMapper.getValues("member"); - assertNotNull(memberValues); - assertEquals(1501, memberValues.size()); + assertThat(memberValues).isNotNull(); + assertThat(memberValues).hasSize(1501); List cnValues = attributeMapper.getValues("cn"); - assertNotNull(cnValues); - assertEquals(1, cnValues.size()); + assertThat(cnValues).isNotNull(); + assertThat(cnValues).hasSize(1); } @Test @@ -217,10 +213,9 @@ public class IncrementalAttributeMapperITest extends AbstractJUnit4SpringContext } // LDAP-234: After rollback the attribute values were cleared after rollback - assertEquals( - 1501, + assertThat( DefaultIncrementalAttributesMapper.lookupAttributeValues( - ldapTemplate, GROUP_DN, "member").size()); + ldapTemplate, GROUP_DN, "member").size()).isEqualTo(1501); } } } diff --git a/test/integration-tests-ad/src/test/java/org/springframework/ldap/itest/ad/SchemaToJavaAdITest.java b/test/integration-tests-ad/src/test/java/org/springframework/ldap/itest/ad/SchemaToJavaAdITest.java old mode 100755 new mode 100644 index 171ac100..701c1abe --- a/test/integration-tests-ad/src/test/java/org/springframework/ldap/itest/ad/SchemaToJavaAdITest.java +++ b/test/integration-tests-ad/src/test/java/org/springframework/ldap/itest/ad/SchemaToJavaAdITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,7 +42,7 @@ import java.util.HashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; // Tests the generation of entry Java classes from LDAP schema public final class SchemaToJavaAdITest { @@ -192,21 +192,21 @@ public final class SchemaToJavaAdITest { // Check some returned values Method getDnMethod=clazz.getMethod("getDn"); Object dn=getDnMethod.invoke(fromDirectory); - assertEquals(testDn, dn); + assertThat(dn).isEqualTo(testDn); Method getCnIteratorMethod=clazz.getMethod("getCn"); @SuppressWarnings("unchecked") String cn=(String)getCnIteratorMethod.invoke(fromDirectory); - assertEquals("William Hartnell", cn); + assertThat(cn).isEqualTo("William Hartnell"); Method telephoneNumberIteratorMethod=clazz.getMethod("getTelephoneNumber"); @SuppressWarnings("unchecked") String telephoneNumber=(String)telephoneNumberIteratorMethod.invoke(fromDirectory); - assertEquals("1", telephoneNumber); + assertThat(telephoneNumber).isEqualTo("1"); // Reread and check whether equals and hashCode are at least sane Object fromDirectory2=odmManager.read(clazz, testDn); - assertEquals(fromDirectory, fromDirectory2); - assertEquals(fromDirectory.hashCode(), fromDirectory2.hashCode()); + assertThat(fromDirectory2).isEqualTo(fromDirectory); + assertThat(fromDirectory2.hashCode()).isEqualTo(fromDirectory.hashCode()); } } diff --git a/test/integration-tests-openldap/build.gradle b/test/integration-tests-openldap/build.gradle index d143209b..699a713e 100644 --- a/test/integration-tests-openldap/build.gradle +++ b/test/integration-tests-openldap/build.gradle @@ -14,7 +14,8 @@ dependencies { "gsbase:gsbase:$gsbaseVersion", "junit:junit:$junitVersion", "com.sun:ldapbp:1.0", - "org.slf4j:slf4j-log4j12:$slf4jVersion" + "org.slf4j:slf4j-log4j12:$slf4jVersion", + "org.assertj:assertj-core:$assertjVersion" } diff --git a/test/integration-tests-openldap/src/test/java/org/springframework/ldap/itest/control/PagedSearchITest.java b/test/integration-tests-openldap/src/test/java/org/springframework/ldap/itest/control/PagedSearchITest.java index d770aa53..f0fc96a6 100644 --- a/test/integration-tests-openldap/src/test/java/org/springframework/ldap/itest/control/PagedSearchITest.java +++ b/test/integration-tests-openldap/src/test/java/org/springframework/ldap/itest/control/PagedSearchITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,8 +38,7 @@ import javax.naming.directory.SearchControls; import java.io.IOException; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Mattias Hellborg Arthursson @@ -87,7 +86,7 @@ public class PagedSearchITest extends AbstractJUnit4SpringContextTests { searchControls, CN_ATTRIBUTES_MAPPER, processor); - assertEquals(3, result.size()); + assertThat(result).hasSize(3); result = operations.search( "ou=People", @@ -95,7 +94,7 @@ public class PagedSearchITest extends AbstractJUnit4SpringContextTests { searchControls, CN_ATTRIBUTES_MAPPER, processor); - assertEquals(3, result.size()); + assertThat(result).hasSize(3); result = operations.search( "ou=People", @@ -103,7 +102,7 @@ public class PagedSearchITest extends AbstractJUnit4SpringContextTests { searchControls, CN_ATTRIBUTES_MAPPER, processor); - assertEquals(3, result.size()); + assertThat(result).hasSize(3); result = operations.search( "ou=People", @@ -111,9 +110,9 @@ public class PagedSearchITest extends AbstractJUnit4SpringContextTests { searchControls, CN_ATTRIBUTES_MAPPER, processor); - assertEquals(1, result.size()); + assertThat(result).hasSize(1); - assertFalse(processor.hasMore()); + assertThat(processor.hasMore()).isFalse(); return null; } }); diff --git a/test/integration-tests-openldap/src/test/java/org/springframework/ldap/itest/core/LdapTemplateSearchResultITest.java b/test/integration-tests-openldap/src/test/java/org/springframework/ldap/itest/core/LdapTemplateSearchResultITest.java index 8526b39b..d47f2f66 100644 --- a/test/integration-tests-openldap/src/test/java/org/springframework/ldap/itest/core/LdapTemplateSearchResultITest.java +++ b/test/integration-tests-openldap/src/test/java/org/springframework/ldap/itest/core/LdapTemplateSearchResultITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,7 +35,7 @@ import javax.naming.Name; import javax.naming.directory.SearchControls; import java.util.List; -import static junit.framework.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Verifies that LdapTemplate search methods work against OpenLDAP with TLS. @@ -95,7 +95,7 @@ public class LdapTemplateSearchResultITest extends AbstractJUnit4SpringContextTe attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); attributesMapper.setExpectedValues(ALL_VALUES); List list = tested.search(BASE_STRING, FILTER_STRING, attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -103,7 +103,7 @@ public class LdapTemplateSearchResultITest extends AbstractJUnit4SpringContextTe attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); attributesMapper.setExpectedValues(ALL_VALUES); List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -113,7 +113,7 @@ public class LdapTemplateSearchResultITest extends AbstractJUnit4SpringContextTe attributesMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -121,7 +121,7 @@ public class LdapTemplateSearchResultITest extends AbstractJUnit4SpringContextTe attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); attributesMapper.setExpectedValues(ALL_VALUES); List list = tested.search(BASE_NAME, FILTER_STRING, attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -129,7 +129,7 @@ public class LdapTemplateSearchResultITest extends AbstractJUnit4SpringContextTe attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); attributesMapper.setExpectedValues(ALL_VALUES); List list = tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -139,7 +139,7 @@ public class LdapTemplateSearchResultITest extends AbstractJUnit4SpringContextTe attributesMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); List list = tested .search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -147,7 +147,7 @@ public class LdapTemplateSearchResultITest extends AbstractJUnit4SpringContextTe contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); contextMapper.setExpectedValues(ALL_VALUES); List list = tested.search(BASE_STRING, FILTER_STRING, contextMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -155,7 +155,7 @@ public class LdapTemplateSearchResultITest extends AbstractJUnit4SpringContextTe contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); contextMapper.setExpectedValues(ALL_VALUES); List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, contextMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -164,7 +164,7 @@ public class LdapTemplateSearchResultITest extends AbstractJUnit4SpringContextTe contextMapper.setExpectedValues(CN_SN_VALUES); contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, contextMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -172,7 +172,7 @@ public class LdapTemplateSearchResultITest extends AbstractJUnit4SpringContextTe contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); contextMapper.setExpectedValues(ALL_VALUES); List list = tested.search(BASE_NAME, FILTER_STRING, contextMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -180,7 +180,7 @@ public class LdapTemplateSearchResultITest extends AbstractJUnit4SpringContextTe contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); contextMapper.setExpectedValues(ALL_VALUES); List list = tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, contextMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -189,6 +189,6 @@ public class LdapTemplateSearchResultITest extends AbstractJUnit4SpringContextTe contextMapper.setExpectedValues(CN_SN_VALUES); contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); List list = tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, contextMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } } diff --git a/test/integration-tests-openldap/src/test/java/org/springframework/ldap/itest/core/support/DigestMd5AuthenticationITest.java b/test/integration-tests-openldap/src/test/java/org/springframework/ldap/itest/core/support/DigestMd5AuthenticationITest.java index ca4b6d6a..b649b655 100644 --- a/test/integration-tests-openldap/src/test/java/org/springframework/ldap/itest/core/support/DigestMd5AuthenticationITest.java +++ b/test/integration-tests-openldap/src/test/java/org/springframework/ldap/itest/core/support/DigestMd5AuthenticationITest.java @@ -1,12 +1,21 @@ /* - * Copyright 2010 The JA-SIG Collaborative. All rights reserved. See license - * distributed with this file and available online at - * http://www.ja-sig.org/products/cas/overview/license/index.html + * Copyright 2005-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.springframework.ldap.itest.core.support; import org.junit.After; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -21,6 +30,8 @@ import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; import javax.naming.directory.DirContext; +import static org.assertj.core.api.Assertions.assertThat; + /** * Integration test to verify DIGEST-MD5 authentication support. * @@ -51,6 +62,6 @@ public class DigestMd5AuthenticationITest extends AbstractJUnit4SpringContextTes @Test public void testAuthenticate() { DirContext ctxt = ldapTemplate.getContextSource().getContext("some.person1", "password"); - Assert.assertNotNull(ctxt); + assertThat(ctxt).isNotNull(); } } diff --git a/test/integration-tests-spring20/build.gradle b/test/integration-tests-spring20/build.gradle index c9f97476..1e566dbd 100644 --- a/test/integration-tests-spring20/build.gradle +++ b/test/integration-tests-spring20/build.gradle @@ -20,6 +20,7 @@ dependencies { "org.springframework:spring-core:$spring20Version", "org.springframework:spring-dao:$spring20Version", "org.springframework:spring-beans:$spring20Version", - "org.slf4j:slf4j-log4j12:$slf4jVersion" + "org.slf4j:slf4j-log4j12:$slf4jVersion", + "org.assertj:assertj-core:$assertjVersion" -} \ No newline at end of file +} diff --git a/test/integration-tests-spring20/src/test/java/org/springframework/ldap/itest20/LdapTemplateLookup20ITest.java b/test/integration-tests-spring20/src/test/java/org/springframework/ldap/itest20/LdapTemplateLookup20ITest.java index 48e5fdf7..1d5e5f6d 100644 --- a/test/integration-tests-spring20/src/test/java/org/springframework/ldap/itest20/LdapTemplateLookup20ITest.java +++ b/test/integration-tests-spring20/src/test/java/org/springframework/ldap/itest20/LdapTemplateLookup20ITest.java @@ -1,53 +1,55 @@ -/* - * Copyright 2005-2013 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.ldap.itest20; - -import org.springframework.ldap.core.DirContextOperations; -import org.springframework.ldap.core.LdapTemplate; -import org.springframework.test.AbstractDependencyInjectionSpringContextTests; - -/** - * Tests the lookup methods of LdapTemplate together with Spring 2.0. - * - * @author Mattias Hellborg Arthursson - */ -public class LdapTemplateLookup20ITest extends AbstractDependencyInjectionSpringContextTests { - - private LdapTemplate tested; - - public void setTested(LdapTemplate tested) { - this.tested = tested; - } - - @Override - protected String[] getConfigLocations() { - return new String[]{"/conf/ldapTemplateTestContext.xml"}; - } - - /** - * This method depends on a DirObjectFactory ( - * {@link org.springframework.ldap.core.support.DefaultDirObjectFactory}) - * being set in the ContextSource. - */ - public void testThatPlainLookupWorksWithSpring20() { - DirContextOperations result = tested.lookupContext("cn=Some Person2, ou=company1,c=Sweden"); - - assertEquals("Some Person2", result.getStringAttribute("cn")); - assertEquals("Person2", result.getStringAttribute("sn")); - assertEquals("Sweden, Company1, Some Person2", result.getStringAttribute("description")); - } -} +/* + * Copyright 2005-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.ldap.itest20; + +import org.springframework.ldap.core.DirContextOperations; +import org.springframework.ldap.core.LdapTemplate; +import org.springframework.test.AbstractDependencyInjectionSpringContextTests; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests the lookup methods of LdapTemplate together with Spring 2.0. + * + * @author Mattias Hellborg Arthursson + */ +public class LdapTemplateLookup20ITest extends AbstractDependencyInjectionSpringContextTests { + + private LdapTemplate tested; + + public void setTested(LdapTemplate tested) { + this.tested = tested; + } + + @Override + protected String[] getConfigLocations() { + return new String[]{"/conf/ldapTemplateTestContext.xml"}; + } + + /** + * This method depends on a DirObjectFactory ( + * {@link org.springframework.ldap.core.support.DefaultDirObjectFactory}) + * being set in the ContextSource. + */ + public void testThatPlainLookupWorksWithSpring20() { + DirContextOperations result = tested.lookupContext("cn=Some Person2, ou=company1,c=Sweden"); + + assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person2"); + assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); + assertThat(result.getStringAttribute("description")).isEqualTo("Sweden, Company1, Some Person2"); + } +} diff --git a/test/integration-tests-spring25/build.gradle b/test/integration-tests-spring25/build.gradle index 6660140a..6385fd56 100644 --- a/test/integration-tests-spring25/build.gradle +++ b/test/integration-tests-spring25/build.gradle @@ -30,6 +30,7 @@ dependencies { "org.springframework:spring-tx:$spring25Version", "org.springframework:spring-beans:$spring25Version", "junit:junit:$junitVersion", - "org.slf4j:slf4j-log4j12:$slf4jVersion" + "org.slf4j:slf4j-log4j12:$slf4jVersion", + "org.assertj:assertj-core:$assertjVersion" } diff --git a/test/integration-tests-spring25/src/test/java/org/springframework/ldap/itest25/LdapTemplateLookup25ITest.java b/test/integration-tests-spring25/src/test/java/org/springframework/ldap/itest25/LdapTemplateLookup25ITest.java index 5cfd21ce..85021480 100644 --- a/test/integration-tests-spring25/src/test/java/org/springframework/ldap/itest25/LdapTemplateLookup25ITest.java +++ b/test/integration-tests-spring25/src/test/java/org/springframework/ldap/itest25/LdapTemplateLookup25ITest.java @@ -1,65 +1,64 @@ -/* - * Copyright 2005-2013 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.ldap.itest25; - - -import org.junit.Test; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.ldap.core.DirContextOperations; -import org.springframework.ldap.core.LdapTemplate; - -import static junit.framework.Assert.assertEquals; - -/** - * Tests the lookup methods of LdapTemplate together with Spring 2.5. - * - * @author Mattias Hellborg Arthursson - */ -public class LdapTemplateLookup25ITest { - /** - * This method depends on a DirObjectFactory ( - * {@link org.springframework.ldap.core.support.DefaultDirObjectFactory}) - * being set in the ContextSource. - */ - @Test - public void testThatPlainLookupWorksWithSpring25() { - ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/conf/ldapTemplateTestContext.xml"); - LdapTemplate tested = (LdapTemplate) ctx.getBean("ldapTemplate"); - - performTestAndShutdownContext(ctx, tested); - } - - @Test - public void testThatNamespaceConfigurationWorksWithSpring25() { - ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/conf/ldapTemplateNamespaceTestContext.xml"); - LdapTemplate tested = (LdapTemplate) ctx.getBean("ldapTemplate"); - - performTestAndShutdownContext(ctx, tested); - } - - private void performTestAndShutdownContext(ClassPathXmlApplicationContext ctx, LdapTemplate tested) { - try { - DirContextOperations result = tested.lookupContext("cn=Some Person2, ou=company1,c=Sweden"); - - assertEquals("Some Person2", result.getStringAttribute("cn")); - assertEquals("Person2", result.getStringAttribute("sn")); - assertEquals("Sweden, Company1, Some Person2", result.getStringAttribute("description")); - } finally { - ctx.close(); - } - } -} +/* + * Copyright 2005-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.ldap.itest25; + +import org.junit.Test; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.ldap.core.DirContextOperations; +import org.springframework.ldap.core.LdapTemplate; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests the lookup methods of LdapTemplate together with Spring 2.5. + * + * @author Mattias Hellborg Arthursson + */ +public class LdapTemplateLookup25ITest { + /** + * This method depends on a DirObjectFactory ( + * {@link org.springframework.ldap.core.support.DefaultDirObjectFactory}) + * being set in the ContextSource. + */ + @Test + public void testThatPlainLookupWorksWithSpring25() { + ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/conf/ldapTemplateTestContext.xml"); + LdapTemplate tested = (LdapTemplate) ctx.getBean("ldapTemplate"); + + performTestAndShutdownContext(ctx, tested); + } + + @Test + public void testThatNamespaceConfigurationWorksWithSpring25() { + ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/conf/ldapTemplateNamespaceTestContext.xml"); + LdapTemplate tested = (LdapTemplate) ctx.getBean("ldapTemplate"); + + performTestAndShutdownContext(ctx, tested); + } + + private void performTestAndShutdownContext(ClassPathXmlApplicationContext ctx, LdapTemplate tested) { + try { + DirContextOperations result = tested.lookupContext("cn=Some Person2, ou=company1,c=Sweden"); + + assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person2"); + assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); + assertThat(result.getStringAttribute("description")).isEqualTo("Sweden, Company1, Some Person2"); + } finally { + ctx.close(); + } + } +} diff --git a/test/integration-tests-spring30/build.gradle b/test/integration-tests-spring30/build.gradle index d77ce27e..0e6de697 100644 --- a/test/integration-tests-spring30/build.gradle +++ b/test/integration-tests-spring30/build.gradle @@ -25,7 +25,8 @@ dependencies { "org.springframework:spring-tx:$spring30Version", "org.springframework:spring-beans:$spring30Version", "junit:junit:$junitVersion", - "org.slf4j:slf4j-log4j12:$slf4jVersion" + "org.slf4j:slf4j-log4j12:$slf4jVersion", + "org.assertj:assertj-core:$assertjVersion" testCompile("org.springframework.data:spring-data-commons:$springDataVersion") { exclude group: "org.springframework" diff --git a/test/integration-tests-spring30/src/test/java/org/springframework/ldap/itest30/LdapTemplateLookup30ITest.java b/test/integration-tests-spring30/src/test/java/org/springframework/ldap/itest30/LdapTemplateLookup30ITest.java index e1d2fad1..5b57f754 100644 --- a/test/integration-tests-spring30/src/test/java/org/springframework/ldap/itest30/LdapTemplateLookup30ITest.java +++ b/test/integration-tests-spring30/src/test/java/org/springframework/ldap/itest30/LdapTemplateLookup30ITest.java @@ -1,55 +1,54 @@ -/* - * Copyright 2005-2013 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.ldap.itest30; - - -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.ldap.core.DirContextOperations; -import org.springframework.ldap.core.LdapTemplate; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; - -import static junit.framework.Assert.assertEquals; - -/** - * Tests the lookup methods of LdapTemplate together with Spring 3.0. - * - * @author Mattias Hellborg Arthursson - */ -@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"}) -@DirtiesContext -public class LdapTemplateLookup30ITest extends AbstractJUnit4SpringContextTests { - - @Autowired - private LdapTemplate tested; - - /** - * This method depends on a DirObjectFactory ( - * {@link org.springframework.ldap.core.support.DefaultDirObjectFactory}) - * being set in the ContextSource. - */ - @Test - public void testThatPlainLookupWorksWithSpring30() { - DirContextOperations result = tested.lookupContext("cn=Some Person2, ou=company1,c=Sweden"); - - assertEquals("Some Person2", result.getStringAttribute("cn")); - assertEquals("Person2", result.getStringAttribute("sn")); - assertEquals("Sweden, Company1, Some Person2", result.getStringAttribute("description")); - } -} +/* + * Copyright 2005-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.ldap.itest30; + +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.ldap.core.DirContextOperations; +import org.springframework.ldap.core.LdapTemplate; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests the lookup methods of LdapTemplate together with Spring 3.0. + * + * @author Mattias Hellborg Arthursson + */ +@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"}) +@DirtiesContext +public class LdapTemplateLookup30ITest extends AbstractJUnit4SpringContextTests { + + @Autowired + private LdapTemplate tested; + + /** + * This method depends on a DirObjectFactory ( + * {@link org.springframework.ldap.core.support.DefaultDirObjectFactory}) + * being set in the ContextSource. + */ + @Test + public void testThatPlainLookupWorksWithSpring30() { + DirContextOperations result = tested.lookupContext("cn=Some Person2, ou=company1,c=Sweden"); + + assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person2"); + assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); + assertThat(result.getStringAttribute("description")).isEqualTo("Sweden, Company1, Some Person2"); + } +} diff --git a/test/integration-tests-spring30/src/test/java/org/springframework/ldap/itest30/LdapTemplateNamespaceLookup30ITest.java b/test/integration-tests-spring30/src/test/java/org/springframework/ldap/itest30/LdapTemplateNamespaceLookup30ITest.java index 6290cac9..7522c5f1 100644 --- a/test/integration-tests-spring30/src/test/java/org/springframework/ldap/itest30/LdapTemplateNamespaceLookup30ITest.java +++ b/test/integration-tests-spring30/src/test/java/org/springframework/ldap/itest30/LdapTemplateNamespaceLookup30ITest.java @@ -1,55 +1,54 @@ -/* - * Copyright 2005-2013 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.ldap.itest30; - - -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.ldap.core.DirContextOperations; -import org.springframework.ldap.core.LdapTemplate; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; - -import static junit.framework.Assert.assertEquals; - -/** - * Tests the lookup methods of LdapTemplate together with Spring 3.0. - * - * @author Mattias Hellborg Arthursson - */ -@ContextConfiguration(locations = {"/conf/ldapTemplateNamespaceTestContext.xml"}) -@DirtiesContext -public class LdapTemplateNamespaceLookup30ITest extends AbstractJUnit4SpringContextTests { - - @Autowired - private LdapTemplate tested; - - /** - * This method depends on a DirObjectFactory ( - * {@link org.springframework.ldap.core.support.DefaultDirObjectFactory}) - * being set in the ContextSource. - */ - @Test - public void testThatPlainLookupWorksWithSpring30() { - DirContextOperations result = tested.lookupContext("cn=Some Person2, ou=company1,c=Sweden"); - - assertEquals("Some Person2", result.getStringAttribute("cn")); - assertEquals("Person2", result.getStringAttribute("sn")); - assertEquals("Sweden, Company1, Some Person2", result.getStringAttribute("description")); - } -} +/* + * Copyright 2005-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.ldap.itest30; + +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.ldap.core.DirContextOperations; +import org.springframework.ldap.core.LdapTemplate; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests the lookup methods of LdapTemplate together with Spring 3.0. + * + * @author Mattias Hellborg Arthursson + */ +@ContextConfiguration(locations = {"/conf/ldapTemplateNamespaceTestContext.xml"}) +@DirtiesContext +public class LdapTemplateNamespaceLookup30ITest extends AbstractJUnit4SpringContextTests { + + @Autowired + private LdapTemplate tested; + + /** + * This method depends on a DirObjectFactory ( + * {@link org.springframework.ldap.core.support.DefaultDirObjectFactory}) + * being set in the ContextSource. + */ + @Test + public void testThatPlainLookupWorksWithSpring30() { + DirContextOperations result = tested.lookupContext("cn=Some Person2, ou=company1,c=Sweden"); + + assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person2"); + assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); + assertThat(result.getStringAttribute("description")).isEqualTo("Sweden, Company1, Some Person2"); + } +} diff --git a/test/integration-tests-sunone/build.gradle b/test/integration-tests-sunone/build.gradle index 9b859b4d..b48f6b59 100644 --- a/test/integration-tests-sunone/build.gradle +++ b/test/integration-tests-sunone/build.gradle @@ -14,7 +14,8 @@ dependencies { "org.springframework:spring-aop:$springVersion", "org.springframework:spring-aop:$springVersion", "gsbase:gsbase:$gsbaseVersion", - "org.slf4j:slf4j-log4j12:$slf4jVersion" + "org.slf4j:slf4j-log4j12:$slf4jVersion", + "org.assertj:assertj-core:$assertjVersion" } diff --git a/test/integration-tests-sunone/src/test/java/org/springframework/ldap/itest/core/LdapTemplateVirtualListViewSearchITest.java b/test/integration-tests-sunone/src/test/java/org/springframework/ldap/itest/core/LdapTemplateVirtualListViewSearchITest.java index 250537a8..e1d0abbd 100644 --- a/test/integration-tests-sunone/src/test/java/org/springframework/ldap/itest/core/LdapTemplateVirtualListViewSearchITest.java +++ b/test/integration-tests-sunone/src/test/java/org/springframework/ldap/itest/core/LdapTemplateVirtualListViewSearchITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,6 @@ */ package org.springframework.ldap.itest.core; -import static junit.framework.Assert.assertEquals; - import java.util.List; import javax.naming.directory.SearchControls; @@ -24,17 +22,20 @@ import javax.naming.directory.SearchControls; import org.junit.After; import org.junit.Before; import org.junit.Test; + import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.ldap.control.VirtualListViewControlDirContextProcessor; +import org.springframework.ldap.control.VirtualListViewResultsCookie; import org.springframework.ldap.core.CollectingNameClassPairCallbackHandler; import org.springframework.ldap.core.ContextMapperCallbackHandler; import org.springframework.ldap.core.LdapTemplate; import org.springframework.ldap.itest.Person; import org.springframework.ldap.itest.PersonContextMapper; -import org.springframework.ldap.control.VirtualListViewControlDirContextProcessor; -import org.springframework.ldap.control.VirtualListViewResultsCookie; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; +import static org.assertj.core.api.Assertions.assertThat; + /** * Integration tests for the virtual list view search result capability of * LdapTemplate. The test should reflect the example in Chapter 7 of the list = tested.list(BASE_STRING); - assertEquals(3, list.size()); + assertThat(list).hasSize(3); verifyBindings(list); } @@ -106,15 +105,15 @@ public class LdapTemplateListITest extends AbstractLdapTemplateIntegrationTest { transformed.add(LdapUtils.newLdapName(s)); } - assertTrue(transformed.contains(LdapUtils.newLdapName("ou=groups"))); - assertTrue(transformed.contains(LdapUtils.newLdapName("ou=Norway"))); - assertTrue(transformed.contains(LdapUtils.newLdapName("ou=Sweden"))); + assertThat(transformed.contains(LdapUtils.newLdapName("ou=groups"))).isTrue(); + assertThat(transformed.contains(LdapUtils.newLdapName("ou=Norway"))).isTrue(); + assertThat(transformed.contains(LdapUtils.newLdapName("ou=Sweden"))).isTrue(); } @Test public void testList_Name() { List list = tested.list(BASE_NAME); - assertEquals(3, list.size()); + assertThat(list).hasSize(3); verifyBindings(list); } @@ -122,40 +121,40 @@ public class LdapTemplateListITest extends AbstractLdapTemplateIntegrationTest { public void testList_Handler() throws Exception { CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler(); tested.list(BASE_STRING, handler); - assertEquals(3, handler.getNoOfRows()); + assertThat(handler.getNoOfRows()).isEqualTo(3); } @Test public void testList_Name_Handler() throws Exception { CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler(); tested.list(BASE_NAME, handler); - assertEquals(3, handler.getNoOfRows()); + assertThat(handler.getNoOfRows()).isEqualTo(3); } @Test public void testListBindings() { List list = tested.listBindings(BASE_STRING); - assertEquals(3, list.size()); + assertThat(list).hasSize(3); verifyBindings(list); } @Test public void testListBindings_Name() { List list = tested.listBindings(BASE_NAME); - assertEquals(3, list.size()); + assertThat(list).hasSize(3); } @Test public void testListBindings_Handler() throws Exception { CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler(); tested.listBindings(BASE_STRING, handler); - assertEquals(3, handler.getNoOfRows()); + assertThat(handler.getNoOfRows()).isEqualTo(3); } @Test public void testListBindings_Name_Handler() throws Exception { CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler(); tested.listBindings(BASE_NAME, handler); - assertEquals(3, handler.getNoOfRows()); + assertThat(handler.getNoOfRows()).isEqualTo(3); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateLookupITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateLookupITest.java index 1f63d41c..d9de7e32 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateLookupITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateLookupITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,8 +29,7 @@ import javax.naming.NamingException; import javax.naming.directory.Attributes; import javax.naming.ldap.LdapName; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNull; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests the lookup methods of LdapTemplate. @@ -53,9 +52,9 @@ public class LdapTemplateLookupITest extends AbstractLdapTemplateIntegrationTest public void testLookup_Plain() { DirContextAdapter result = (DirContextAdapter) tested.lookup("cn=Some Person2, ou=company1,ou=Sweden"); - assertEquals("Some Person2", result.getStringAttribute("cn")); - assertEquals("Person2", result.getStringAttribute("sn")); - assertEquals("Sweden, Company1, Some Person2", result.getStringAttribute("description")); + assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person2"); + assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); + assertThat(result.getStringAttribute("description")).isEqualTo("Sweden, Company1, Some Person2"); } /** @@ -67,8 +66,8 @@ public class LdapTemplateLookupITest extends AbstractLdapTemplateIntegrationTest public void testLookupContextRoot() { DirContextAdapter result = (DirContextAdapter) tested.lookup(""); - assertEquals("", result.getDn().toString()); - assertEquals(base, result.getNameInNamespace()); + assertThat(result.getDn().toString()).isEqualTo(""); + assertThat(result.getNameInNamespace()).isEqualTo(base); } @Test @@ -76,9 +75,9 @@ public class LdapTemplateLookupITest extends AbstractLdapTemplateIntegrationTest AttributesMapper mapper = new PersonAttributesMapper(); Person person = (Person) tested.lookup("cn=Some Person2, ou=company1,ou=Sweden", mapper); - assertEquals("Some Person2", person.getFullname()); - assertEquals("Person2", person.getLastname()); - assertEquals("Sweden, Company1, Some Person2", person.getDescription()); + assertThat(person.getFullname()).isEqualTo("Some Person2"); + assertThat(person.getLastname()).isEqualTo("Person2"); + assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2"); } @Test @@ -86,9 +85,9 @@ public class LdapTemplateLookupITest extends AbstractLdapTemplateIntegrationTest AttributesMapper mapper = new PersonAttributesMapper(); Person person = (Person) tested.lookup(LdapUtils.newLdapName("cn=Some Person2, ou=company1,ou=Sweden"), mapper); - assertEquals("Some Person2", person.getFullname()); - assertEquals("Person2", person.getLastname()); - assertEquals("Sweden, Company1, Some Person2", person.getDescription()); + assertThat(person.getFullname()).isEqualTo("Some Person2"); + assertThat(person.getLastname()).isEqualTo("Person2"); + assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2"); } /** @@ -108,8 +107,8 @@ public class LdapTemplateLookupITest extends AbstractLdapTemplateIntegrationTest public Object mapFromAttributes(Attributes attributes) throws NamingException { Person person = new Person(); person.setFullname((String) attributes.get("cn").get()); - assertNull("sn should be null", attributes.get("sn")); - assertNull("description should be null", attributes.get("description")); + assertThat(attributes.get("sn")).as("sn should be null").isNull(); + assertThat(attributes.get("description")).as("description should be null").isNull(); return person; } } @@ -124,9 +123,9 @@ public class LdapTemplateLookupITest extends AbstractLdapTemplateIntegrationTest Person person = (Person) tested.lookup("cn=Some Person2, ou=company1,ou=Sweden", new String[] { "cn" }, mapper); - assertEquals("Some Person2", person.getFullname()); - assertNull("lastName should not be set", person.getLastname()); - assertNull("description should not be set", person.getDescription()); + assertThat(person.getFullname()).isEqualTo("Some Person2"); + assertThat(person.getLastname()).as("lastName should not be set").isNull(); + assertThat(person.getDescription()).as("description should not be set").isNull(); } /** @@ -140,9 +139,9 @@ public class LdapTemplateLookupITest extends AbstractLdapTemplateIntegrationTest Person person = (Person) tested.lookup(LdapUtils.newLdapName("cn=Some Person2, ou=company1,ou=Sweden"), new String[] { "cn" }, mapper); - assertEquals("Some Person2", person.getFullname()); - assertNull("lastName should not be set", person.getLastname()); - assertNull("description should not be set", person.getDescription()); + assertThat(person.getFullname()).isEqualTo("Some Person2"); + assertThat(person.getLastname()).as("lastName should not be set").isNull(); + assertThat(person.getDescription()).as("description should not be set").isNull(); } /** @@ -155,9 +154,9 @@ public class LdapTemplateLookupITest extends AbstractLdapTemplateIntegrationTest ContextMapper mapper = new PersonContextMapper(); Person person = (Person) tested.lookup("cn=Some Person2, ou=company1,ou=Sweden", mapper); - assertEquals("Some Person2", person.getFullname()); - assertEquals("Person2", person.getLastname()); - assertEquals("Sweden, Company1, Some Person2", person.getDescription()); + assertThat(person.getFullname()).isEqualTo("Some Person2"); + assertThat(person.getLastname()).isEqualTo("Person2"); + assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2"); } /** @@ -170,9 +169,9 @@ public class LdapTemplateLookupITest extends AbstractLdapTemplateIntegrationTest Person person = (Person) tested.lookup("cn=Some Person2, ou=company1,ou=Sweden", new String[] { "cn" }, mapper); - assertEquals("Some Person2", person.getFullname()); - assertNull("lastName should not be set", person.getLastname()); - assertNull("description should not be set", person.getDescription()); + assertThat(person.getFullname()).isEqualTo("Some Person2"); + assertThat(person.getLastname()).as("lastName should not be set").isNull(); + assertThat(person.getDescription()).as("description should not be set").isNull(); } @Test @@ -181,7 +180,7 @@ public class LdapTemplateLookupITest extends AbstractLdapTemplateIntegrationTest DirContextAdapter result = (DirContextAdapter) tested.lookup(expectedDn); LdapName expectedName = LdapUtils.newLdapName(expectedDn); - assertEquals(expectedName, result.getDn()); - assertEquals("cn=Some Person2,ou=company1,ou=Sweden," + base, result.getNameInNamespace()); + assertThat(result.getDn()).isEqualTo(expectedName); + assertThat(result.getNameInNamespace()).isEqualTo("cn=Some Person2,ou=company1,ou=Sweden," + base); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateLookupMultiRdnITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateLookupMultiRdnITest.java index bfc5a8e5..205451f8 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateLookupMultiRdnITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateLookupMultiRdnITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ import org.springframework.ldap.core.DirContextAdapter; import org.springframework.ldap.core.LdapTemplate; import org.springframework.test.context.ContextConfiguration; -import static junit.framework.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests the lookup methods of LdapTemplate. @@ -55,9 +55,9 @@ public class LdapTemplateLookupMultiRdnITest extends AbstractLdapTemplateIntegra AttributesMapper mapper = new PersonAttributesMapper(); Person person = (Person) tested.lookup("cn=Some Person+sn=Person, ou=company1,ou=Norway", mapper); - assertEquals("Some Person", person.getFullname()); - assertEquals("Person", person.getLastname()); - assertEquals("Norway, Company1, Some Person+Person", person.getDescription()); + assertThat(person.getFullname()).isEqualTo("Some Person"); + assertThat(person.getLastname()).isEqualTo("Person"); + assertThat(person.getDescription()).isEqualTo("Norway, Company1, Some Person+Person"); } /** @@ -70,9 +70,9 @@ public class LdapTemplateLookupMultiRdnITest extends AbstractLdapTemplateIntegra public void testLookup_MultiValuedRdn_DirContextAdapter() { DirContextAdapter result = (DirContextAdapter) tested.lookup("cn=Some Person+sn=Person, ou=company1,ou=Norway"); - assertEquals("Some Person", result.getStringAttribute("cn")); - assertEquals("Person", result.getStringAttribute("sn")); - assertEquals("Norway, Company1, Some Person+Person", result.getStringAttribute("description")); + assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person"); + assertThat(result.getStringAttribute("sn")).isEqualTo("Person"); + assertThat(result.getStringAttribute("description")).isEqualTo("Norway, Company1, Some Person+Person"); } @Test @@ -80,7 +80,7 @@ public class LdapTemplateLookupMultiRdnITest extends AbstractLdapTemplateIntegra public void testLookup_GetNameInNamespace_MultiRdn() { DirContextAdapter result = (DirContextAdapter) tested.lookup("cn=Some Person+sn=Person,ou=company1,ou=Norway"); - assertEquals("cn=Some Person+sn=Person,ou=company1,ou=Norway", result.getDn().toString()); - assertEquals("cn=Some Person+sn=Person,ou=company1,ou=Norway," + base, result.getNameInNamespace()); + assertThat(result.getDn().toString()).isEqualTo("cn=Some Person+sn=Person,ou=company1,ou=Norway"); + assertThat(result.getNameInNamespace()).isEqualTo("cn=Some Person+sn=Person,ou=company1,ou=Norway," + base); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateModifyITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateModifyITest.java index c55e892b..3e75f436 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateModifyITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateModifyITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,9 +35,8 @@ import javax.naming.directory.ModificationItem; import java.util.Arrays; import java.util.List; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertTrue; -import static junit.framework.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Tests the modification methods (rebind and modifyAttributes) of LdapTemplate. @@ -117,9 +116,9 @@ public class LdapTemplateModifyITest extends AbstractLdapTemplateIntegrationTest DirContextAdapter result = (DirContextAdapter) tested.lookup(PERSON4_DN); List attributes = Arrays.asList(result.getStringAttributes("description")); - assertEquals(2, attributes.size()); - assertTrue(attributes.contains("Some other description")); - assertTrue(attributes.contains("Another description")); + assertThat(attributes).hasSize(2); + assertThat(attributes.contains("Some other description")).isTrue(); + assertThat(attributes.contains("Another description")).isTrue(); } @Test @@ -133,10 +132,10 @@ public class LdapTemplateModifyITest extends AbstractLdapTemplateIntegrationTest DirContextAdapter result = (DirContextAdapter) tested.lookup(PERSON4_DN); List attributes = Arrays.asList(result.getStringAttributes("description")); - assertEquals(3, attributes.size()); - assertTrue(attributes.contains("Some other description")); - assertTrue(attributes.contains("Another description")); - assertTrue(attributes.contains("Some description")); + assertThat(attributes).hasSize(3); + assertThat(attributes.contains("Some other description")).isTrue(); + assertThat(attributes.contains("Another description")).isTrue(); + assertThat(attributes.contains("Some description")).isTrue(); } @Test @@ -144,7 +143,7 @@ public class LdapTemplateModifyITest extends AbstractLdapTemplateIntegrationTest DirContextOperations ctx = tested.lookupContext("cn=ROLE_USER,ou=groups"); ctx.addAttributeValue("uniqueMember", "cn=Some Person,ou=company1,ou=Norway," + base); tested.modifyAttributes(ctx); - assertTrue(true); + assertThat(true).isTrue(); } @Test @@ -180,10 +179,10 @@ public class LdapTemplateModifyITest extends AbstractLdapTemplateIntegrationTest DirContextAdapter result = (DirContextAdapter) tested.lookup(PERSON4_DN); List attributes = Arrays.asList(result.getStringAttributes("description")); - assertEquals(3, attributes.size()); - assertTrue(attributes.contains("Some other description")); - assertTrue(attributes.contains("Another description")); - assertTrue(attributes.contains("Some description")); + assertThat(attributes).hasSize(3); + assertThat(attributes.contains("Some other description")).isTrue(); + assertThat(attributes.contains("Another description")).isTrue(); + assertThat(attributes.contains("Some description")).isTrue(); } @Test @@ -216,11 +215,11 @@ public class LdapTemplateModifyITest extends AbstractLdapTemplateIntegrationTest // Verify adapter = (DirContextAdapter) tested.lookup(PERSON5_DN); List attributes = Arrays.asList(adapter.getStringAttributes("description")); - assertEquals(4, attributes.size()); - assertTrue(attributes.contains("qwe")); - assertTrue(attributes.contains("123")); - assertTrue(attributes.contains("klytt")); - assertTrue(attributes.contains("kalle")); + assertThat(attributes).hasSize(4); + assertThat(attributes.contains("qwe")).isTrue(); + assertThat(attributes.contains("123")).isTrue(); + assertThat(attributes.contains("klytt")).isTrue(); + assertThat(attributes.contains("kalle")).isTrue(); } /** @@ -278,8 +277,8 @@ public class LdapTemplateModifyITest extends AbstractLdapTemplateIntegrationTest private void verifyBoundCorrectData() { DirContextAdapter result = (DirContextAdapter) tested.lookup(PERSON4_DN); - assertEquals("Some Person4", result.getStringAttribute("cn")); - assertEquals("Person4", result.getStringAttribute("sn")); - assertEquals("Some other description", result.getStringAttribute("description")); + assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person4"); + assertThat(result.getStringAttribute("sn")).isEqualTo("Person4"); + assertThat(result.getStringAttribute("description")).isEqualTo("Some other description"); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateNoBaseSuffixITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateNoBaseSuffixITest.java index f75d33fd..2fc45370 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateNoBaseSuffixITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateNoBaseSuffixITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,9 +28,8 @@ import org.springframework.test.context.ContextConfiguration; import javax.naming.Name; import javax.naming.ldap.LdapName; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertTrue; -import static junit.framework.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Tests to verify that not setting a base suffix on the ContextSource (as @@ -60,13 +59,13 @@ public class LdapTemplateNoBaseSuffixITest extends AbstractLdapTemplateIntegrati String expectedDn = "cn=Some Person2, ou=company1, ou=Sweden," + base; DirContextAdapter result = (DirContextAdapter) tested.lookup(expectedDn); - assertEquals("Some Person2", result.getStringAttribute("cn")); - assertEquals("Person2", result.getStringAttribute("sn")); - assertEquals("Sweden, Company1, Some Person2", result.getStringAttribute("description")); + assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person2"); + assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); + assertThat(result.getStringAttribute("description")).isEqualTo("Sweden, Company1, Some Person2"); LdapName expectedName = LdapUtils.newLdapName(expectedDn); - assertEquals(expectedName, result.getDn()); - assertEquals(expectedDn, result.getNameInNamespace()); + assertThat(result.getDn()).isEqualTo(expectedName); + assertThat(result.getNameInNamespace()).isEqualTo(expectedDn); } @Test @@ -74,7 +73,7 @@ public class LdapTemplateNoBaseSuffixITest extends AbstractLdapTemplateIntegrati CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler(); tested.search(base, "(objectclass=person)", handler); - assertEquals(5, handler.getNoOfRows()); + assertThat(handler.getNoOfRows()).isEqualTo(5); } @Test @@ -88,9 +87,9 @@ public class LdapTemplateNoBaseSuffixITest extends AbstractLdapTemplateIntegrati DirContextAdapter result = (DirContextAdapter) tested .lookup("cn=Some Person4, ou=company1, ou=Sweden," + base); - assertEquals("Some Person4", result.getStringAttribute("cn")); - assertEquals("Person4", result.getStringAttribute("sn")); - assertEquals(LdapUtils.newLdapName("cn=Some Person4,ou=company1,ou=Sweden," + base), result.getDn()); + assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person4"); + assertThat(result.getStringAttribute("sn")).isEqualTo("Person4"); + assertThat(result.getDn()).isEqualTo(LdapUtils.newLdapName("cn=Some Person4,ou=company1,ou=Sweden," + base)); tested.unbind("cn=Some Person4,ou=company1,ou=Sweden," + base); try { @@ -98,7 +97,7 @@ public class LdapTemplateNoBaseSuffixITest extends AbstractLdapTemplateIntegrati fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplatePooledITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplatePooledITest.java index a1cd848a..9f0b1da8 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplatePooledITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplatePooledITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,9 +29,8 @@ import org.springframework.ldap.test.LdapTestUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertTrue; -import static junit.framework.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * This test only works against in-process Apache DS server, regardless of configured profile. @@ -64,9 +63,9 @@ public class LdapTemplatePooledITest extends AbstractJUnit4SpringContextTests { LdapTestUtils.cleanAndSetup(contextSource, LdapUtils.emptyLdapName(), new ClassPathResource("/setup_data.ldif")); DirContextOperations result = tested.lookupContext("cn=Some Person2, ou=company1,ou=Sweden"); - assertEquals("Some Person2", result.getStringAttribute("cn")); - assertEquals("Person2", result.getStringAttribute("sn")); - assertEquals("Sweden, Company1, Some Person2", result.getStringAttribute("description")); + assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person2"); + assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); + assertThat(result.getStringAttribute("description")).isEqualTo("Sweden, Company1, Some Person2"); // Shutdown server and kill all existing connections LdapTestUtils.shutdownEmbeddedServer(); @@ -77,7 +76,7 @@ public class LdapTemplatePooledITest extends AbstractJUnit4SpringContextTests { fail("Exception expected"); } catch (Exception expected) { // This should fail because the target connection was closed - assertTrue(true); + assertThat(true).isTrue(); } LdapTestUtils.cleanAndSetup(contextSource, LdapUtils.emptyLdapName(), new ClassPathResource("/setup_data.ldif")); diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateRenameITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateRenameITest.java index 7e814bd2..4d27f2cf 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateRenameITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateRenameITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,8 @@ import org.springframework.test.context.ContextConfiguration; import javax.naming.Name; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Tests the rename methods of LdapTemplate. @@ -96,8 +96,8 @@ public class LdapTemplateRenameITest extends AbstractLdapTemplateIntegrationTest private void verifyBoundCorrectData() { DirContextAdapter result = (DirContextAdapter) tested.lookup(NEWDN); - assertEquals("Some Person6", result.getStringAttribute("cn")); - assertEquals("Person6", result.getStringAttribute("sn")); - assertEquals("Some description", result.getStringAttribute("description")); + assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person6"); + assertThat(result.getStringAttribute("sn")).isEqualTo("Person6"); + assertThat(result.getStringAttribute("description")).isEqualTo("Some description"); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateSearchResultITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateSearchResultITest.java index 7a176572..347144a7 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateSearchResultITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateSearchResultITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,10 +41,8 @@ import javax.naming.NamingException; import javax.naming.directory.SearchControls; import java.util.List; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertTrue; -import static junit.framework.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.springframework.ldap.query.LdapQueryBuilder.query; /** @@ -99,7 +97,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); attributesMapper.setExpectedValues(ALL_VALUES); List list = tested.search(BASE_STRING, FILTER_STRING, attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -111,7 +109,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati .base(BASE_STRING) .where("objectclass").is("person").and("sn").is("Person2"), attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -124,7 +122,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati .attributes("cn") .where("objectclass").is("person").and("sn").is("Person2"), attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -137,7 +135,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati .searchScope(SearchScope.ONELEVEL) .where("objectclass").is("person").and("sn").is("Person2"), attributesMapper); - assertEquals(0, list.size()); + assertThat(list).isEmpty(); } @Test @@ -150,7 +148,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati .searchScope(SearchScope.ONELEVEL) .where("objectclass").is("person").and("sn").is("Person2"), attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -161,7 +159,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati List list = tested.search(query() .where("objectclass").is("person").and("sn").is("Person2"), attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -173,7 +171,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati .base("ou=Norway") .where("objectclass").is("person").and("sn").is("Person2"), attributesMapper); - assertEquals(0, list.size()); + assertThat(list).isEmpty(); } @Test @@ -181,7 +179,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); attributesMapper.setExpectedValues(ALL_VALUES); List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -191,7 +189,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati attributesMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -199,7 +197,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); attributesMapper.setExpectedValues(ALL_VALUES); List list = tested.search(BASE_NAME, FILTER_STRING, attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -207,7 +205,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); attributesMapper.setExpectedValues(ALL_VALUES); List list = tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -217,7 +215,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati attributesMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); List list = tested .search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -225,7 +223,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); contextMapper.setExpectedValues(ALL_VALUES); List list = tested.search(BASE_STRING, FILTER_STRING, contextMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -234,7 +232,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati contextMapper.setExpectedValues(ALL_VALUES); DirContextAdapter result = (DirContextAdapter) tested .searchForObject(BASE_STRING, FILTER_STRING, contextMapper); - assertNotNull(result); + assertThat(result).isNotNull(); } @Test(expected = IncorrectResultSizeDataAccessException.class) @@ -262,7 +260,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); contextMapper.setExpectedValues(ALL_VALUES); List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, contextMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -271,7 +269,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati contextMapper.setExpectedValues(CN_SN_VALUES); contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, contextMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -279,7 +277,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); contextMapper.setExpectedValues(ALL_VALUES); List list = tested.search(BASE_NAME, FILTER_STRING, contextMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -290,7 +288,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati .base(BASE_NAME) .where("objectclass").is("person").and("sn").is("Person2"), contextMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -300,7 +298,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati List list = tested.search(query() .where("objectclass").is("person").and("sn").is("Person2"), contextMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -312,7 +310,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati .searchScope(SearchScope.ONELEVEL) .where("objectclass").is("person").and("sn").is("Person2"), contextMapper); - assertEquals(0, list.size()); + assertThat(list).isEmpty(); } @Test @@ -324,7 +322,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati .searchScope(SearchScope.ONELEVEL) .where("objectclass").is("person").and("sn").is("Person2"), contextMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -332,8 +330,8 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati DirContextOperations result = tested.searchForContext(query() .where("objectclass").is("person").and("sn").is("Person2")); - assertNotNull(result); - assertEquals("Person2", result.getStringAttribute("sn")); + assertThat(result).isNotNull(); + assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); } @Test(expected = EmptyResultDataAccessException.class) @@ -351,8 +349,8 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati .base("ou=company1,ou=Sweden") .where("objectclass").is("person").and("sn").is("Person2")); - assertNotNull(result); - assertEquals("Person2", result.getStringAttribute("sn")); + assertThat(result).isNotNull(); + assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); } @Test @@ -360,7 +358,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); contextMapper.setExpectedValues(ALL_VALUES); List list = tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, contextMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -369,7 +367,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati contextMapper.setExpectedValues(CN_SN_VALUES); contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); List list = tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, contextMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -380,7 +378,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @@ -392,7 +390,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); List list = tested.search(BASE_NAME + "ou=unknown", FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, contextMapper); - assertEquals(0, list.size()); + assertThat(list).isEmpty(); } @Test @@ -406,7 +404,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati } }); - assertEquals(3, result.size()); + assertThat(result).hasSize(3); } @Test(expected = SizeLimitExceededException.class) diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateSearchResultNamespaceConfigITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateSearchResultNamespaceConfigITest.java index 3ab4424a..34bda824 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateSearchResultNamespaceConfigITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateSearchResultNamespaceConfigITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,10 +38,8 @@ import javax.naming.Name; import javax.naming.directory.SearchControls; import java.util.List; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertTrue; -import static junit.framework.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.springframework.ldap.query.LdapQueryBuilder.query; /** @@ -96,7 +94,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); attributesMapper.setExpectedValues(ALL_VALUES); List list = tested.search(BASE_STRING, FILTER_STRING, attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -108,7 +106,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe .base(BASE_STRING) .where("objectclass").is("person").and("sn").is("Person2"), attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -121,7 +119,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe .attributes("cn") .where("objectclass").is("person").and("sn").is("Person2"), attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -134,7 +132,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe .searchScope(SearchScope.ONELEVEL) .where("objectclass").is("person").and("sn").is("Person2"), attributesMapper); - assertEquals(0, list.size()); + assertThat(list).isEmpty(); } @Test @@ -147,7 +145,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe .searchScope(SearchScope.ONELEVEL) .where("objectclass").is("person").and("sn").is("Person2"), attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -158,7 +156,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe List list = tested.search(query() .where("objectclass").is("person").and("sn").is("Person2"), attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -170,7 +168,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe .base("ou=Norway") .where("objectclass").is("person").and("sn").is("Person2"), attributesMapper); - assertEquals(0, list.size()); + assertThat(list).isEmpty(); } @Test @@ -178,7 +176,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); attributesMapper.setExpectedValues(ALL_VALUES); List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -188,7 +186,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe attributesMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -196,7 +194,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); attributesMapper.setExpectedValues(ALL_VALUES); List list = tested.search(BASE_NAME, FILTER_STRING, attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -204,7 +202,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); attributesMapper.setExpectedValues(ALL_VALUES); List list = tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -214,7 +212,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe attributesMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); List list = tested .search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, attributesMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -222,7 +220,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); contextMapper.setExpectedValues(ALL_VALUES); List list = tested.search(BASE_STRING, FILTER_STRING, contextMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -231,7 +229,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe contextMapper.setExpectedValues(ALL_VALUES); DirContextAdapter result = (DirContextAdapter) tested .searchForObject(BASE_STRING, FILTER_STRING, contextMapper); - assertNotNull(result); + assertThat(result).isNotNull(); } @Test(expected = IncorrectResultSizeDataAccessException.class) @@ -259,7 +257,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); contextMapper.setExpectedValues(ALL_VALUES); List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, contextMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -268,7 +266,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe contextMapper.setExpectedValues(CN_SN_VALUES); contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, contextMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -276,7 +274,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); contextMapper.setExpectedValues(ALL_VALUES); List list = tested.search(BASE_NAME, FILTER_STRING, contextMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -287,7 +285,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe .base(BASE_NAME) .where("objectclass").is("person").and("sn").is("Person2"), contextMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -297,7 +295,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe List list = tested.search(query() .where("objectclass").is("person").and("sn").is("Person2"), contextMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -309,7 +307,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe .searchScope(SearchScope.ONELEVEL) .where("objectclass").is("person").and("sn").is("Person2"), contextMapper); - assertEquals(0, list.size()); + assertThat(list).isEmpty(); } @Test @@ -321,7 +319,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe .searchScope(SearchScope.ONELEVEL) .where("objectclass").is("person").and("sn").is("Person2"), contextMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -329,8 +327,8 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe DirContextOperations result = tested.searchForContext(query() .where("objectclass").is("person").and("sn").is("Person2")); - assertNotNull(result); - assertEquals("Person2", result.getStringAttribute("sn")); + assertThat(result).isNotNull(); + assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); } @Test(expected = EmptyResultDataAccessException.class) @@ -348,8 +346,8 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe .base("ou=company1,ou=Sweden") .where("objectclass").is("person").and("sn").is("Person2")); - assertNotNull(result); - assertEquals("Person2", result.getStringAttribute("sn")); + assertThat(result).isNotNull(); + assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); } @Test @@ -357,7 +355,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); contextMapper.setExpectedValues(ALL_VALUES); List list = tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, contextMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -366,7 +364,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe contextMapper.setExpectedValues(CN_SN_VALUES); contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); List list = tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, contextMapper); - assertEquals(1, list.size()); + assertThat(list).hasSize(1); } @Test @@ -377,7 +375,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @@ -389,6 +387,6 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); List list = tested.search(BASE_NAME + "ou=unknown", FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, contextMapper); - assertEquals(0, list.size()); + assertThat(list).isEmpty(); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/control/SupportedControlsITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/control/SupportedControlsITest.java index b6db9c41..f4373fc3 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/control/SupportedControlsITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/control/SupportedControlsITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,7 @@ import javax.naming.Name; import java.util.Arrays; import java.util.HashSet; -import static junit.framework.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Provides tests that verify that the server supports certain controls. @@ -71,8 +71,8 @@ public class SupportedControlsITest extends AbstractLdapTemplateIntegrationTest HashSet controlsSet = new HashSet(Arrays.asList(controls)); - assertTrue("Entry Change Notification LDAPv3 control,", controlsSet.contains("1.3.6.1.4.1.4203.1.10.1")); - assertTrue("Subentries Control,", controlsSet.contains("1.3.6.1.4.1.4203.1.10.1")); - assertTrue("Manage DSA IT LDAPv3 control,", controlsSet.contains("2.16.840.1.113730.3.4.2")); + assertThat(controlsSet.contains("1.3.6.1.4.1.4203.1.10.1")).as("Entry Change Notification LDAPv3 control,").isTrue(); + assertThat(controlsSet.contains("1.3.6.1.4.1.4203.1.10.1")).as("Subentries Control,").isTrue(); + assertThat(controlsSet.contains("2.16.840.1.113730.3.4.2")).as("Manage DSA IT LDAPv3 control,").isTrue(); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/DistinguishedNameEditorITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/DistinguishedNameEditorITest.java index 58c62654..f2f6f3bf 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/DistinguishedNameEditorITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/DistinguishedNameEditorITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,7 @@ import org.springframework.ldap.core.DistinguishedName; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; /** * Integration tests for {@link org.springframework.ldap.core.DistinguishedNameEditor}. @@ -37,8 +36,8 @@ public class DistinguishedNameEditorITest extends AbstractJUnit4SpringContextTes @Test public void testDistinguishedNameEditor() throws Exception { - assertNotNull(distinguishedNameConsumer); + assertThat(distinguishedNameConsumer).isNotNull(); DistinguishedName name = distinguishedNameConsumer.getDistinguishedName(); - assertEquals(new DistinguishedName("dc=jayway, dc=se"), name); + assertThat(name).isEqualTo(new DistinguishedName("dc=jayway, dc=se")); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/simple/SimpleLdapTemplateITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/simple/SimpleLdapTemplateITest.java index 51643fc3..d47d6191 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/simple/SimpleLdapTemplateITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/simple/SimpleLdapTemplateITest.java @@ -37,9 +37,8 @@ import javax.naming.directory.SearchControls; import javax.naming.ldap.LdapName; import java.util.List; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertTrue; -import static junit.framework.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; @ContextConfiguration(locations = {"/conf/simpleLdapTemplateTestContext.xml"}) public class SimpleLdapTemplateITest extends AbstractLdapTemplateIntegrationTest { @@ -53,28 +52,28 @@ public class SimpleLdapTemplateITest extends AbstractLdapTemplateIntegrationTest @Test public void testLookup() { String result = ldapTemplate.lookup("cn=Some Person,ou=company1,ou=Sweden", new CnContextMapper()); - assertEquals("Some Person", result); + assertThat(result).isEqualTo("Some Person"); } @Test public void testLookupName() { String result = ldapTemplate.lookup(LdapUtils.newLdapName("cn=Some Person,ou=company1,ou=Sweden"), new CnContextMapper()); - assertEquals("Some Person", result); + assertThat(result).isEqualTo("Some Person"); } @Test public void testSearch() { List cns = ldapTemplate.search("", "(&(objectclass=person)(sn=Person3))", new CnContextMapper()); - assertEquals(1, cns.size()); - assertEquals("Some Person3", cns.get(0)); + assertThat(cns).hasSize(1); + assertThat(cns.get(0)).isEqualTo("Some Person3"); } @Test public void testSearchForObject() { String cn = ldapTemplate.searchForObject("", "(&(objectclass=person)(sn=Person3))", new CnContextMapper()); - assertEquals("Some Person3", cn); + assertThat(cn).isEqualTo("Some Person3"); } @Test @@ -86,10 +85,10 @@ public class SimpleLdapTemplateITest extends AbstractLdapTemplateIntegrationTest List cns = ldapTemplate.search("", "(&(objectclass=person)(sn=Person3))", searchControls, new CnContextMapper(), processor); - assertEquals(1, cns.size()); - assertEquals("Some Person3", cns.get(0)); - assertTrue(processor.isPreProcessCalled()); - assertTrue(processor.isPostProcessCalled()); + assertThat(cns).hasSize(1); + assertThat(cns.get(0)).isEqualTo("Some Person3"); + assertThat(processor.isPreProcessCalled()).isTrue(); + assertThat(processor.isPostProcessCalled()).isTrue(); } @Test @@ -101,10 +100,10 @@ public class SimpleLdapTemplateITest extends AbstractLdapTemplateIntegrationTest List cns = ldapTemplate.search(LdapUtils.emptyLdapName(), "(&(objectclass=person)(sn=Person3))", searchControls, new CnContextMapper(), processor); - assertEquals(1, cns.size()); - assertEquals("Some Person3", cns.get(0)); - assertTrue(processor.isPreProcessCalled()); - assertTrue(processor.isPostProcessCalled()); + assertThat(cns).hasSize(1); + assertThat(cns.get(0)).isEqualTo("Some Person3"); + assertThat(processor.isPreProcessCalled()).isTrue(); + assertThat(processor.isPostProcessCalled()).isTrue(); } @Test @@ -112,8 +111,8 @@ public class SimpleLdapTemplateITest extends AbstractLdapTemplateIntegrationTest List cns = ldapTemplate.search(LdapUtils.emptyLdapName(), "(&(objectclass=person)(sn=Person3))", new CnContextMapper()); - assertEquals(1, cns.size()); - assertEquals("Some Person3", cns.get(0)); + assertThat(cns).hasSize(1); + assertThat(cns.get(0)).isEqualTo("Some Person3"); } @Test @@ -129,8 +128,8 @@ public class SimpleLdapTemplateITest extends AbstractLdapTemplateIntegrationTest ldapTemplate.lookup("cn=Some Person,ou=company1,ou=Sweden", new ParameterizedContextMapper() { public Object mapFromContext(Object ctx) { DirContextAdapter adapter = (DirContextAdapter) ctx; - assertEquals("updated description", adapter.getStringAttribute("description")); - assertEquals("0000001", adapter.getStringAttribute("telephoneNumber")); + assertThat(adapter.getStringAttribute("description")).isEqualTo("updated description"); + assertThat(adapter.getStringAttribute("telephoneNumber")).isEqualTo("0000001"); return null; } }); @@ -150,8 +149,8 @@ public class SimpleLdapTemplateITest extends AbstractLdapTemplateIntegrationTest ldapTemplate.lookup("cn=Some Person,ou=company1,ou=Sweden", new ParameterizedContextMapper() { public Object mapFromContext(Object ctx) { DirContextAdapter adapter = (DirContextAdapter) ctx; - assertEquals("updated description", adapter.getStringAttribute("description")); - assertEquals("0000001", adapter.getStringAttribute("telephoneNumber")); + assertThat(adapter.getStringAttribute("description")).isEqualTo("updated description"); + assertThat(adapter.getStringAttribute("telephoneNumber")).isEqualTo("0000001"); return null; } }); @@ -201,13 +200,13 @@ public class SimpleLdapTemplateITest extends AbstractLdapTemplateIntegrationTest public void testAuthenticate() { AndFilter filter = new AndFilter(); filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3")); - assertTrue(ldapTemplate.authenticate("", filter.toString(), "password")); + assertThat(ldapTemplate.authenticate("", filter.toString(), "password")).isTrue(); } private void verifyBoundCorrectData() { DirContextOperations result = ldapTemplate.lookupContext(DN_STRING); - assertEquals("Some Person4", result.getStringAttribute("cn")); - assertEquals("Person4", result.getStringAttribute("sn")); + assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person4"); + assertThat(result.getStringAttribute("sn")).isEqualTo("Person4"); } private void verifyCleanup() { @@ -216,7 +215,7 @@ public class SimpleLdapTemplateITest extends AbstractLdapTemplateIntegrationTest fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/support/BaseLdapPathBeanPostprocessorITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/support/BaseLdapPathBeanPostprocessorITest.java index e69832ac..d212f5c0 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/support/BaseLdapPathBeanPostprocessorITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/support/BaseLdapPathBeanPostprocessorITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,10 +23,8 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.ldap.core.DistinguishedName; import org.springframework.ldap.support.LdapUtils; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertTrue; -import static junit.framework.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Integration tests for {@link org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor}. @@ -42,11 +40,11 @@ public class BaseLdapPathBeanPostprocessorITest { DummyBaseLdapPathAware tested = ctx.getBean(DummyBaseLdapPathAware.class); DistinguishedName base = tested.getBase(); - assertNotNull(base); - assertEquals(new DistinguishedName("dc=261consulting,dc=com"), base); + assertThat(base).isNotNull(); + assertThat(base).isEqualTo(new DistinguishedName("dc=261consulting,dc=com")); DummyBaseLdapNameAware otherTested = ctx.getBean(DummyBaseLdapNameAware.class); - assertEquals(LdapUtils.newLdapName("dc=261consulting,dc=com"), otherTested.getBaseLdapPath()); + assertThat(otherTested.getBaseLdapPath()).isEqualTo(LdapUtils.newLdapName("dc=261consulting,dc=com")); } @Test @@ -57,7 +55,7 @@ public class BaseLdapPathBeanPostprocessorITest { } catch (BeanCreationException expected) { Throwable cause = expected.getCause(); - assertTrue(cause instanceof NoSuchBeanDefinitionException); + assertThat(cause instanceof NoSuchBeanDefinitionException).isTrue(); } } @@ -68,8 +66,8 @@ public class BaseLdapPathBeanPostprocessorITest { DummyBaseLdapPathAware tested = (DummyBaseLdapPathAware) ctx.getBean("dummyBaseContextAware"); DistinguishedName base = tested.getBase(); - assertNotNull(base); - assertEquals(new DistinguishedName("cn=john doe,dc=261consulting,dc=com"), base); + assertThat(base).isNotNull(); + assertThat(base).isEqualTo(new DistinguishedName("cn=john doe,dc=261consulting,dc=com")); } @Test @@ -80,7 +78,7 @@ public class BaseLdapPathBeanPostprocessorITest { } catch (BeanCreationException expected) { Throwable cause = expected.getCause(); - assertTrue(cause instanceof NoSuchBeanDefinitionException); + assertThat(cause instanceof NoSuchBeanDefinitionException).isTrue(); } } @@ -91,8 +89,8 @@ public class BaseLdapPathBeanPostprocessorITest { DummyBaseLdapPathAware tested = (DummyBaseLdapPathAware) ctx.getBean("dummyBaseContextAware"); DistinguishedName base = tested.getBase(); - assertNotNull(base); - assertEquals(new DistinguishedName("cn=john doe"), base); + assertThat(base).isNotNull(); + assertThat(base).isEqualTo(new DistinguishedName("cn=john doe")); } @Test @@ -102,7 +100,7 @@ public class BaseLdapPathBeanPostprocessorITest { DummyBaseLdapPathAware tested = (DummyBaseLdapPathAware) ctx.getBean("dummyBaseContextAware"); DistinguishedName base = tested.getBase(); - assertNotNull(base); - assertEquals(new DistinguishedName("dc=261consulting,dc=com"), base); + assertThat(base).isNotNull(); + assertThat(base).isEqualTo(new DistinguishedName("dc=261consulting,dc=com")); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/support/BaseLdapPathBeanPostprocessorNamespaceConfigITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/support/BaseLdapPathBeanPostprocessorNamespaceConfigITest.java index ecf5bafc..5069867c 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/support/BaseLdapPathBeanPostprocessorNamespaceConfigITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/support/BaseLdapPathBeanPostprocessorNamespaceConfigITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.ldap.core.DistinguishedName; import org.springframework.ldap.support.LdapUtils; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; /** * Integration tests for {@link org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor}. @@ -38,11 +37,11 @@ public class BaseLdapPathBeanPostprocessorNamespaceConfigITest { DummyBaseLdapPathAware tested = ctx.getBean(DummyBaseLdapPathAware.class); DistinguishedName base = tested.getBase(); - assertNotNull(base); - assertEquals(new DistinguishedName("dc=jayway,dc=se"), base); + assertThat(base).isNotNull(); + assertThat(base).isEqualTo(new DistinguishedName("dc=jayway,dc=se")); DummyBaseLdapNameAware otherTested = ctx.getBean(DummyBaseLdapNameAware.class); - assertEquals(LdapUtils.newLdapName("dc=jayway,dc=se"), otherTested.getBaseLdapPath()); + assertThat(otherTested.getBaseLdapPath()).isEqualTo(LdapUtils.newLdapName("dc=jayway,dc=se")); } @Test @@ -52,11 +51,11 @@ public class BaseLdapPathBeanPostprocessorNamespaceConfigITest { DummyBaseLdapPathAware tested = ctx.getBean(DummyBaseLdapPathAware.class); DistinguishedName base = tested.getBase(); - assertNotNull(base); - assertEquals(new DistinguishedName("dc=jayway,dc=se"), base); + assertThat(base).isNotNull(); + assertThat(base).isEqualTo(new DistinguishedName("dc=jayway,dc=se")); DummyBaseLdapNameAware otherTested = ctx.getBean(DummyBaseLdapNameAware.class); - assertEquals(LdapUtils.newLdapName("dc=jayway,dc=se"), otherTested.getBaseLdapPath()); + assertThat(otherTested.getBaseLdapPath()).isEqualTo(LdapUtils.newLdapName("dc=jayway,dc=se")); } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/support/LdapContextSourceIntegrationTest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/support/LdapContextSourceIntegrationTest.java index 6a4cbbe1..4acd6ef4 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/support/LdapContextSourceIntegrationTest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/support/LdapContextSourceIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,11 +38,8 @@ import javax.naming.directory.DirContext; import java.util.Hashtable; import java.util.List; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertTrue; -import static junit.framework.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Integration tests for LdapContextSource. @@ -65,11 +62,11 @@ public class LdapContextSourceIntegrationTest extends AbstractLdapTemplateIntegr try { ctx = tested.getReadOnlyContext(); - assertNotNull(ctx); + assertThat(ctx).isNotNull(); Hashtable environment = ctx.getEnvironment(); - assertFalse(environment.containsKey(LdapContextSource.SUN_LDAP_POOLING_FLAG)); - assertTrue(environment.containsKey(Context.SECURITY_PRINCIPAL)); - assertTrue(environment.containsKey(Context.SECURITY_CREDENTIALS)); + assertThat(environment.containsKey(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isFalse(); + assertThat(environment.containsKey(Context.SECURITY_PRINCIPAL)).isTrue(); + assertThat(environment.containsKey(Context.SECURITY_CREDENTIALS)).isTrue(); } finally { // Always clean up. @@ -90,12 +87,12 @@ public class LdapContextSourceIntegrationTest extends AbstractLdapTemplateIntegr try { ctx = tested.getReadWriteContext(); - assertNotNull(ctx); + assertThat(ctx).isNotNull(); // Double check to see that we are authenticated. Hashtable environment = ctx.getEnvironment(); - assertFalse(environment.containsKey(LdapContextSource.SUN_LDAP_POOLING_FLAG)); - assertTrue(environment.containsKey(Context.SECURITY_PRINCIPAL)); - assertTrue(environment.containsKey(Context.SECURITY_CREDENTIALS)); + assertThat(environment.containsKey(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isFalse(); + assertThat(environment.containsKey(Context.SECURITY_PRINCIPAL)).isTrue(); + assertThat(environment.containsKey(Context.SECURITY_CREDENTIALS)).isTrue(); } finally { // Always clean up. @@ -118,13 +115,13 @@ public class LdapContextSourceIntegrationTest extends AbstractLdapTemplateIntegr String expectedPrincipal = "cn=Some Person,ou=company1,ou=Sweden," + base; String expectedCredentials = "password"; ctx = tested.getContext(expectedPrincipal, expectedCredentials); - assertNotNull(ctx); + assertThat(ctx).isNotNull(); // Double check to see that we are authenticated, and that we did not receive // a connection eligible for connection pooling. Hashtable environment = ctx.getEnvironment(); - assertFalse(environment.containsKey(LdapContextSource.SUN_LDAP_POOLING_FLAG)); - assertEquals(expectedPrincipal, environment.get(Context.SECURITY_PRINCIPAL)); - assertEquals(expectedCredentials, environment.get(Context.SECURITY_CREDENTIALS)); + assertThat(environment.containsKey(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isFalse(); + assertThat(environment.get(Context.SECURITY_PRINCIPAL)).isEqualTo(expectedPrincipal); + assertThat(environment.get(Context.SECURITY_CREDENTIALS)).isEqualTo(expectedCredentials); } finally { // Always clean up. @@ -152,7 +149,7 @@ public class LdapContextSourceIntegrationTest extends AbstractLdapTemplateIntegr DirContext ctx = null; try { ctx = tested.getContext(results.get(0), "password"); - assertTrue(true); + assertThat(true).isTrue(); } catch (Exception e) { fail("Authentication failed"); diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/support/LdapContextSourceMultiServerIntegrationTest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/support/LdapContextSourceMultiServerIntegrationTest.java index eedbb78c..7a1ba9de 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/support/LdapContextSourceMultiServerIntegrationTest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/support/LdapContextSourceMultiServerIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; import javax.naming.NamingException; -import static junit.framework.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Advanced integration tests for LdapContextSource. @@ -41,6 +41,6 @@ public class LdapContextSourceMultiServerIntegrationTest extends AbstractJUnit4S String[] urls = tested.getUrls(); String string = tested.assembleProviderUrlString(urls); - assertEquals("ldap://127.0.0.1:389 ldap://127.0.0.2:389", string); + assertThat(string).isEqualTo("ldap://127.0.0.1:389 ldap://127.0.0.2:389"); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/filter/HardcodedFilterIntegrationTest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/filter/HardcodedFilterIntegrationTest.java index caaeb93c..2931da20 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/filter/HardcodedFilterIntegrationTest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/filter/HardcodedFilterIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,8 +25,7 @@ import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTest; import org.springframework.ldap.support.LdapUtils; import org.springframework.test.context.ContextConfiguration; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Mattias Hellborg Arthursson @@ -43,8 +42,8 @@ public class HardcodedFilterIntegrationTest extends AbstractLdapTemplateIntegrat @Test public void verifyThatFilterEditorWorks() { Filter filter = dummyFilterConsumer.getFilter(); - assertTrue(filter instanceof HardcodedFilter); - assertEquals("(&(objectclass=person)(!(objectclass=computer))", filter.toString()); + assertThat(filter instanceof HardcodedFilter).isTrue(); + assertThat(filter.toString()).isEqualTo("(&(objectclass=person)(!(objectclass=computer))"); } @Test @@ -53,6 +52,6 @@ public class HardcodedFilterIntegrationTest extends AbstractLdapTemplateIntegrat CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler(); ldapTemplate.search(LdapUtils.emptyLdapName(), filter.encode(), handler); int hits = handler.getNoOfRows(); - assertTrue("expected more than one hit, got " + hits, hits > 1); + assertThat(hits > 1).isTrue(); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/integration/JiraLdap247ITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/integration/JiraLdap247ITest.java index 874e0cfb..b4c19a9d 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/integration/JiraLdap247ITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/integration/JiraLdap247ITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTest; import org.springframework.ldap.itest.LdapGroupDao; import org.springframework.test.context.ContextConfiguration; -import static org.junit.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for https://jira.springsource.org/browse/LDAP-247. @@ -38,12 +38,10 @@ public class JiraLdap247ITest extends AbstractLdapTemplateIntegrationTest { @Test public void verifyThatBasePathIsProperlyPopulated() { - assertNotNull(ldapGroupDao); + assertThat(ldapGroupDao).isNotNull(); // The base path should be automatically populated by BaseLdapPathBeanPostProcessor, // but it doesn't unless it implements Ordered, which caused the assertion below to fail. - assertNotNull( - "Base path has not been populated by BaseLdapPathBeanPostProcessor", - ldapGroupDao.getBasePath()); + assertThat(ldapGroupDao.getBasePath()).isNotNull(); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/ldap321/Ldap321Test.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/ldap321/Ldap321Test.java index a3abd76b..281f2fe4 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/ldap321/Ldap321Test.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/ldap321/Ldap321Test.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ */ package org.springframework.ldap.itest.ldap321; -import static org.junit.Assert.*; +import static org.assertj.core.api.Assertions.*; import java.util.Map; @@ -41,7 +41,7 @@ public class Ldap321Test{ @Test public void testQueryRoleMap() throws Exception { Map roleMap=roleRepo.queryRoleMap(); - assertNotNull(roleMap); + assertThat(roleMap).isNotNull(); for(String roleName:roleMap.keySet()){ System.out.println(roleName+":"+ roleMap.get(roleName)); diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceAndDataSourceTransactionManagerIntegrationTest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceAndDataSourceTransactionManagerIntegrationTest.java index fd2b5dbe..f53dbd24 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceAndDataSourceTransactionManagerIntegrationTest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceAndDataSourceTransactionManagerIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,10 +39,8 @@ import javax.naming.directory.Attributes; import java.sql.ResultSet; import java.sql.SQLException; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertTrue; -import static junit.framework.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Integration tests for {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceAndDataSourceTransactionManager}. @@ -88,7 +86,7 @@ public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } log.debug("Verifying result"); @@ -99,7 +97,7 @@ public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } try { @@ -111,7 +109,7 @@ public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends fail("EmptyResultDataAccessException expected"); } catch (EmptyResultDataAccessException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @@ -127,8 +125,8 @@ public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends return new Object(); } }); - assertNotNull(ldapResult); - assertNotNull(dbResult); + assertThat(ldapResult).isNotNull(); + assertThat(dbResult).isNotNull(); ldapTemplate.unbind("cn=some testperson, ou=company1, ou=Sweden"); } @@ -141,15 +139,15 @@ public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } log.debug("Verifying result"); Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Person", attributes.get("sn").get()); - assertEquals("Sweden, Company1, Some Person", attributes.get("description").get()); + assertThat(attributes.get("sn").get()).isEqualTo("Person"); + assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person"); return new Object(); } }); @@ -157,14 +155,14 @@ public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends Object jdbcResult = jdbcTemplate.queryForObject("select * from PERSON where fullname=?", new Object[] { "Some Person" }, new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { - assertEquals("Person", rs.getString("lastname")); - assertEquals("Sweden, Company1, Some Person", rs.getString("description")); + assertThat(rs.getString("lastname")).isEqualTo("Person"); + assertThat(rs.getString("description")).isEqualTo("Sweden, Company1, Some Person"); return new Object(); } }); - assertNotNull(ldapResult); - assertNotNull(jdbcResult); + assertThat(ldapResult).isNotNull(); + assertThat(jdbcResult).isNotNull(); } @Test @@ -175,8 +173,8 @@ public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends log.debug("Verifying result"); Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Updated Person", attributes.get("sn").get()); - assertEquals("Updated description", attributes.get("description").get()); + assertThat(attributes.get("sn").get()).isEqualTo("Updated Person"); + assertThat(attributes.get("description").get()).isEqualTo("Updated description"); return new Object(); } }); @@ -184,14 +182,14 @@ public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends Object jdbcResult = jdbcTemplate.queryForObject("select * from PERSON where fullname=?", new Object[] { "Some Person" }, new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { - assertEquals("Updated Person", rs.getString("lastname")); - assertEquals("Updated description", rs.getString("description")); + assertThat(rs.getString("lastname")).isEqualTo("Updated Person"); + assertThat(rs.getString("description")).isEqualTo("Updated description"); return new Object(); } }); - assertNotNull(ldapResult); - assertNotNull(jdbcResult); + assertThat(ldapResult).isNotNull(); + assertThat(jdbcResult).isNotNull(); dummyDao.update(dn, "Some Person", "Person", "Sweden, Company1, Some Person"); } @@ -205,7 +203,7 @@ public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } // Verify that entry was not moved. @@ -214,17 +212,17 @@ public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } // Verify that original entry was not updated. Object object = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Sweden, Company1, Some Person2", attributes.get("description").get()); + assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person2"); return new Object(); } }); - assertNotNull(object); + assertThat(object).isNotNull(); } @Test @@ -237,12 +235,12 @@ public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends // Verify that entry was moved and updated. Object object = ldapTemplate.lookup(newDn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Updated description", attributes.get("description").get()); + assertThat(attributes.get("description").get()).isEqualTo("Updated description"); return new Object(); } }); - assertNotNull(object); + assertThat(object).isNotNull(); dummyDao.updateAndRename(newDn, dn, "Sweden, Company1, Some Person2"); } @@ -255,19 +253,19 @@ public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } // Verify result - check that the operation was properly rolled back Object result = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Person", attributes.get("sn").get()); - assertEquals("Sweden, Company1, Some Person", attributes.get("description").get()); + assertThat(attributes.get("sn").get()).isEqualTo("Person"); + assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person"); return new Object(); } }); - assertNotNull(result); + assertThat(result).isNotNull(); } @Test @@ -279,13 +277,13 @@ public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends // Verify result - check that the operation was not rolled back Object result = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Updated lastname", attributes.get("sn").get()); - assertEquals("Updated description", attributes.get("description").get()); + assertThat(attributes.get("sn").get()).isEqualTo("Updated lastname"); + assertThat(attributes.get("description").get()).isEqualTo("Updated description"); return new Object(); } }); - assertNotNull(result); + assertThat(result).isNotNull(); dummyDao.update(dn, "Some Person", "Person", "Sweden, Company1, Some Person"); } @@ -298,7 +296,7 @@ public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } // Verify result - check that the operation was properly rolled back @@ -317,8 +315,8 @@ public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends } }); - assertNotNull(ldapResult); - assertNotNull(jdbcResult); + assertThat(ldapResult).isNotNull(); + assertThat(jdbcResult).isNotNull(); } @Test @@ -333,7 +331,7 @@ public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } try { @@ -346,7 +344,7 @@ public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends fail("EmptyResultDataAccessException expected"); } catch (EmptyResultDataAccessException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceAndDataSourceTransactionManagerLdap179IntegrationTest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceAndDataSourceTransactionManagerLdap179IntegrationTest.java index 972587ad..30832922 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceAndDataSourceTransactionManagerLdap179IntegrationTest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceAndDataSourceTransactionManagerLdap179IntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,9 +32,8 @@ import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; import org.springframework.transaction.CannotCreateTransactionException; import org.springframework.transaction.support.TransactionSynchronizationManager; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Integration tests for {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceAndDataSourceTransactionManager}. @@ -75,17 +74,17 @@ public class ContextSourceAndDataSourceTransactionManagerLdap179IntegrationTest dummyDao.create("Sweden", "company1", "some testperson", "testperson", "some description"); fail("CannotCreateTransactionException expected"); } catch (CannotCreateTransactionException expected) { - assertTrue(expected.getCause() instanceof CommunicationException); + assertThat(expected.getCause() instanceof CommunicationException).isTrue(); } // Make sure there is no transaction synchronization - assertFalse(TransactionSynchronizationManager.isSynchronizationActive()); + assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isFalse(); try { dummyDao.create("Sweden", "company1", "some testperson", "testperson", "some description"); fail("CannotCreateTransactionException expected"); } catch (CannotCreateTransactionException expected) { - assertTrue(expected.getCause() instanceof CommunicationException); + assertThat(expected.getCause() instanceof CommunicationException).isTrue(); } } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceAndDataSourceTransactionManagerNamespaceITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceAndDataSourceTransactionManagerNamespaceITest.java index 11b86765..db3c889f 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceAndDataSourceTransactionManagerNamespaceITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceAndDataSourceTransactionManagerNamespaceITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,10 +40,8 @@ import javax.naming.directory.Attributes; import java.sql.ResultSet; import java.sql.SQLException; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertTrue; -import static junit.framework.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Integration tests for {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceAndDataSourceTransactionManager} @@ -90,7 +88,7 @@ public class ContextSourceAndDataSourceTransactionManagerNamespaceITest extends fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } log.debug("Verifying result"); @@ -101,7 +99,7 @@ public class ContextSourceAndDataSourceTransactionManagerNamespaceITest extends fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } try { @@ -113,7 +111,7 @@ public class ContextSourceAndDataSourceTransactionManagerNamespaceITest extends fail("EmptyResultDataAccessException expected"); } catch (EmptyResultDataAccessException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @@ -129,8 +127,8 @@ public class ContextSourceAndDataSourceTransactionManagerNamespaceITest extends return new Object(); } }); - assertNotNull(ldapResult); - assertNotNull(dbResult); + assertThat(ldapResult).isNotNull(); + assertThat(dbResult).isNotNull(); ldapTemplate.unbind("cn=some testperson, ou=company1, ou=Sweden"); } @@ -143,15 +141,15 @@ public class ContextSourceAndDataSourceTransactionManagerNamespaceITest extends fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } log.debug("Verifying result"); Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Person", attributes.get("sn").get()); - assertEquals("Sweden, Company1, Some Person", attributes.get("description").get()); + assertThat(attributes.get("sn").get()).isEqualTo("Person"); + assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person"); return new Object(); } }); @@ -159,14 +157,14 @@ public class ContextSourceAndDataSourceTransactionManagerNamespaceITest extends Object jdbcResult = jdbcTemplate.queryForObject("select * from PERSON where fullname=?", new Object[] { "Some Person" }, new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { - assertEquals("Person", rs.getString("lastname")); - assertEquals("Sweden, Company1, Some Person", rs.getString("description")); + assertThat(rs.getString("lastname")).isEqualTo("Person"); + assertThat(rs.getString("description")).isEqualTo("Sweden, Company1, Some Person"); return new Object(); } }); - assertNotNull(ldapResult); - assertNotNull(jdbcResult); + assertThat(ldapResult).isNotNull(); + assertThat(jdbcResult).isNotNull(); } @Test @@ -177,8 +175,8 @@ public class ContextSourceAndDataSourceTransactionManagerNamespaceITest extends log.debug("Verifying result"); Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Updated Person", attributes.get("sn").get()); - assertEquals("Updated description", attributes.get("description").get()); + assertThat(attributes.get("sn").get()).isEqualTo("Updated Person"); + assertThat(attributes.get("description").get()).isEqualTo("Updated description"); return new Object(); } }); @@ -186,14 +184,14 @@ public class ContextSourceAndDataSourceTransactionManagerNamespaceITest extends Object jdbcResult = jdbcTemplate.queryForObject("select * from PERSON where fullname=?", new Object[] { "Some Person" }, new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { - assertEquals("Updated Person", rs.getString("lastname")); - assertEquals("Updated description", rs.getString("description")); + assertThat(rs.getString("lastname")).isEqualTo("Updated Person"); + assertThat(rs.getString("description")).isEqualTo("Updated description"); return new Object(); } }); - assertNotNull(ldapResult); - assertNotNull(jdbcResult); + assertThat(ldapResult).isNotNull(); + assertThat(jdbcResult).isNotNull(); dummyDao.update(dn, "Some Person", "Person", "Sweden, Company1, Some Person"); } @@ -207,7 +205,7 @@ public class ContextSourceAndDataSourceTransactionManagerNamespaceITest extends fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } // Verify that entry was not moved. @@ -216,17 +214,17 @@ public class ContextSourceAndDataSourceTransactionManagerNamespaceITest extends fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } // Verify that original entry was not updated. Object object = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Sweden, Company1, Some Person2", attributes.get("description").get()); + assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person2"); return new Object(); } }); - assertNotNull(object); + assertThat(object).isNotNull(); } @Test @@ -239,12 +237,12 @@ public class ContextSourceAndDataSourceTransactionManagerNamespaceITest extends // Verify that entry was moved and updated. Object object = ldapTemplate.lookup(newDn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Updated description", attributes.get("description").get()); + assertThat(attributes.get("description").get()).isEqualTo("Updated description"); return new Object(); } }); - assertNotNull(object); + assertThat(object).isNotNull(); dummyDao.updateAndRename(newDn, dn, "Sweden, Company1, Some Person2"); } @@ -257,19 +255,19 @@ public class ContextSourceAndDataSourceTransactionManagerNamespaceITest extends fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } // Verify result - check that the operation was properly rolled back Object result = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Person", attributes.get("sn").get()); - assertEquals("Sweden, Company1, Some Person", attributes.get("description").get()); + assertThat(attributes.get("sn").get()).isEqualTo("Person"); + assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person"); return new Object(); } }); - assertNotNull(result); + assertThat(result).isNotNull(); } @Test @@ -281,13 +279,13 @@ public class ContextSourceAndDataSourceTransactionManagerNamespaceITest extends // Verify result - check that the operation was not rolled back Object result = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Updated lastname", attributes.get("sn").get()); - assertEquals("Updated description", attributes.get("description").get()); + assertThat(attributes.get("sn").get()).isEqualTo("Updated lastname"); + assertThat(attributes.get("description").get()).isEqualTo("Updated description"); return new Object(); } }); - assertNotNull(result); + assertThat(result).isNotNull(); dummyDao.update(dn, "Some Person", "Person", "Sweden, Company1, Some Person"); } @@ -300,7 +298,7 @@ public class ContextSourceAndDataSourceTransactionManagerNamespaceITest extends fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } // Verify result - check that the operation was properly rolled back @@ -319,8 +317,8 @@ public class ContextSourceAndDataSourceTransactionManagerNamespaceITest extends } }); - assertNotNull(ldapResult); - assertNotNull(jdbcResult); + assertThat(ldapResult).isNotNull(); + assertThat(jdbcResult).isNotNull(); } @Test @@ -335,7 +333,7 @@ public class ContextSourceAndDataSourceTransactionManagerNamespaceITest extends fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } try { @@ -348,7 +346,7 @@ public class ContextSourceAndDataSourceTransactionManagerNamespaceITest extends fail("EmptyResultDataAccessException expected"); } catch (EmptyResultDataAccessException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceTransactionManagerIntegrationTest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceTransactionManagerIntegrationTest.java index 159acf9d..a8fbc008 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceTransactionManagerIntegrationTest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceTransactionManagerIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,10 +33,8 @@ import org.springframework.transaction.support.TransactionSynchronizationManager import javax.naming.NamingException; import javax.naming.directory.Attributes; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertTrue; -import static junit.framework.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Integration tests for {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceTransactionManager}. @@ -69,7 +67,7 @@ public class ContextSourceTransactionManagerIntegrationTest extends AbstractLdap fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } log.debug("Verifying result"); @@ -80,7 +78,7 @@ public class ContextSourceTransactionManagerIntegrationTest extends AbstractLdap fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @@ -91,7 +89,7 @@ public class ContextSourceTransactionManagerIntegrationTest extends AbstractLdap log.debug("Verifying result"); String expectedDn = "cn=some testperson, ou=company1, ou=Sweden"; Object ldapResult = ldapTemplate.lookup(expectedDn); - assertNotNull(ldapResult); + assertThat(ldapResult).isNotNull(); ldapTemplate.unbind(expectedDn); } @@ -104,20 +102,20 @@ public class ContextSourceTransactionManagerIntegrationTest extends AbstractLdap fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } log.debug("Verifying result"); Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Person", attributes.get("sn").get()); - assertEquals("Sweden, Company1, Some Person", attributes.get("description").get()); + assertThat(attributes.get("sn").get()).isEqualTo("Person"); + assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person"); return new Object(); } }); - assertNotNull(ldapResult); + assertThat(ldapResult).isNotNull(); } @Test @@ -128,13 +126,13 @@ public class ContextSourceTransactionManagerIntegrationTest extends AbstractLdap log.debug("Verifying result"); Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Updated Person", attributes.get("sn").get()); - assertEquals("Updated description", attributes.get("description").get()); + assertThat(attributes.get("sn").get()).isEqualTo("Updated Person"); + assertThat(attributes.get("description").get()).isEqualTo("Updated description"); return new Object(); } }); - assertNotNull(ldapResult); + assertThat(ldapResult).isNotNull(); dummyDao.update(dn, "Some Person", "Person", "Sweden, Company1, Some Person"); } @@ -149,7 +147,7 @@ public class ContextSourceTransactionManagerIntegrationTest extends AbstractLdap fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } // Verify that entry was not moved. @@ -158,17 +156,17 @@ public class ContextSourceTransactionManagerIntegrationTest extends AbstractLdap fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } // Verify that original entry was not updated. Object object = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Sweden, Company1, Some Person2", attributes.get("description").get()); + assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person2"); return new Object(); } }); - assertNotNull(object); + assertThat(object).isNotNull(); } @Test @@ -181,12 +179,12 @@ public class ContextSourceTransactionManagerIntegrationTest extends AbstractLdap // Verify that entry was moved and updated. Object object = ldapTemplate.lookup(newDn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Updated description", attributes.get("description").get()); + assertThat(attributes.get("description").get()).isEqualTo("Updated description"); return new Object(); } }); - assertNotNull(object); + assertThat(object).isNotNull(); dummyDao.updateAndRename(newDn, dn, "Sweden, Company1, Some Person2"); } @@ -199,19 +197,19 @@ public class ContextSourceTransactionManagerIntegrationTest extends AbstractLdap fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } // Verify result - check that the operation was properly rolled back Object result = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Person", attributes.get("sn").get()); - assertEquals("Sweden, Company1, Some Person", attributes.get("description").get()); + assertThat(attributes.get("sn").get()).isEqualTo("Person"); + assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person"); return new Object(); } }); - assertNotNull(result); + assertThat(result).isNotNull(); } @Test @@ -223,13 +221,13 @@ public class ContextSourceTransactionManagerIntegrationTest extends AbstractLdap // Verify result - check that the operation was not rolled back Object result = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Updated lastname", attributes.get("sn").get()); - assertEquals("Updated description", attributes.get("description").get()); + assertThat(attributes.get("sn").get()).isEqualTo("Updated lastname"); + assertThat(attributes.get("description").get()).isEqualTo("Updated description"); return new Object(); } }); - assertNotNull(result); + assertThat(result).isNotNull(); } @Test @@ -241,7 +239,7 @@ public class ContextSourceTransactionManagerIntegrationTest extends AbstractLdap fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } // Verify result - check that the operation was properly rolled back @@ -252,7 +250,7 @@ public class ContextSourceTransactionManagerIntegrationTest extends AbstractLdap } }); - assertNotNull(ldapResult); + assertThat(ldapResult).isNotNull(); } @Test @@ -267,7 +265,7 @@ public class ContextSourceTransactionManagerIntegrationTest extends AbstractLdap fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceTransactionManagerNamespaceIntegrationTest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceTransactionManagerNamespaceIntegrationTest.java index d3e37ea9..76daa71f 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceTransactionManagerNamespaceIntegrationTest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceTransactionManagerNamespaceIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,10 +33,8 @@ import org.springframework.transaction.support.TransactionSynchronizationManager import javax.naming.NamingException; import javax.naming.directory.Attributes; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertTrue; -import static junit.framework.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Integration tests for {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceTransactionManager} @@ -70,7 +68,7 @@ public class ContextSourceTransactionManagerNamespaceIntegrationTest extends Abs fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } log.debug("Verifying result"); @@ -81,7 +79,7 @@ public class ContextSourceTransactionManagerNamespaceIntegrationTest extends Abs fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @@ -92,7 +90,7 @@ public class ContextSourceTransactionManagerNamespaceIntegrationTest extends Abs log.debug("Verifying result"); String expectedDn = "cn=some testperson, ou=company1, ou=Sweden"; Object ldapResult = ldapTemplate.lookup(expectedDn); - assertNotNull(ldapResult); + assertThat(ldapResult).isNotNull(); ldapTemplate.unbind(expectedDn); } @@ -105,20 +103,20 @@ public class ContextSourceTransactionManagerNamespaceIntegrationTest extends Abs fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } log.debug("Verifying result"); Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Person", attributes.get("sn").get()); - assertEquals("Sweden, Company1, Some Person", attributes.get("description").get()); + assertThat(attributes.get("sn").get()).isEqualTo("Person"); + assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person"); return new Object(); } }); - assertNotNull(ldapResult); + assertThat(ldapResult).isNotNull(); } @Test @@ -129,13 +127,13 @@ public class ContextSourceTransactionManagerNamespaceIntegrationTest extends Abs log.debug("Verifying result"); Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Updated Person", attributes.get("sn").get()); - assertEquals("Updated description", attributes.get("description").get()); + assertThat(attributes.get("sn").get()).isEqualTo("Updated Person"); + assertThat(attributes.get("description").get()).isEqualTo("Updated description"); return new Object(); } }); - assertNotNull(ldapResult); + assertThat(ldapResult).isNotNull(); dummyDao.update(dn, "Some Person", "Person", "Sweden, Company1, Some Person"); } @@ -150,7 +148,7 @@ public class ContextSourceTransactionManagerNamespaceIntegrationTest extends Abs fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } // Verify that entry was not moved. @@ -159,17 +157,17 @@ public class ContextSourceTransactionManagerNamespaceIntegrationTest extends Abs fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } // Verify that original entry was not updated. Object object = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Sweden, Company1, Some Person2", attributes.get("description").get()); + assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person2"); return new Object(); } }); - assertNotNull(object); + assertThat(object).isNotNull(); } @Test @@ -182,12 +180,12 @@ public class ContextSourceTransactionManagerNamespaceIntegrationTest extends Abs // Verify that entry was moved and updated. Object object = ldapTemplate.lookup(newDn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Updated description", attributes.get("description").get()); + assertThat(attributes.get("description").get()).isEqualTo("Updated description"); return new Object(); } }); - assertNotNull(object); + assertThat(object).isNotNull(); dummyDao.updateAndRename(newDn, dn, "Sweden, Company1, Some Person2"); } @@ -200,19 +198,19 @@ public class ContextSourceTransactionManagerNamespaceIntegrationTest extends Abs fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } // Verify result - check that the operation was properly rolled back Object result = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Person", attributes.get("sn").get()); - assertEquals("Sweden, Company1, Some Person", attributes.get("description").get()); + assertThat(attributes.get("sn").get()).isEqualTo("Person"); + assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person"); return new Object(); } }); - assertNotNull(result); + assertThat(result).isNotNull(); } @Test @@ -224,13 +222,13 @@ public class ContextSourceTransactionManagerNamespaceIntegrationTest extends Abs // Verify result - check that the operation was not rolled back Object result = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Updated lastname", attributes.get("sn").get()); - assertEquals("Updated description", attributes.get("description").get()); + assertThat(attributes.get("sn").get()).isEqualTo("Updated lastname"); + assertThat(attributes.get("description").get()).isEqualTo("Updated description"); return new Object(); } }); - assertNotNull(result); + assertThat(result).isNotNull(); } @Test @@ -242,7 +240,7 @@ public class ContextSourceTransactionManagerNamespaceIntegrationTest extends Abs fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } // Verify result - check that the operation was properly rolled back @@ -253,7 +251,7 @@ public class ContextSourceTransactionManagerNamespaceIntegrationTest extends Abs } }); - assertNotNull(ldapResult); + assertThat(ldapResult).isNotNull(); } @Test @@ -268,7 +266,7 @@ public class ContextSourceTransactionManagerNamespaceIntegrationTest extends Abs fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceTransactionManagerSubtreeIntegrationTest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceTransactionManagerSubtreeIntegrationTest.java index 8592dce4..3cd182bb 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceTransactionManagerSubtreeIntegrationTest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceTransactionManagerSubtreeIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,8 +30,8 @@ import org.springframework.ldap.itest.transaction.compensating.manager.DummyExce import org.springframework.test.context.ContextConfiguration; import org.springframework.transaction.support.TransactionSynchronizationManager; -import static junit.framework.Assert.assertTrue; -import static junit.framework.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Integration tests for {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceAndDataSourceTransactionManager} @@ -68,7 +68,7 @@ public class ContextSourceTransactionManagerSubtreeIntegrationTest extends Abstr ldapTemplate.lookup("ou=company1,ou=Sweden"); fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } @@ -78,7 +78,7 @@ public class ContextSourceTransactionManagerSubtreeIntegrationTest extends Abstr dummyDao.deleteRecursivelyWithException("ou=company1,ou=Sweden"); fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } // Entry should have been restored @@ -96,7 +96,7 @@ public class ContextSourceTransactionManagerSubtreeIntegrationTest extends Abstr dummyDao.createRecursivelyAndUnbindSubnodeWithException(); fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/hibernate/ContextSourceAndHibernateTransactionManagerIntegrationTest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/hibernate/ContextSourceAndHibernateTransactionManagerIntegrationTest.java old mode 100755 new mode 100644 index 8c16626d..f8d3a766 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/hibernate/ContextSourceAndHibernateTransactionManagerIntegrationTest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/hibernate/ContextSourceAndHibernateTransactionManagerIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,11 +42,8 @@ import javax.naming.NamingException; import javax.naming.directory.Attributes; import java.util.List; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertNull; -import static junit.framework.Assert.assertTrue; -import static junit.framework.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Integration tests for {@link ContextSourceAndHibernateTransactionManager}. @@ -123,7 +120,7 @@ public class ContextSourceAndHibernateTransactionManagerIntegrationTest extends fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } log.debug("Verifying result"); @@ -134,12 +131,12 @@ public class ContextSourceAndHibernateTransactionManagerIntegrationTest extends fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } List result = hibernateTemplate.findByNamedParam("from OrgPerson person where person.lastname = :lastname", "lastname", person.getLastname()); - assertTrue(result.size() == 0); + assertThat(result.size() == 0).isTrue(); } @@ -161,8 +158,8 @@ public class ContextSourceAndHibernateTransactionManagerIntegrationTest extends log.debug("Verifying result"); Object ldapResult = ldapTemplate.lookup("cn=some testperson, ou=company1, ou=Sweden"); OrgPerson fromDb = (OrgPerson) this.hibernateTemplate.get(OrgPerson.class, new Integer(2)); - assertNotNull(ldapResult); - assertNotNull(fromDb); + assertThat(ldapResult).isNotNull(); + assertThat(fromDb).isNotNull(); } @Test @@ -175,24 +172,24 @@ public class ContextSourceAndHibernateTransactionManagerIntegrationTest extends fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } log.debug("Verifying result"); Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertNotNull("Person", attributes.get("sn").get()); - assertEquals("Sweden, Company1, Some Person", attributes.get("description").get()); + assertThat(attributes.get("sn").get()).as("Person").isNotNull(); + assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person"); return new Object(); } }); OrgPerson notUpdatedPerson = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1)); - assertEquals("Person", notUpdatedPerson.getLastname()); - assertEquals("Sweden, Company1, Some Person", notUpdatedPerson.getDescription()); + assertThat(notUpdatedPerson.getLastname()).isEqualTo("Person"); + assertThat(notUpdatedPerson.getDescription()).isEqualTo("Sweden, Company1, Some Person"); - assertNotNull(ldapResult); + assertThat(ldapResult).isNotNull(); // no need to assert if notUpdatedPerson exists } @@ -208,16 +205,16 @@ public class ContextSourceAndHibernateTransactionManagerIntegrationTest extends log.debug("Verifying result"); Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Updated Person", attributes.get("sn").get()); - assertEquals("Updated description", attributes.get("description").get()); + assertThat(attributes.get("sn").get()).isEqualTo("Updated Person"); + assertThat(attributes.get("description").get()).isEqualTo("Updated description"); return new Object(); } }); OrgPerson updatedPerson = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1)); - assertEquals("Updated Person", updatedPerson.getLastname()); - assertEquals("Updated description", updatedPerson.getDescription()); - assertNotNull(ldapResult); + assertThat(updatedPerson.getLastname()).isEqualTo("Updated Person"); + assertThat(updatedPerson.getDescription()).isEqualTo("Updated description"); + assertThat(ldapResult).isNotNull(); } @Test @@ -234,7 +231,7 @@ public class ContextSourceAndHibernateTransactionManagerIntegrationTest extends fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } // Verify that entry was not moved. @@ -243,17 +240,17 @@ public class ContextSourceAndHibernateTransactionManagerIntegrationTest extends fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } // Verify that original entry was not updated. Object object = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Sweden, Company1, Some Person2", attributes.get("description").get()); + assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person2"); return new Object(); } }); - assertNotNull(object); + assertThat(object).isNotNull(); } @Test @@ -266,12 +263,12 @@ public class ContextSourceAndHibernateTransactionManagerIntegrationTest extends // Verify that entry was moved and updated. Object object = ldapTemplate.lookup(newDn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Updated description", attributes.get("description").get()); + assertThat(attributes.get("description").get()).isEqualTo("Updated description"); return new Object(); } }); - assertNotNull(object); + assertThat(object).isNotNull(); } @Test @@ -283,19 +280,19 @@ public class ContextSourceAndHibernateTransactionManagerIntegrationTest extends fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } // Verify result - check that the operation was properly rolled back Object result = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Person", attributes.get("sn").get()); - assertEquals("Sweden, Company1, Some Person", attributes.get("description").get()); + assertThat(attributes.get("sn").get()).isEqualTo("Person"); + assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person"); return new Object(); } }); - assertNotNull(result); + assertThat(result).isNotNull(); } @Test @@ -307,13 +304,13 @@ public class ContextSourceAndHibernateTransactionManagerIntegrationTest extends // Verify result - check that the operation was not rolled back Object result = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Updated lastname", attributes.get("sn").get()); - assertEquals("Updated description", attributes.get("description").get()); + assertThat(attributes.get("sn").get()).isEqualTo("Updated lastname"); + assertThat(attributes.get("description").get()).isEqualTo("Updated description"); return new Object(); } }); - assertNotNull(result); + assertThat(result).isNotNull(); } @Test @@ -327,7 +324,7 @@ public class ContextSourceAndHibernateTransactionManagerIntegrationTest extends fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } person = null; @@ -348,7 +345,7 @@ public class ContextSourceAndHibernateTransactionManagerIntegrationTest extends // not // exist - assertNotNull(ldapResult); + assertThat(ldapResult).isNotNull(); } @Test @@ -364,10 +361,10 @@ public class ContextSourceAndHibernateTransactionManagerIntegrationTest extends fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } person = (OrgPerson) this.hibernateTemplate.get(OrgPerson.class, new Integer(1)); - assertNull(person); + assertThat(person).isNull(); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/hibernate/ContextSourceAndHibernateTransactionManagerLdap179IntegrationTest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/hibernate/ContextSourceAndHibernateTransactionManagerLdap179IntegrationTest.java old mode 100755 new mode 100644 index a0ba2ba2..2905c9a1 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/hibernate/ContextSourceAndHibernateTransactionManagerLdap179IntegrationTest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/hibernate/ContextSourceAndHibernateTransactionManagerLdap179IntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,8 +30,7 @@ import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; import org.springframework.transaction.CannotCreateTransactionException; import org.springframework.transaction.support.TransactionSynchronizationManager; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Integration tests for {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceAndHibernateTransactionManager}. @@ -68,16 +67,16 @@ public class ContextSourceAndHibernateTransactionManagerLdap179IntegrationTest e try { this.dummyDao.create(person); } catch (CannotCreateTransactionException expected) { - assertTrue(expected.getCause() instanceof CommunicationException); + assertThat(expected.getCause() instanceof CommunicationException).isTrue(); } // Make sure there is no transaction synchronization - assertFalse(TransactionSynchronizationManager.isSynchronizationActive()); + assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isFalse(); try { this.dummyDao.create(person); } catch (CannotCreateTransactionException expected) { - assertTrue(expected.getCause() instanceof CommunicationException); + assertThat(expected.getCause() instanceof CommunicationException).isTrue(); } } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/hibernate/ContextSourceAndHibernateTransactionManagerNamespaceITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/hibernate/ContextSourceAndHibernateTransactionManagerNamespaceITest.java old mode 100755 new mode 100644 index acd8173c..c279d060 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/hibernate/ContextSourceAndHibernateTransactionManagerNamespaceITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/hibernate/ContextSourceAndHibernateTransactionManagerNamespaceITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,11 +41,8 @@ import javax.naming.NamingException; import javax.naming.directory.Attributes; import java.util.List; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertNull; -import static junit.framework.Assert.assertTrue; -import static junit.framework.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Integration tests for {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceAndHibernateTransactionManager} @@ -123,7 +120,7 @@ public class ContextSourceAndHibernateTransactionManagerNamespaceITest extends A fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } log.debug("Verifying result"); @@ -134,12 +131,12 @@ public class ContextSourceAndHibernateTransactionManagerNamespaceITest extends A fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } List result = hibernateTemplate.findByNamedParam("from OrgPerson person where person.lastname = :lastname", "lastname", person.getLastname()); - assertTrue(result.size() == 0); + assertThat(result.size() == 0).isTrue(); } @@ -161,8 +158,8 @@ public class ContextSourceAndHibernateTransactionManagerNamespaceITest extends A log.debug("Verifying result"); Object ldapResult = ldapTemplate.lookup("cn=some testperson, ou=company1, ou=Sweden"); OrgPerson fromDb = (OrgPerson) this.hibernateTemplate.get(OrgPerson.class, new Integer(2)); - assertNotNull(ldapResult); - assertNotNull(fromDb); + assertThat(ldapResult).isNotNull(); + assertThat(fromDb).isNotNull(); } @Test @@ -175,24 +172,24 @@ public class ContextSourceAndHibernateTransactionManagerNamespaceITest extends A fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } log.debug("Verifying result"); Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertNotNull("Person", attributes.get("sn").get()); - assertEquals("Sweden, Company1, Some Person", attributes.get("description").get()); + assertThat(attributes.get("sn").get()).as("Person").isNotNull(); + assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person"); return new Object(); } }); OrgPerson notUpdatedPerson = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1)); - assertEquals("Person", notUpdatedPerson.getLastname()); - assertEquals("Sweden, Company1, Some Person", notUpdatedPerson.getDescription()); + assertThat(notUpdatedPerson.getLastname()).isEqualTo("Person"); + assertThat(notUpdatedPerson.getDescription()).isEqualTo("Sweden, Company1, Some Person"); - assertNotNull(ldapResult); + assertThat(ldapResult).isNotNull(); // no need to assert if notUpdatedPerson exists } @@ -208,16 +205,16 @@ public class ContextSourceAndHibernateTransactionManagerNamespaceITest extends A log.debug("Verifying result"); Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Updated Person", attributes.get("sn").get()); - assertEquals("Updated description", attributes.get("description").get()); + assertThat(attributes.get("sn").get()).isEqualTo("Updated Person"); + assertThat(attributes.get("description").get()).isEqualTo("Updated description"); return new Object(); } }); OrgPerson updatedPerson = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1)); - assertEquals("Updated Person", updatedPerson.getLastname()); - assertEquals("Updated description", updatedPerson.getDescription()); - assertNotNull(ldapResult); + assertThat(updatedPerson.getLastname()).isEqualTo("Updated Person"); + assertThat(updatedPerson.getDescription()).isEqualTo("Updated description"); + assertThat(ldapResult).isNotNull(); } @Test @@ -234,7 +231,7 @@ public class ContextSourceAndHibernateTransactionManagerNamespaceITest extends A fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } // Verify that entry was not moved. @@ -243,17 +240,17 @@ public class ContextSourceAndHibernateTransactionManagerNamespaceITest extends A fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } // Verify that original entry was not updated. Object object = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Sweden, Company1, Some Person2", attributes.get("description").get()); + assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person2"); return new Object(); } }); - assertNotNull(object); + assertThat(object).isNotNull(); } @Test @@ -266,12 +263,12 @@ public class ContextSourceAndHibernateTransactionManagerNamespaceITest extends A // Verify that entry was moved and updated. Object object = ldapTemplate.lookup(newDn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Updated description", attributes.get("description").get()); + assertThat(attributes.get("description").get()).isEqualTo("Updated description"); return new Object(); } }); - assertNotNull(object); + assertThat(object).isNotNull(); } @Test @@ -283,19 +280,19 @@ public class ContextSourceAndHibernateTransactionManagerNamespaceITest extends A fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } // Verify result - check that the operation was properly rolled back Object result = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Person", attributes.get("sn").get()); - assertEquals("Sweden, Company1, Some Person", attributes.get("description").get()); + assertThat(attributes.get("sn").get()).isEqualTo("Person"); + assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person"); return new Object(); } }); - assertNotNull(result); + assertThat(result).isNotNull(); } @Test @@ -307,13 +304,13 @@ public class ContextSourceAndHibernateTransactionManagerNamespaceITest extends A // Verify result - check that the operation was not rolled back Object result = ldapTemplate.lookup(dn, new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - assertEquals("Updated lastname", attributes.get("sn").get()); - assertEquals("Updated description", attributes.get("description").get()); + assertThat(attributes.get("sn").get()).isEqualTo("Updated lastname"); + assertThat(attributes.get("description").get()).isEqualTo("Updated description"); return new Object(); } }); - assertNotNull(result); + assertThat(result).isNotNull(); } @Test @@ -327,7 +324,7 @@ public class ContextSourceAndHibernateTransactionManagerNamespaceITest extends A fail("DummyException expected"); } catch (DummyException expected) { - assertTrue(true); + assertThat(true).isTrue(); } person = null; @@ -348,7 +345,7 @@ public class ContextSourceAndHibernateTransactionManagerNamespaceITest extends A // not // exist - assertNotNull(ldapResult); + assertThat(ldapResult).isNotNull(); } @Test @@ -364,10 +361,10 @@ public class ContextSourceAndHibernateTransactionManagerNamespaceITest extends A fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { - assertTrue(true); + assertThat(true).isTrue(); } person = (OrgPerson) this.hibernateTemplate.get(OrgPerson.class, new Integer(1)); - assertNull(person); + assertThat(person).isNull(); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmGroupManipulationITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmGroupManipulationITest.java index c351c9fd..03c5227e 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmGroupManipulationITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmGroupManipulationITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,10 +27,7 @@ import javax.naming.Name; import java.util.HashSet; import java.util.Set; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.ldap.query.LdapQueryBuilder.query; /** @@ -45,15 +42,15 @@ public class LdapTemplateOdmGroupManipulationITest extends AbstractLdapTemplateI public void testFindOne() { Group group = tested.findOne(query().where("cn").is("ROLE_USER"), Group.class); - assertNotNull(group); - assertEquals("ROLE_USER", group.getName()); - assertEquals(4, group.getMembers().size()); + assertThat(group).isNotNull(); + assertThat(group.getName()).isEqualTo("ROLE_USER"); + assertThat(group.getMembers()).hasSize(4); Set members = group.getMembers(); - assertTrue(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company1,ou=Sweden," + base))); - assertTrue(members.contains(LdapUtils.newLdapName("cn=Some Person2,ou=company1,ou=Sweden," + base))); - assertTrue(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company2,ou=Sweden," + base))); - assertTrue(members.contains(LdapUtils.newLdapName("cn=Some Person3,ou=company1,ou=Sweden," + base))); + assertThat(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company1,ou=Sweden," + base))).isTrue(); + assertThat(members.contains(LdapUtils.newLdapName("cn=Some Person2,ou=company1,ou=Sweden," + base))).isTrue(); + assertThat(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company2,ou=Sweden," + base))).isTrue(); + assertThat(members.contains(LdapUtils.newLdapName("cn=Some Person3,ou=company1,ou=Sweden," + base))).isTrue(); } @Test @@ -66,8 +63,8 @@ public class LdapTemplateOdmGroupManipulationITest extends AbstractLdapTemplateI Group verification = tested.findOne(query().where("cn").is("ROLE_USER"), Group.class); Set members = verification.getMembers(); - assertEquals(3, members.size()); - assertFalse(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company1,ou=Sweden," + base))); + assertThat(members).hasSize(3); + assertThat(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company1,ou=Sweden," + base))).isFalse(); } @Test @@ -80,8 +77,8 @@ public class LdapTemplateOdmGroupManipulationITest extends AbstractLdapTemplateI Group verification = tested.findOne(query().where("cn").is("ROLE_USER"), Group.class); Set members = verification.getMembers(); - assertEquals(3, members.size()); - assertFalse(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company1,ou=Sweden," + base))); + assertThat(members).hasSize(3); + assertThat(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company1,ou=Sweden," + base))).isFalse(); } @Test @@ -94,8 +91,8 @@ public class LdapTemplateOdmGroupManipulationITest extends AbstractLdapTemplateI Group verification = tested.findOne(query().where("cn").is("ROLE_USER"), Group.class); Set members = verification.getMembers(); - assertEquals(5, members.size()); - assertTrue(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company1,ou=Norway," + base))); + assertThat(members).hasSize(5); + assertThat(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company1,ou=Norway," + base))).isTrue(); } @Test @@ -108,8 +105,8 @@ public class LdapTemplateOdmGroupManipulationITest extends AbstractLdapTemplateI Group verification = tested.findOne(query().where("cn").is("ROLE_USER"), Group.class); Set members = verification.getMembers(); - assertEquals(4, members.size()); - assertTrue(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company1,ou=Sweden," + base))); + assertThat(members).hasSize(4); + assertThat(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company1,ou=Sweden," + base))).isTrue(); } @Test @@ -122,8 +119,8 @@ public class LdapTemplateOdmGroupManipulationITest extends AbstractLdapTemplateI Group verification = tested.findOne(query().where("cn").is("ROLE_USER"), Group.class); Set members = verification.getMembers(); - assertEquals(4, members.size()); - assertTrue(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company1,ou=Sweden," + base))); + assertThat(members).hasSize(4); + assertThat(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company1,ou=Sweden," + base))).isTrue(); } @Test @@ -140,8 +137,8 @@ public class LdapTemplateOdmGroupManipulationITest extends AbstractLdapTemplateI Set members = verification.getMembers(); - assertEquals(2, members.size()); - assertTrue(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company1,ou=Sweden," + base))); - assertTrue(members.contains(LdapUtils.newLdapName("cn=Some Person2,ou=company1,ou=Sweden," + base))); + assertThat(members).hasSize(2); + assertThat(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company1,ou=Sweden," + base))).isTrue(); + assertThat(members.contains(LdapUtils.newLdapName("cn=Some Person2,ou=company1,ou=Sweden," + base))).isTrue(); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithDnAnnotationsITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithDnAnnotationsITest.java index c6c7fbbb..566c59b2 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithDnAnnotationsITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithDnAnnotationsITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,9 +26,8 @@ import org.springframework.test.context.ContextConfiguration; import java.util.Arrays; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.springframework.ldap.query.LdapQueryBuilder.query; /** @@ -44,15 +43,15 @@ public class LdapTemplateOdmWithDnAnnotationsITest extends AbstractLdapTemplateI PersonWithDnAnnotations person = tested.findOne(query() .where("cn").is("Some Person3"), PersonWithDnAnnotations.class); - assertNotNull(person); - assertEquals("Some Person3", person.getCommonName()); - assertEquals("Person3", person.getSurname()); - assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); - assertEquals("+46 555-123654", person.getTelephoneNumber()); + assertThat(person).isNotNull(); + assertThat(person.getCommonName()).isEqualTo("Some Person3"); + assertThat(person.getSurname()).isEqualTo("Person3"); + assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); + assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); // Automatically calculated - assertEquals("company1", person.getCompany()); - assertEquals("Sweden", person.getCountry()); + assertThat(person.getCompany()).isEqualTo("company1"); + assertThat(person.getCountry()).isEqualTo("Sweden"); } @Test @@ -60,15 +59,15 @@ public class LdapTemplateOdmWithDnAnnotationsITest extends AbstractLdapTemplateI PersonWithDnAnnotations person = tested.findByDn(LdapUtils.newLdapName("cn=Some Person3,ou=company1,ou=Sweden"), PersonWithDnAnnotations.class); - assertNotNull(person); - assertEquals("Some Person3", person.getCommonName()); - assertEquals("Person3", person.getSurname()); - assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); - assertEquals("+46 555-123654", person.getTelephoneNumber()); + assertThat(person).isNotNull(); + assertThat(person.getCommonName()).isEqualTo("Some Person3"); + assertThat(person.getSurname()).isEqualTo("Person3"); + assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); + assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); // Automatically calculated - assertEquals("company1", person.getCompany()); - assertEquals("Sweden", person.getCountry()); + assertThat(person.getCompany()).isEqualTo("company1"); + assertThat(person.getCountry()).isEqualTo("Sweden"); } @Test @@ -77,13 +76,13 @@ public class LdapTemplateOdmWithDnAnnotationsITest extends AbstractLdapTemplateI .base("ou=Sweden") .where("cn").isPresent(), PersonWithDnAnnotations.class); - assertEquals(4, persons.size()); + assertThat(persons).hasSize(4); PersonWithDnAnnotations person = findPerson(persons, "Some Person3"); // Automatically calculated - assertEquals("company1", person.getCompany()); - assertEquals("Sweden", person.getCountry()); + assertThat(person.getCompany()).isEqualTo("company1"); + assertThat(person.getCountry()).isEqualTo("Sweden"); } private PersonWithDnAnnotations findPerson(List persons, String cn) { @@ -112,19 +111,19 @@ public class LdapTemplateOdmWithDnAnnotationsITest extends AbstractLdapTemplateI tested.create(person); - assertEquals(6, tested.findAll(PersonWithDnAnnotations.class).size()); + assertThat(tested.findAll(PersonWithDnAnnotations.class)).hasSize(6); person = tested.findByDn(LdapUtils.newLdapName("cn=New Person,ou=company1,ou=Sweden"), PersonWithDnAnnotations.class); - assertEquals("New Person", person.getCommonName()); - assertEquals("Person", person.getSurname()); - assertEquals("This is the description", person.getDesc().get(0)); - assertEquals("0123456", person.getTelephoneNumber()); + assertThat(person.getCommonName()).isEqualTo("New Person"); + assertThat(person.getSurname()).isEqualTo("Person"); + assertThat(person.getDesc().get(0)).isEqualTo("This is the description"); + assertThat(person.getTelephoneNumber()).isEqualTo("0123456"); // Automatically calculated - assertEquals("company1", person.getCompany()); - assertEquals("Sweden", person.getCountry()); + assertThat(person.getCompany()).isEqualTo("company1"); + assertThat(person.getCountry()).isEqualTo("Sweden"); } @Test @@ -139,10 +138,10 @@ public class LdapTemplateOdmWithDnAnnotationsITest extends AbstractLdapTemplateI LdapUtils.newLdapName("cn=Some Person3, ou=company1, ou=Sweden"), PersonWithDnAnnotations.class); - assertEquals("Some Person3", person.getCommonName()); - assertEquals("Person3", person.getSurname()); - assertEquals("New Description", person.getDesc().get(0)); - assertEquals("+46 555-123654", person.getTelephoneNumber()); + assertThat(person.getCommonName()).isEqualTo("Some Person3"); + assertThat(person.getSurname()).isEqualTo("Person3"); + assertThat(person.getDesc().get(0)).isEqualTo("New Description"); + assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); } @Test @@ -158,10 +157,10 @@ public class LdapTemplateOdmWithDnAnnotationsITest extends AbstractLdapTemplateI LdapUtils.newLdapName("cn=Some Person3, ou=company1, ou=Norway"), PersonWithDnAnnotations.class); - assertEquals("Some Person3", person.getCommonName()); - assertEquals("Person3", person.getSurname()); - assertEquals("Norway", person.getCountry()); - assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); - assertEquals("+46 555-123654", person.getTelephoneNumber()); + assertThat(person.getCommonName()).isEqualTo("Some Person3"); + assertThat(person.getSurname()).isEqualTo("Person3"); + assertThat(person.getCountry()).isEqualTo("Norway"); + assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); + assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithNoDnAnnotationsITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithNoDnAnnotationsITest.java index 33571817..a42d1af1 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithNoDnAnnotationsITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithNoDnAnnotationsITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,11 +29,8 @@ import org.springframework.test.context.ContextConfiguration; import java.util.Arrays; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.springframework.ldap.query.LdapQueryBuilder.query; /** @@ -49,22 +46,22 @@ public class LdapTemplateOdmWithNoDnAnnotationsITest extends AbstractLdapTemplat Person person = tested.findOne(query() .where("cn").is("Some Person3"), Person.class); - assertNotNull(person); - assertEquals("Some Person3", person.getCommonName()); - assertEquals("Person3", person.getSurname()); - assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); - assertEquals("+46 555-123654", person.getTelephoneNumber()); + assertThat(person).isNotNull(); + assertThat(person.getCommonName()).isEqualTo("Some Person3"); + assertThat(person.getSurname()).isEqualTo("Person3"); + assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); + assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); } @Test public void testFindByDn() { Person person = tested.findByDn(LdapUtils.newLdapName("cn=Some Person3,ou=company1,ou=Sweden"), Person.class); - assertNotNull(person); - assertEquals("Some Person3", person.getCommonName()); - assertEquals("Person3", person.getSurname()); - assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); - assertEquals("+46 555-123654", person.getTelephoneNumber()); + assertThat(person).isNotNull(); + assertThat(person.getCommonName()).isEqualTo("Some Person3"); + assertThat(person.getSurname()).isEqualTo("Person3"); + assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); + assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); } @Test(expected = OdmException.class) @@ -83,14 +80,14 @@ public class LdapTemplateOdmWithNoDnAnnotationsITest extends AbstractLdapTemplat List persons = tested.find(query() .where("cn").is("Some Person3"), Person.class); - assertEquals(1, persons.size()); + assertThat(persons).hasSize(1); Person person = persons.get(0); - assertNotNull(person); - assertEquals("Some Person3", person.getCommonName()); - assertEquals("Person3", person.getSurname()); - assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); - assertEquals("+46 555-123654", person.getTelephoneNumber()); + assertThat(person).isNotNull(); + assertThat(person.getCommonName()).isEqualTo("Some Person3"); + assertThat(person.getSurname()).isEqualTo("Person3"); + assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); + assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); } @Test @@ -99,16 +96,16 @@ public class LdapTemplateOdmWithNoDnAnnotationsITest extends AbstractLdapTemplat .base("ou=Sweden") .where("cn").isPresent(), Person.class); - assertEquals(4, persons.size()); + assertThat(persons).hasSize(4); Person person = persons.get(0); - assertNotNull(person); + assertThat(person).isNotNull(); } @Test public void testFindAll() { List result = tested.findAll(Person.class); - assertEquals(5, result.size()); + assertThat(result).hasSize(5); } @Test @@ -123,15 +120,15 @@ public class LdapTemplateOdmWithNoDnAnnotationsITest extends AbstractLdapTemplat tested.create(person); - assertEquals(6, tested.findAll(Person.class).size()); + assertThat(tested.findAll(Person.class)).hasSize(6); person = tested.findOne(query() .where("cn").is("New Person"), Person.class); - assertEquals("New Person", person.getCommonName()); - assertEquals("Person", person.getSurname()); - assertEquals("This is the description", person.getDesc().get(0)); - assertEquals("0123456", person.getTelephoneNumber()); + assertThat(person.getCommonName()).isEqualTo("New Person"); + assertThat(person.getSurname()).isEqualTo("Person"); + assertThat(person.getDesc().get(0)).isEqualTo("This is the description"); + assertThat(person.getTelephoneNumber()).isEqualTo("0123456"); } @Test @@ -145,10 +142,10 @@ public class LdapTemplateOdmWithNoDnAnnotationsITest extends AbstractLdapTemplat person = tested.findOne(query() .where("cn").is("Some Person3"), Person.class); - assertEquals("Some Person3", person.getCommonName()); - assertEquals("Person3", person.getSurname()); - assertEquals("New Description", person.getDesc().get(0)); - assertEquals("+46 555-123654", person.getTelephoneNumber()); + assertThat(person.getCommonName()).isEqualTo("Some Person3"); + assertThat(person.getSurname()).isEqualTo("Person3"); + assertThat(person.getDesc().get(0)).isEqualTo("New Description"); + assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); } @Test @@ -162,7 +159,7 @@ public class LdapTemplateOdmWithNoDnAnnotationsITest extends AbstractLdapTemplat tested.findOne(query().where("cn").is("Some Person3"), Person.class); fail("EmptyResultDataAccessException e"); } catch (EmptyResultDataAccessException e) { - assertTrue(true); + assertThat(true).isTrue(); } } @@ -180,6 +177,6 @@ public class LdapTemplateOdmWithNoDnAnnotationsITest extends AbstractLdapTemplat person = tested.findOne(query() .where("cn").is("Some Person3"), Person.class); - assertNull("TelephoneNumber should be null", person.getTelephoneNumber()); + assertThat(person.getTelephoneNumber()).as("TelephoneNumber should be null").isNull(); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateQueryDslLdapQueryITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateQueryDslLdapQueryITest.java index 41d01862..2c781a37 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateQueryDslLdapQueryITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateQueryDslLdapQueryITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,8 +26,7 @@ import org.springframework.test.context.ContextConfiguration; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Mattias Hellborg Arthursson @@ -49,11 +48,11 @@ public class LdapTemplateQueryDslLdapQueryITest extends AbstractLdapTemplateInte public void testUniqueResult() { Person person = query.where(qperson.commonName.eq("Some Person3")).uniqueResult(); - assertNotNull(person); - assertEquals("Some Person3", person.getCommonName()); - assertEquals("Person3", person.getSurname()); - assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); - assertEquals("+46 555-123654", person.getTelephoneNumber()); + assertThat(person).isNotNull(); + assertThat(person.getCommonName()).isEqualTo("Some Person3"); + assertThat(person.getSurname()).isEqualTo("Person3"); + assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); + assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); } @Test @@ -61,9 +60,9 @@ public class LdapTemplateQueryDslLdapQueryITest extends AbstractLdapTemplateInte List persons = query.where(qperson.commonName.eq("Some Person3")).list(); Person person = persons.get(0); - assertEquals("Some Person3", person.getCommonName()); - assertEquals("Person3", person.getSurname()); - assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); - assertEquals("+46 555-123654", person.getTelephoneNumber()); + assertThat(person.getCommonName()).isEqualTo("Some Person3"); + assertThat(person.getSurname()).isEqualTo("Person3"); + assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); + assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); } -} \ No newline at end of file +} diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanAnnotationConfiguredITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanAnnotationConfiguredITest.java index e7172311..5918315b 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanAnnotationConfiguredITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanAnnotationConfiguredITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,9 +26,7 @@ import org.springframework.test.context.ContextConfiguration; import javax.naming.Name; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for Spring LDAP automatic repository scan functionality enabled with @@ -45,17 +43,17 @@ public class RepositoryScanAnnotationConfiguredITest extends AbstractLdapTemplat @Test public void testExists() { - assertTrue(tested.exists(PERSON3_DN)); + assertThat(tested.exists(PERSON3_DN)).isTrue(); } @Test public void testFindOneWithDn() { Person person = tested.findOne(PERSON3_DN); - assertNotNull(person); - assertEquals("Some Person3", person.getCommonName()); - assertEquals("Person3", person.getSurname()); - assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); - assertEquals("+46 555-123654", person.getTelephoneNumber()); + assertThat(person).isNotNull(); + assertThat(person.getCommonName()).isEqualTo("Some Person3"); + assertThat(person.getSurname()).isEqualTo("Person3"); + assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); + assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanITest.java index d816bedd..7d6894b2 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,12 +31,8 @@ import javax.naming.ldap.LdapName; import java.util.Arrays; import java.util.Iterator; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.springframework.ldap.query.LdapQueryBuilder.query; /** @@ -54,48 +50,48 @@ public class RepositoryScanITest extends AbstractLdapTemplateIntegrationTest { @Test public void testExists() { - assertTrue(tested.exists(PERSON3_DN)); + assertThat(tested.exists(PERSON3_DN)).isTrue(); } @Test public void testFindOneWithDn() { Person person = tested.findOne(PERSON3_DN); - assertNotNull(person); - assertEquals("Some Person3", person.getCommonName()); - assertEquals("Person3", person.getSurname()); - assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); - assertEquals("+46 555-123654", person.getTelephoneNumber()); + assertThat(person).isNotNull(); + assertThat(person.getCommonName()).isEqualTo("Some Person3"); + assertThat(person.getSurname()).isEqualTo("Person3"); + assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); + assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); } @Test public void verifyThatFindOneWithNonexistingDnReturnsNull() { Person person = tested.findOne(LdapUtils.newLdapName("cn=unknown")); - assertNull(person); + assertThat(person).isNull(); } @Test public void testFindOneWithQuery() { Person person = tested.findOne(query().where("cn").is("Some Person3")); - assertNotNull(person); - assertEquals("Some Person3", person.getCommonName()); - assertEquals("Person3", person.getSurname()); - assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); - assertEquals("+46 555-123654", person.getTelephoneNumber()); + assertThat(person).isNotNull(); + assertThat(person.getCommonName()).isEqualTo("Some Person3"); + assertThat(person.getSurname()).isEqualTo("Person3"); + assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); + assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); } @Test public void testFindAll() { Iterable result = tested.findAll(); - assertEquals(5, countIterable(result)); + assertThat(countIterable(result)).isEqualTo(5); for (Person person : result) { if(StringUtils.equals(person.getCommonName(), "Some Person3")) { - assertEquals("Some Person3", person.getCommonName()); - assertEquals("Person3", person.getSurname()); - assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); - assertEquals("+46 555-123654", person.getTelephoneNumber()); + assertThat(person.getCommonName()).isEqualTo("Some Person3"); + assertThat(person.getSurname()).isEqualTo("Person3"); + assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); + assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); // Done return; @@ -109,16 +105,16 @@ public class RepositoryScanITest extends AbstractLdapTemplateIntegrationTest { public void testFindAllWithQuery() { Iterable persons = tested.findAll(query().where("cn").is("Some Person3")); - assertNotNull(persons); + assertThat(persons).isNotNull(); Iterator iterator = persons.iterator(); Person person = iterator.next(); - assertEquals("Some Person3", person.getCommonName()); - assertEquals("Person3", person.getSurname()); - assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); - assertEquals("+46 555-123654", person.getTelephoneNumber()); + assertThat(person.getCommonName()).isEqualTo("Some Person3"); + assertThat(person.getSurname()).isEqualTo("Person3"); + assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); + assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); - assertFalse(iterator.hasNext()); + assertThat(iterator.hasNext()).isFalse(); } @Test @@ -127,19 +123,19 @@ public class RepositoryScanITest extends AbstractLdapTemplateIntegrationTest { Iterator iterator = persons.iterator(); Person person = iterator.next(); - assertEquals("Some Person", person.getCommonName()); - assertEquals("Person", person.getSurname()); - assertEquals("Sweden, Company1, Some Person", person.getDesc().get(0)); - assertEquals("+46 555-123456", person.getTelephoneNumber()); + assertThat(person.getCommonName()).isEqualTo("Some Person"); + assertThat(person.getSurname()).isEqualTo("Person"); + assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person"); + assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123456"); person = iterator.next(); - assertEquals("Some Person3", person.getCommonName()); - assertEquals("Person3", person.getSurname()); - assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); - assertEquals("+46 555-123654", person.getTelephoneNumber()); + assertThat(person.getCommonName()).isEqualTo("Some Person3"); + assertThat(person.getSurname()).isEqualTo("Person3"); + assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); + assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); - assertFalse(iterator.hasNext()); + assertThat(iterator.hasNext()).isFalse(); } @Test @@ -148,17 +144,17 @@ public class RepositoryScanITest extends AbstractLdapTemplateIntegrationTest { Iterator iterator = persons.iterator(); Person person = iterator.next(); - assertEquals("Some Person3", person.getCommonName()); - assertEquals("Person3", person.getSurname()); - assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); - assertEquals("+46 555-123654", person.getTelephoneNumber()); + assertThat(person.getCommonName()).isEqualTo("Some Person3"); + assertThat(person.getSurname()).isEqualTo("Person3"); + assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); + assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); - assertFalse(iterator.hasNext()); + assertThat(iterator.hasNext()).isFalse(); } @Test public void testCount() { - assertEquals(5, tested.count()); + assertThat(tested.count()).isEqualTo(5); } private int countIterable(Iterable iterable) { @@ -183,14 +179,14 @@ public class RepositoryScanITest extends AbstractLdapTemplateIntegrationTest { person.setNew(); tested.save(person); - assertEquals(6, tested.count()); + assertThat(tested.count()).isEqualTo(6); person = tested.findOne(dn); - assertEquals("New Person", person.getCommonName()); - assertEquals("Person", person.getSurname()); - assertEquals("This is the description", person.getDesc().get(0)); - assertEquals("0123456", person.getTelephoneNumber()); + assertThat(person.getCommonName()).isEqualTo("New Person"); + assertThat(person.getSurname()).isEqualTo("Person"); + assertThat(person.getDesc().get(0)).isEqualTo("This is the description"); + assertThat(person.getTelephoneNumber()).isEqualTo("0123456"); } @Test(expected = IllegalArgumentException.class) @@ -213,10 +209,10 @@ public class RepositoryScanITest extends AbstractLdapTemplateIntegrationTest { person = tested.findOne(query().where("cn").is("Some Person3")); - assertEquals("Some Person3", person.getCommonName()); - assertEquals("Person3", person.getSurname()); - assertEquals("New Description", person.getDesc().get(0)); - assertEquals("+46 555-123654", person.getTelephoneNumber()); + assertThat(person.getCommonName()).isEqualTo("Some Person3"); + assertThat(person.getSurname()).isEqualTo("Person3"); + assertThat(person.getDesc().get(0)).isEqualTo("New Description"); + assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); } @Test @@ -225,7 +221,7 @@ public class RepositoryScanITest extends AbstractLdapTemplateIntegrationTest { tested.delete(person); Person found = tested.findOne(query().where("cn").is("Some Person3")); - assertNull(found); + assertThat(found).isNull(); } @Test @@ -233,33 +229,33 @@ public class RepositoryScanITest extends AbstractLdapTemplateIntegrationTest { Iterable found = tested.findAll(Arrays.asList(PERSON1_DN, PERSON3_DN)); tested.delete(found); - assertEquals(3, tested.count()); + assertThat(tested.count()).isEqualTo(3); } @Test public void testFindByLastName() { Iterable found = tested.findByLastName("Person3"); - assertEquals(1, countIterable(found)); + assertThat(countIterable(found)).isEqualTo(1); } @Test public void testFindByUid() { Person person = tested.findByUid("some.person3"); - assertEquals("Some Person3", person.getCommonName()); - assertEquals("Person3", person.getSurname()); - assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); - assertEquals("+46 555-123654", person.getTelephoneNumber()); + assertThat(person.getCommonName()).isEqualTo("Some Person3"); + assertThat(person.getSurname()).isEqualTo("Person3"); + assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); + assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); } @Test public void testFindByPhoneNumber() { Person person = tested.findByTelephoneNumber("+46 555-123654"); - assertEquals("Some Person3", person.getCommonName()); - assertEquals("Person3", person.getSurname()); - assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); - assertEquals("+46 555-123654", person.getTelephoneNumber()); + assertThat(person.getCommonName()).isEqualTo("Some Person3"); + assertThat(person.getSurname()).isEqualTo("Person3"); + assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); + assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanQueryDslITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanQueryDslITest.java index 72b02108..b2f6985d 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanQueryDslITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanQueryDslITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,14 +22,9 @@ import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTest; import org.springframework.ldap.itest.odm.Person; import org.springframework.ldap.itest.odm.QPerson; import org.springframework.ldap.itest.repositories.PersonQueryDslRepository; -import org.springframework.ldap.support.LdapUtils; import org.springframework.test.context.ContextConfiguration; -import javax.naming.Name; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for Spring LDAP automatic repository scan functionality. @@ -48,11 +43,11 @@ public class RepositoryScanQueryDslITest extends AbstractLdapTemplateIntegration Person found = tested.findOne(person.commonName.eq("Some Person3")); - assertNotNull(found); - assertEquals("Some Person3", found.getCommonName()); - assertEquals("Person3", found.getSurname()); - assertEquals("Sweden, Company1, Some Person3", found.getDesc().get(0)); - assertEquals("+46 555-123654", found.getTelephoneNumber()); + assertThat(found).isNotNull(); + assertThat(found.getCommonName()).isEqualTo("Some Person3"); + assertThat(found.getSurname()).isEqualTo("Person3"); + assertThat(found.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); + assertThat(found.getTelephoneNumber()).isEqualTo("+46 555-123654"); } @Test @@ -62,10 +57,10 @@ public class RepositoryScanQueryDslITest extends AbstractLdapTemplateIntegration Iterable foundPersons = tested.findAll(person.commonName.eq("Some Person3")); Person found = foundPersons.iterator().next(); - assertEquals("Some Person3", found.getCommonName()); - assertEquals("Person3", found.getSurname()); - assertEquals("Sweden, Company1, Some Person3", found.getDesc().get(0)); - assertEquals("+46 555-123654", found.getTelephoneNumber()); + assertThat(found.getCommonName()).isEqualTo("Some Person3"); + assertThat(found.getSurname()).isEqualTo("Person3"); + assertThat(found.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); + assertThat(found.getTelephoneNumber()).isEqualTo("+46 555-123654"); } @Test @@ -73,6 +68,6 @@ public class RepositoryScanQueryDslITest extends AbstractLdapTemplateIntegration QPerson person = QPerson.person; long count = tested.count(person.commonName.eq("Some Person3")); - assertEquals(1, count); + assertThat(count).isEqualTo(1); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanWithDnAnnotationsITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanWithDnAnnotationsITest.java index 8aefe529..cd89aca5 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanWithDnAnnotationsITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanWithDnAnnotationsITest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2013 the original author or authors. + * Copyright 2005-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,15 +21,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTest; import org.springframework.ldap.itest.odm.PersonWithDnAnnotations; import org.springframework.ldap.itest.repositories.PersonWithDnAnnotationsRepository; -import org.springframework.ldap.query.LdapQueryBuilder; import org.springframework.ldap.support.LdapUtils; import org.springframework.test.context.ContextConfiguration; import java.util.Arrays; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.ldap.query.LdapQueryBuilder.query; /** @@ -52,33 +49,33 @@ public class RepositoryScanWithDnAnnotationsITest extends AbstractLdapTemplateIn person.setCountry("Sweden"); person.setCompany("company1"); - assertNull(person.getDn()); + assertThat(person.getDn()).isNull(); tested.save(person); - assertNotNull(person.getDn()); + assertThat(person.getDn()).isNotNull(); - assertEquals(6, tested.count()); + assertThat(tested.count()).isEqualTo(6); person = tested.findOne(query().where("cn").is("New Person")); - assertEquals("New Person", person.getCommonName()); - assertEquals("Person", person.getSurname()); - assertEquals("This is the description", person.getDesc().get(0)); - assertEquals("0123456", person.getTelephoneNumber()); + assertThat(person.getCommonName()).isEqualTo("New Person"); + assertThat(person.getSurname()).isEqualTo("Person"); + assertThat(person.getDesc().get(0)).isEqualTo("This is the description"); + assertThat(person.getTelephoneNumber()).isEqualTo("0123456"); } @Test public void verifyThatMovedEntryGetsUpdatedId() { PersonWithDnAnnotations found = tested.findOne(query().where("cn").is("Some Person3")); - assertNotNull(found); + assertThat(found).isNotNull(); - assertEquals(LdapUtils.newLdapName("cn=Some Person3,ou=company1,ou=Sweden"), found.getDn()); + assertThat(found.getDn()).isEqualTo(LdapUtils.newLdapName("cn=Some Person3,ou=company1,ou=Sweden")); found.setCompany("company2"); tested.save(found); - assertEquals(LdapUtils.newLdapName("cn=Some Person3,ou=company2,ou=Sweden"), found.getDn()); + assertThat(found.getDn()).isEqualTo(LdapUtils.newLdapName("cn=Some Person3,ou=company2,ou=Sweden")); } }