diff --git a/jpa/jpa21/src/main/java/example/springdata/jpa/fetchgraph/FetchGraphConfiguration.java b/jpa/jpa21/src/main/java/example/springdata/jpa/fetchgraph/FetchGraphConfiguration.java index 56b54d18..067e5261 100644 --- a/jpa/jpa21/src/main/java/example/springdata/jpa/fetchgraph/FetchGraphConfiguration.java +++ b/jpa/jpa21/src/main/java/example/springdata/jpa/fetchgraph/FetchGraphConfiguration.java @@ -1,11 +1,11 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2020 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 + * https://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, @@ -18,6 +18,8 @@ package example.springdata.jpa.fetchgraph; import org.springframework.boot.autoconfigure.SpringBootApplication; /** + * Application configuration for fetch graph tests. + * * @author Thomas Darimont */ @SpringBootApplication diff --git a/jpa/jpa21/src/main/java/example/springdata/jpa/fetchgraph/Product.java b/jpa/jpa21/src/main/java/example/springdata/jpa/fetchgraph/Product.java index 019c079d..55a47853 100644 --- a/jpa/jpa21/src/main/java/example/springdata/jpa/fetchgraph/Product.java +++ b/jpa/jpa21/src/main/java/example/springdata/jpa/fetchgraph/Product.java @@ -1,11 +1,11 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2020 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 + * https://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, diff --git a/jpa/jpa21/src/main/java/example/springdata/jpa/fetchgraph/ProductRepository.java b/jpa/jpa21/src/main/java/example/springdata/jpa/fetchgraph/ProductRepository.java index 1a552a9e..3ec1108c 100644 --- a/jpa/jpa21/src/main/java/example/springdata/jpa/fetchgraph/ProductRepository.java +++ b/jpa/jpa21/src/main/java/example/springdata/jpa/fetchgraph/ProductRepository.java @@ -1,11 +1,11 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2020 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 + * https://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, diff --git a/jpa/jpa21/src/main/java/example/springdata/jpa/fetchgraph/Tag.java b/jpa/jpa21/src/main/java/example/springdata/jpa/fetchgraph/Tag.java index d2ebf600..916bb04b 100644 --- a/jpa/jpa21/src/main/java/example/springdata/jpa/fetchgraph/Tag.java +++ b/jpa/jpa21/src/main/java/example/springdata/jpa/fetchgraph/Tag.java @@ -1,11 +1,11 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2020 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 + * https://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, diff --git a/jpa/jpa21/src/test/java/example/springdata/jpa/fetchgraph/FetchGraphIntegrationTests.java b/jpa/jpa21/src/test/java/example/springdata/jpa/fetchgraph/FetchGraphIntegrationTests.java index 12d165e5..b9b3c2d7 100644 --- a/jpa/jpa21/src/test/java/example/springdata/jpa/fetchgraph/FetchGraphIntegrationTests.java +++ b/jpa/jpa21/src/test/java/example/springdata/jpa/fetchgraph/FetchGraphIntegrationTests.java @@ -1,11 +1,11 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2020 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 + * https://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, @@ -15,14 +15,13 @@ */ package example.springdata.jpa.fetchgraph; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.assertj.core.api.Assertions.*; import java.util.Collections; import javax.persistence.EntityManager; -import org.junit.Assert; +import org.hibernate.LazyInitializationException; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -34,6 +33,7 @@ import org.springframework.transaction.annotation.Transactional; * Integration test showing the usage of JPA 2.1 fetch graph support through Spring Data JPA repositories. * * @author Thomas Darimont + * @author Jens Schauder */ @RunWith(SpringRunner.class) @Transactional @@ -58,17 +58,14 @@ public class FetchGraphIntegrationTests { Product loadedXps = repository.findById(xps.getId()).get(); em.detach(loadedXps); - try { - loadedXps.getTags().toString(); - fail("Expected LazyInitializationException to occur when trying to access uninitialized association 'tags'."); - } catch (Exception expected) { - System.out.println(expected.getMessage()); - } + assertThatExceptionOfType(LazyInitializationException.class) + .as("Expected LazyInitializationException to occur when trying to access uninitialized association 'tags'.") + .isThrownBy(() -> loadedXps.getTags().toString()); - // here we use the findOneById that uses a NamedEntityGraph + // here we use the findWithNamedEntityGraphById that uses a NamedEntityGraph Product loadedXpsWithFetchGraph = repository.findWithNamedEntityGraphById(xps.getId()); - Assert.assertThat(loadedXpsWithFetchGraph.getTags(), hasSize(3)); + assertThat(loadedXpsWithFetchGraph.getTags()).hasSize(3); } @Test @@ -85,16 +82,14 @@ public class FetchGraphIntegrationTests { Product loadedXps = repository.findById(xps.getId()).get(); em.detach(loadedXps); - try { - loadedXps.getTags().toString(); - fail("Expected LazyInitializationException to occur when trying to access uninitialized association 'tags'."); - } catch (Exception expected) { - System.out.println(expected.getMessage()); - } + assertThatExceptionOfType(LazyInitializationException.class) + .as("Expected LazyInitializationException to occur when trying to access uninitialized association 'tags'.") + .isThrownBy(() -> loadedXps.getTags().toString()); - // here we use getOneById which uses an ad-hoc declarative fetch graph definition + // here we use findWithAdhocEntityGraphById which uses an ad-hoc declarative fetch graph definition Product loadedXpsWithFetchGraph = repository.findWithAdhocEntityGraphById(xps.getId()); - Assert.assertThat(loadedXpsWithFetchGraph.getTags(), hasSize(3)); + assertThat(loadedXpsWithFetchGraph.getTags()).hasSize(3); + ; } } diff --git a/jpa/jpa21/src/test/java/example/springdata/jpa/storedprocedures/UserRepositoryIntegrationTests.java b/jpa/jpa21/src/test/java/example/springdata/jpa/storedprocedures/UserRepositoryIntegrationTests.java index 4501d8bb..0f586ac1 100644 --- a/jpa/jpa21/src/test/java/example/springdata/jpa/storedprocedures/UserRepositoryIntegrationTests.java +++ b/jpa/jpa21/src/test/java/example/springdata/jpa/storedprocedures/UserRepositoryIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2018 the original author or authors. + * Copyright 2014-2020 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.