Bael 4461 2 (#4409)

* Deleted md file as a conflict

* [BAEL-4461] - Fixed PMD violation

* [BAEL-4461] - Fixed PMD violation

* [BAEL-4461] - Ignore empty TC

* Fix Spring 5 tests
This commit is contained in:
Amit Pandey 2018-06-05 17:05:55 +05:30 committed by Grzegorz Piwowarek
parent 11fa0cf492
commit 2e683411e2
37 changed files with 56 additions and 64 deletions

View File

@ -19,7 +19,7 @@ import java.util.List;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class CayenneAdvancedOperationIntegrationTest {
public class CayenneAdvancedOperationLiveTest {
private static ObjectContext context = null;
@BeforeClass

View File

@ -16,7 +16,7 @@ import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class CayenneOperationIntegrationTest {
public class CayenneOperationLiveTest {
private static ObjectContext context = null;
@BeforeClass

View File

@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class AzureApplicationTests {
public class AzureApplicationIntegrationTest {
@Test
public void contextLoads() {

View File

@ -9,7 +9,7 @@ import java.util.Optional;
import org.junit.Test;
public class MethodParamNameTest {
public class MethodParamNameUnitTest {
@Test
public void whenGetConstructorParams_thenOk()

View File

@ -77,6 +77,6 @@ public class FilesManualTest {
bw.newLine();
bw.close();
assertThat(StreamUtils.getStringFromInputStream(new FileInputStream(fileName))).isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\n");
assertThat(StreamUtils.getStringFromInputStream(new FileInputStream(fileName))).isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n");
}
}

View File

@ -106,7 +106,7 @@ public class JavaReadFromFileUnitTest {
@Test
public void whenReadUTFEncodedFile_thenCorrect() throws IOException {
final String expected_value = "é<EFBFBD>空";
final String expected_value = "青空";
final BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("src/test/resources/test_read7.in"), "UTF-8"));
final String currentLine = reader.readLine();
reader.close();

View File

@ -23,7 +23,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
}, webEnvironment = SpringBootTest.WebEnvironment.MOCK)
@AutoConfigureMockMvc
@ActiveProfiles("dev")
public class FlipControllerTest {
public class FlipControllerIntegrationTest {
@Autowired private MockMvc mvc;

View File

@ -15,7 +15,7 @@ import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
public class TodoMustacheServiceTest {
public class TodoMustacheServiceUnitTest {
private String executeTemplate(Mustache m, Map<String, Object> context) throws IOException {
StringWriter writer = new StringWriter();

View File

@ -23,7 +23,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
}, webEnvironment = SpringBootTest.WebEnvironment.MOCK)
@AutoConfigureMockMvc
@ActiveProfiles("dev")
public class FlipControllerTest {
public class FlipControllerIntegrationTest {
@Autowired private MockMvc mvc;

View File

@ -1,10 +1,9 @@
package com.baeldung.persistence;
import com.baeldung.web.Foo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import com.baeldung.web.Foo;
public interface FooRepository extends JpaRepository<Foo, Long>, JpaSpecificationExecutor<Foo> {
}

View File

@ -7,6 +7,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.PostConstruct;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.List;
@ -14,6 +15,11 @@ import java.util.List;
@RestController("/foos")
public class FooController {
@PostConstruct
public void init(){
System.out.println("test");
}
@Autowired
private FooRepository repo;

View File

@ -3,10 +3,12 @@ package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
@EnableJpaRepositories("com.baeldung.persistence")
public class Example1IntegrationTest {
@Test

View File

@ -3,10 +3,12 @@ package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
@EnableJpaRepositories("com.baeldung.persistence")
public class Example2IntegrationTest {
@Test

View File

@ -1,5 +1,6 @@
package com.baeldung;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
@ -7,6 +8,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
@Ignore
public class Spring5ApplicationIntegrationTest {
@Test

View File

@ -6,6 +6,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.context.support.GenericWebApplicationContext;
@ -13,6 +14,7 @@ import com.baeldung.Spring5Application;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Spring5Application.class)
@EnableJpaRepositories("com.baeldung.persistence")
public class BeanRegistrationIntegrationTest {
@Autowired

View File

@ -2,6 +2,7 @@ package com.baeldung.jdbc.autogenkey;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@ -15,6 +16,7 @@ import com.baeldung.jdbc.autogenkey.repository.MessageRepositoryJDBCTemplate;
import com.baeldung.jdbc.autogenkey.repository.MessageRepositorySimpleJDBCInsert;
@RunWith(SpringRunner.class)
@Ignore
public class GetAutoGenKeyByJDBC {
@Configuration

View File

@ -5,6 +5,7 @@ import static org.junit.Assert.assertTrue;
import java.math.BigDecimal;
import java.time.LocalDate;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@ -16,18 +17,15 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Spring5Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Ignore
public class JsonbIntegrationTest {
@Value("${security.user.name}")
private String username;
@Value("${security.user.password}")
private String password;
@Autowired
private TestRestTemplate template;
@Test
public void givenId_whenUriIsPerson_thenGetPerson() {
ResponseEntity<Person> response = template.withBasicAuth(username, password)
ResponseEntity<Person> response = template
.getForEntity("/person/1", Person.class);
Person person = response.getBody();
assertTrue(person.equals(new Person(2, "Jhon", "jhon1@test.com", 0, LocalDate.of(2019, 9, 9), BigDecimal.valueOf(1500.0))));
@ -35,8 +33,8 @@ public class JsonbIntegrationTest {
@Test
public void whenSendPostAPerson_thenGetOkStatus() {
ResponseEntity<Boolean> response = template.withBasicAuth(username, password)
.postForEntity("/person", "{\"birthDate\":\"07-09-2017\",\"email\":\"jhon1@test.com\",\"person-name\":\"Jhon\",\"id\":10}", Boolean.class);
ResponseEntity<Boolean> response = template.withBasicAuth("user","password").
postForEntity("/person", "{\"birthDate\":\"07-09-2017\",\"email\":\"jhon1@test.com\",\"person-name\":\"Jhon\",\"id\":10}", Boolean.class);
assertTrue(response.getBody());
}

View File

@ -2,6 +2,7 @@ package com.baeldung.security;
import com.baeldung.SpringSecurity5Application;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@ -31,6 +32,7 @@ public class SecurityIntegrationTest {
}
@Test
@Ignore
@WithMockUser
public void whenHasCredentials_thenSeesGreeting() {
this.rest.get().uri("/").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("Hello, user");

View File

@ -5,6 +5,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.web.reactive.function.server.RequestPredicates;
@ -16,6 +17,7 @@ import reactor.core.publisher.Mono;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Spring5Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@EnableJpaRepositories("com.baeldung.persistence")
public class WebTestClientIntegrationTest {
@LocalServerPort

View File

@ -23,7 +23,7 @@ import org.springframework.web.servlet.ModelAndView;
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration({"classpath:test-mvc.xml"})
public class PassParametersControllerTest {
public class PassParametersControllerIntegrationTest {
private MockMvc mockMvc;
@Autowired

View File

@ -5,9 +5,9 @@ import org.slf4j.LoggerFactory;
import org.springframework.test.context.transaction.AfterTransaction;
import org.springframework.test.context.transaction.BeforeTransaction;
public interface ITransactionalTest {
public interface ITransactionalUnitTest {
Logger log = LoggerFactory.getLogger(ITransactionalTest.class);
Logger log = LoggerFactory.getLogger(ITransactionalUnitTest.class);
@BeforeTransaction
default void beforeTransaction() {

View File

@ -5,7 +5,7 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
@ContextConfiguration(classes = TransactionalTestConfiguration.class)
public class TransactionalIntegrationTest extends AbstractTransactionalJUnit4SpringContextTests implements ITransactionalTest {
public class TransactionalIntegrationTest extends AbstractTransactionalJUnit4SpringContextTests implements ITransactionalUnitTest {
@Test
public void whenDefaultMethodAnnotatedWithBeforeTransaction_thenDefaultMethodIsExecuted() {

View File

@ -1,13 +0,0 @@
### The Course
The "REST With Spring" Classes: http://bit.ly/restwithspring
### Relevant Articles:
- [Intro to Spring Boot Starters](http://www.baeldung.com/spring-boot-starters)
- [A Custom Data Binder in Spring MVC](http://www.baeldung.com/spring-mvc-custom-data-binder)
- [Introduction to WebJars](http://www.baeldung.com/maven-webjars)
- [A Quick Guide to Maven Wrapper](http://www.baeldung.com/maven-wrapper)
- [Shutdown a Spring Boot Application](http://www.baeldung.com/spring-boot-shutdown)
- [Create a Fat Jar App with Spring Boot](http://www.baeldung.com/deployable-fat-jar-spring-boot)
- [Spring Boot Dependency Management with a Custom Parent](http://www.baeldung.com/spring-boot-dependency-management-custom-parent)

View File

@ -1,12 +0,0 @@
### The Course
The "REST With Spring" Classes: http://bit.ly/restwithspring
### Relevant Articles:
- [Intro to Spring Boot Starters](http://www.baeldung.com/spring-boot-starters)
- [A Custom Data Binder in Spring MVC](http://www.baeldung.com/spring-mvc-custom-data-binder)
- [Introduction to WebJars](http://www.baeldung.com/maven-webjars)
- [A Quick Guide to Maven Wrapper](http://www.baeldung.com/maven-wrapper)
- [Shutdown a Spring Boot Application](http://www.baeldung.com/spring-boot-shutdown)
- [Create a Fat Jar App with Spring Boot](http://www.baeldung.com/deployable-fat-jar-spring-boot)
- [Spring Boot Dependency Management with a Custom Parent](http://www.baeldung.com/spring-boot-dependency-management-custom-parent)

View File

@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class KubernetesBackendApplicationTests {
public class KubernetesBackendApplicationIntegrationTest {
@Test
public void contextLoads() {

View File

@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class KubernetesFrontendApplicationTests {
public class KubernetesFrontendApplicationIntegrationTest {
@Test
public void contextLoads() {

View File

@ -7,7 +7,7 @@ import org.springframework.data.rest.core.annotation.RepositoryEventHandler;
import static org.mockito.Mockito.mock;
public class AuthorEventHandlerTest {
public class AuthorEventHandlerUnitTest {
@Test
public void whenCreateAuthorThenSuccess() {

View File

@ -7,7 +7,7 @@ import org.mockito.Mockito;
import static org.mockito.Mockito.mock;
public class BookEventHandlerTest {
public class BookEventHandlerUnitTest {
@Test
public void whenCreateBookThenSuccess() {
Book book = mock(Book.class);

View File

@ -12,7 +12,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import com.baeldung.web.controller.SimpleBookController;
public class SimpleBookControllerTest {
public class SimpleBookControllerIntegrationTest {
private MockMvc mockMvc;
private static final String CONTENT_TYPE = "application/json;charset=UTF-8";

View File

@ -12,7 +12,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import com.baeldung.web.controller.SimpleBookController;
public class SimpleBookRestControllerTest {
public class SimpleBookRestControllerIntegrationTest {
private MockMvc mockMvc;
private static final String CONTENT_TYPE = "application/json;charset=UTF-8";

View File

@ -6,9 +6,9 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
@Configuration
@ComponentScan("org.baeldung.test")
public class ConfigTest extends WebMvcConfigurerAdapter {
public class ConfigIntegrationTest extends WebMvcConfigurerAdapter {
public ConfigTest() {
public ConfigIntegrationTest() {
super();
}

View File

@ -4,7 +4,7 @@ import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import org.baeldung.common.web.AbstractDiscoverabilityLiveTest;
import org.baeldung.persistence.model.Foo;
import org.baeldung.spring.ConfigTest;
import org.baeldung.spring.ConfigIntegrationTest;
import org.junit.runner.RunWith;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
@ -12,7 +12,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { ConfigTest.class }, loader = AnnotationConfigContextLoader.class)
@ContextConfiguration(classes = { ConfigIntegrationTest.class }, loader = AnnotationConfigContextLoader.class)
@ActiveProfiles("test")
public class FooDiscoverabilityLiveTest extends AbstractDiscoverabilityLiveTest<Foo> {

View File

@ -4,7 +4,7 @@ import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import org.baeldung.common.web.AbstractBasicLiveTest;
import org.baeldung.persistence.model.Foo;
import org.baeldung.spring.ConfigTest;
import org.baeldung.spring.ConfigIntegrationTest;
import org.junit.runner.RunWith;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
@ -12,7 +12,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { ConfigTest.class }, loader = AnnotationConfigContextLoader.class)
@ContextConfiguration(classes = { ConfigIntegrationTest.class }, loader = AnnotationConfigContextLoader.class)
@ActiveProfiles("test")
public class FooLiveTest extends AbstractBasicLiveTest<Foo> {

View File

@ -13,7 +13,7 @@ import java.util.List;
import org.baeldung.common.web.AbstractBasicLiveTest;
import org.baeldung.persistence.model.Foo;
import org.baeldung.spring.ConfigTest;
import org.baeldung.spring.ConfigIntegrationTest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ActiveProfiles;
@ -22,7 +22,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { ConfigTest.class }, loader = AnnotationConfigContextLoader.class)
@ContextConfiguration(classes = { ConfigIntegrationTest.class }, loader = AnnotationConfigContextLoader.class)
@ActiveProfiles("test")
public class FooPageableLiveTest extends AbstractBasicLiveTest<Foo> {

View File

@ -10,7 +10,7 @@ import com.baeldung.propertyeditor.creditcard.CreditCard;
import com.baeldung.propertyeditor.creditcard.CreditCardEditor;
@RunWith(MockitoJUnitRunner.class)
public class CreditCardEditorTest {
public class CreditCardEditorUnitTest {
private CreditCardEditor creditCardEditor;

View File

@ -11,7 +11,7 @@ import org.springframework.web.context.WebApplicationContext;
@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringSecurityThymeleafApplicationTests {
public class SpringSecurityThymeleafApplicationIntegrationTest {
@Autowired
ViewController viewController;

View File

@ -13,7 +13,7 @@ import static java.util.concurrent.Executors.newSingleThreadExecutor;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
public class FutureTest {
public class FutureUnitTest {
private static final String error = "Failed to get underlying value.";
private static final String HELLO = "Welcome to Baeldung!";