Skip to content

Commit

Permalink
- Remove public and private modifiers from test classes
Browse files Browse the repository at this point in the history
- Remove `SpringExtension` from test classes, `@SpringBootTest` is enough
  • Loading branch information
vicziani committed Jun 12, 2022
1 parent f1fcc3f commit 7ab2c9f
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 29 deletions.
2 changes: 0 additions & 2 deletions src/main/java/com/learnwebservices/LearnWebservicesApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public void setupBus() {
@Bean
public Endpoint endpoint(HelloEndpoint helloEndpoint) {
EndpointImpl endpoint = new EndpointImpl(bus, helloEndpoint);
endpoint.setPublishedEndpointUrl(environment.getProperty("publish.url.prefix") + "/services/hello");
endpoint.publish("/hello");
return endpoint;
}
Expand All @@ -57,7 +56,6 @@ public Endpoint endpoint(HelloEndpoint helloEndpoint) {
public Endpoint publishedTempConverterEndpoint(TempConverterEndpoint tempConverterEndpoint) {
EndpointImpl endpoint = new EndpointImpl(bus, tempConverterEndpoint);
endpoint.setOutFaultInterceptors(List.of(new FaultInterceptor()));
endpoint.setPublishedEndpointUrl(environment.getProperty("publish.url.prefix") + "/services/tempconverter");
endpoint.publish("/tempconverter");
return endpoint;
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
publish.url.prefix = http://localhost:8080

management.endpoints.web.exposure.include = info,health

logging.level.com.learnwebservices = debug
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

public class HelloEndpointTest {
class HelloEndpointTest {

@Test
public void testSayHello() {
void testSayHello() {
var helloEndpoint = new SimpleHelloEndpoint();
var response = helloEndpoint.sayHello(new HelloRequest("John Doe"));
assertEquals("Hello John Doe!", response.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;


@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class HelloIT {
class HelloIT {

@LocalServerPort
private int port;
int port;

@Test
public void testHello() {
void testHello() {
var proxyFactory = new JaxWsProxyFactoryBean();
proxyFactory.setServiceClass(HelloEndpoint.class);
proxyFactory.setAddress("http://localhost:" + port + "/services/hello");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
public class TempConverterEndpointTest {
class TempConverterEndpointTest {

@Mock
private TempConverterService tempConverterService;
TempConverterService tempConverterService;

@InjectMocks
private DelegatingTempConverterEndpoint tempConverterEndpoint;
DelegatingTempConverterEndpoint tempConverterEndpoint;

@Test
public void testConvertToFahrenheit() {
void testConvertToFahrenheit() {
when(tempConverterService.convertFahrenheitToCelsius(anyDouble())).thenReturn(-17.778);

var response =
Expand All @@ -31,7 +31,7 @@ public void testConvertToFahrenheit() {
}

@Test
public void testConvertToCelsius() {
void testConvertToCelsius() {
when(tempConverterService.convertCelsiusToFahrenheit(anyDouble())).thenReturn(32.0);

CelsiusToFahrenheitResponse response =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,21 @@
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;

@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class TempConverterIT {
class TempConverterIT {

@LocalServerPort
private int port;
int port;

private TempConverterEndpoint endpoint;
TempConverterEndpoint endpoint;

@BeforeEach
public void init() {
void init() {
var proxyFactory = new JaxWsProxyFactoryBean();
proxyFactory.setServiceClass(TempConverterEndpoint.class);
proxyFactory.setAddress("http://localhost:" + port + "/services/tempconverter");
Expand All @@ -29,13 +26,13 @@ public void init() {
}

@Test
public void testConvertToCelsius() {
void testConvertToCelsius() {
var request = new FahrenheitToCelsiusRequest(0);
assertEquals(-17.778, endpoint.convertToCelsius(request).getTemperatureInCelsius(), 0.0005);
}

@Test
public void testConvertToFahrenheit() {
void testConvertToFahrenheit() {
var request = new CelsiusToFahrenheitRequest(0);
assertEquals(32.0, endpoint.convertToFahrenheit(request).getTemperatureInFahrenheit(), 0.00005);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

public class TempConverterServiceTest {
class TempConverterServiceTest {

private TempConverterService tempConverterService = new TempConverterService();
TempConverterService tempConverterService = new TempConverterService();

@Test
public void testConvert() {
void testConvert() {
assertEquals(-28.889, tempConverterService.convertFahrenheitToCelsius(-20), 0.0005);
assertEquals(-17.778, tempConverterService.convertFahrenheitToCelsius(0), 0.0005);
assertEquals(4.4444, tempConverterService.convertFahrenheitToCelsius(40), 0.00005);
Expand Down

0 comments on commit 7ab2c9f

Please sign in to comment.