#125 - Polishing.

Use AssertJ for assertions.
Adjust copyright.

Original pull request: #126.
This commit is contained in:
Jens Schauder
2020-11-09 15:17:24 +01:00
parent 322c8b5ba3
commit 16fe0db465
6 changed files with 27 additions and 30 deletions

View File

@@ -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

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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);
;
}
}

View File

@@ -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.