Skip to content

Commit

Permalink
Prettier formatted content including Java
Browse files Browse the repository at this point in the history
  • Loading branch information
joemoore committed Mar 22, 2024
1 parent e5be85f commit c867cd7
Show file tree
Hide file tree
Showing 12 changed files with 304 additions and 258 deletions.
22 changes: 11 additions & 11 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ diverse, inclusive, and healthy community.
Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
- Demonstrating empathy and kindness toward other people
- Being respectful of differing opinions, viewpoints, and experiences
- Giving and gracefully accepting constructive feedback
- Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall
- Focusing on what is best not just for us as individuals, but for the overall
community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or advances of
- The use of sexualized language or imagery, and sexual attention or advances of
any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email address,
- Trolling, insulting or derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or email address,
without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities
Expand Down Expand Up @@ -104,7 +104,7 @@ Violating these terms may lead to a permanent ban.
### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within the
Expand Down
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

Thanks for your interest in contributing to the Labs Practices Site!


## Code Contributions

If you are interested in contributing new features, bug fixes, or open issues, follow these steps:
Expand All @@ -19,4 +18,4 @@ If you are interested in contributing new features, bug fixes, or open issues, f

## Content Contributions

Your pull requests are welcomed!
Your pull requests are welcomed!
2 changes: 1 addition & 1 deletion content/guides/basics-of-rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ This constraint states that a server can extend the functionality of a client by

## Conclusion

Well, this is the end of this coverage of the basics of REST. Reading Roy Fielding's REST [dissertation](https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm) is a great place to start if you haven't already. If you’d like to start building your own REST APIs and are a Spring developer, be sure to check out [Building a REST API with Spring Boot](https://spring.academy/courses/building-a-rest-api-with-spring-boot) _(note: see [_Edit_](#edit) below)_ to see these principles in action!
Well, this is the end of this coverage of the basics of REST. Reading Roy Fielding's REST [dissertation](https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm) is a great place to start if you haven't already. If you’d like to start building your own REST APIs and are a Spring developer, be sure to check out [Building a REST API with Spring Boot](https://spring.academy/courses/building-a-rest-api-with-spring-boot) _\(note: see [Edit](#edit) below\)_ to see these principles in action!

<a name=edit></a>
_**Edit** March 4, 2024: The article originally referenced was removed during the curation of the Labs Practices Site. Reference changed to the free online course on Spring Academy: [Building a REST API with Spring Boot](https://spring.academy/courses/building-a-rest-api-with-spring-boot). -- Joe Moore_
61 changes: 32 additions & 29 deletions content/guides/consumer-driven-contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,13 @@ You can then provide those base class implementations as such:
@ActiveProfiles("mock")
public abstract class Consumer1HttpBase {

@Autowired
private MockMvc mvc;

@Before
public void test() {
RestAssuredMockMvc.mockMvc(this.mvc);
}
@Autowired
private MockMvc mvc;

@Before
public void test() {
RestAssuredMockMvc.mockMvc(this.mvc);
}
}

@RunWith(SpringRunner.class)
Expand All @@ -97,29 +96,33 @@ public abstract class Consumer1HttpBase {
@ActiveProfiles("mock")
public abstract class Consumer1MessagingBase {

@Autowired
private MockMvc mvc;

@Before
public void test() {
RestAssuredMockMvc.mockMvc(this.mvc);
}

/**
* This method is called from the triggeredBy() method in the contract DSL to
* publish the message to be tested.
*/
public void requestAutoRateApiIsCalled() {
// given:
MockMvcRequestSpecification request = RestAssuredMockMvc.given()
.header("Content-Type", "application/json;charset=UTF-8")
.body("{\"quote\":{\"jurisdiction\":\"NY\",\"policyEffectiveDate\":\"2017-05-25T15:04:05-04:00\",\"policyTransactionType\":\"01\",\"quoteEffectiveDate\":\"2017-05-25T15:04:05-04:00\",\"quoteId\":\"1\"}}");

// when:
ResponseOptions response = RestAssuredMockMvc.given().spec(request)
.post("/rateableQuote");
}
@Autowired
private MockMvc mvc;

@Before
public void test() {
RestAssuredMockMvc.mockMvc(this.mvc);
}

/**
* This method is called from the triggeredBy() method in the contract DSL to
* publish the message to be tested.
*/
public void requestAutoRateApiIsCalled() {
// given:
MockMvcRequestSpecification request = RestAssuredMockMvc.given()
.header("Content-Type", "application/json;charset=UTF-8")
.body(
"{\"quote\":{\"jurisdiction\":\"NY\",\"policyEffectiveDate\":\"2017-05-25T15:04:05-04:00\",\"policyTransactionType\":\"01\",\"quoteEffectiveDate\":\"2017-05-25T15:04:05-04:00\",\"quoteId\":\"1\"}}"
);

// when:
ResponseOptions response = RestAssuredMockMvc.given()
.spec(request)
.post("/rateableQuote");
}
}

```

### Contracts for RESTful APIs
Expand Down
10 changes: 5 additions & 5 deletions content/guides/remote-tips-facillitation.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ level2: Team Tips

- Agree on tools that everyone has access to.
- Agree on how you will communicate, interact, and make decisions. This can be based on user manuals created by each team member:
- Chat tools are used for ****\_**** .
- Email is used for ****\_\_\_**** .
- I tap someone on the shoulder by doing ****\_****.
- Standup is for ****\_**** .
- Stand-down is for ****\_\_\_\_****.
- Chat tools are used for \***\*\_\*\*** .
- Email is used for \***\*\_\_\_\*\*** .
- I tap someone on the shoulder by doing \***\*\_\*\***.
- Standup is for \***\*\_\*\*** .
- Stand-down is for \***\*\_\_\_\_\*\***.
- Clearly set the agenda, desired outcomes and a timebox for each session.
- Agree on hand gestures during video calls.
- Maintain a team decision log.
Expand Down
77 changes: 39 additions & 38 deletions content/guides/spring-boot-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,56 +68,57 @@ You can better isolate the functionality you want to test by limiting the contex
In the very naive code snippet below, there are no database interactions, and MapRepository loads data from the classpath.

```java
import org.junit.Test;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class MapRepositoryTest {

private MapRepository mapRepository = new MapRepository();
private MapRepository mapRepository = new MapRepository();

@Test
public void shouldReturnJurisdictionForZip() {
final String expectedJurisdiction = "NJ";
assertEquals(expectedJurisdiction, mapRepository.findByZip("07677"));
}
@Test
public void shouldReturnJurisdictionForZip() {
final String expectedJurisdiction = "NJ";
assertEquals(expectedJurisdiction, mapRepository.findByZip("07677"));
}
}

```

As a next step up in complexity, consider adding mock frameworks, like those generated by the [Mockito](https://site.mockito.org) mocking framework, if you have interactions with external resources. Using mock frameworks eliminates the need to access real instances of external resources.

```java
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import java.util.Date;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.Date;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

@RunWith(MockitoJUnitRunner.class)
public class CarServiceTest {

private CarService carService;
private CarService carService;

@Mock
private RateFinder rateFinder;
@Mock
private RateFinder rateFinder;

@Before
public void init() {
carService = new CarService(rateFinder);
}
@Before
public void init() {
carService = new CarService(rateFinder);
}

@Test
public void shouldInteractWithRateFinderToFindBestRate() {
carService.schedulePickup(new Date(), new Route());
verify(rateFinder, times(1)).findBestRate(any(Route.class));
}
@Test
public void shouldInteractWithRateFinderToFindBestRate() {
carService.schedulePickup(new Date(), new Route());
verify(rateFinder, times(1)).findBestRate(any(Route.class));
}
}

```

## Only load slices of functionality
Expand All @@ -127,29 +128,29 @@ public class CarServiceTest {
When testing spring boot applications, the `@SpringBootTest` annotation loads the whole application, but it is often better to limit the application context to just the set of Spring components that participate in the test scenario. This is accomplished by listing them in the annotation declaration.

```java
import static org.junit.Assert.assertTrue;

import java.util.Date;
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.test.context.junit4.SpringRunner;

import java.util.Date;

import static org.junit.Assert.assertTrue;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {MapRepository.class, CarService.class})
@SpringBootTest(classes = { MapRepository.class, CarService.class })
public class CarServiceWithRepoTest {

@Autowired
private CarService carService;
@Autowired
private CarService carService;

@Test
public void shouldReturnValidDateInTheFuture() {
Date date = carService.schedulePickup(new Date(), new Route());
assertTrue(date.getTime() > new Date().getTime());
}
@Test
public void shouldReturnValidDateInTheFuture() {
Date date = carService.schedulePickup(new Date(), new Route());
assertTrue(date.getTime() > new Date().getTime());
}
}

```

### @DataJpaTest Annotation
Expand Down
32 changes: 17 additions & 15 deletions content/guides/tanzu-labs-engineer-faq/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,29 +102,31 @@ Conversely, "Is it possible for a story to be too small?". To answer the questio

For example, suppose your story is about authentication:

> _A User can sign in, **_and_** sign out, **_and_** recover their password, **_and_** change their password, **_and_** recover their username_
> A User can sign in, **_and_** sign out, **_and_** recover their password, **_and_** change their password, **_and_** recover their username
Your team collaborates, "How do we make this story smaller and still deliver value to the user?". Together, everyone decides to make smaller stories about authentication. So, now instead of having one large story, you have several smaller ones, including the following:
Your team collaborates, "How do we make this story smaller and still deliver value to the user?"

- _A User can **sign in**_
- _A User can **sign out**_
- _A User can **recover their password**_
- _A User can **change their password**_
- _A User can **recover their username**_
Together, everyone decides to make smaller stories about authentication. So, now instead of having one large story, you have several smaller ones, including the following:

> - A User can **sign in**
> - A User can **sign out**
> - A User can **recover their password**
> - A User can **change their password**
> - A User can **recover their username**
{{% callout %}}
**Tip:** If a user story contains an **_"and"_**, try splitting the story at that point and evaluate whether the two (or more) stories provide value on their own.
{{% /callout %}}

However, the team goes too far in making smaller stories out of bigger ones. They decide to break down _User can sign in_ into the following tiny stories:
However, the team goes too far in making smaller stories out of bigger ones. They decide to break down _User can sign in_ into the following teeny-tiny stories:

- _A User can **view the Username field on the Sign In form**_
- _A User can **view the Password field on the Sign In form**_
- _A User can **view the 'Sign In' button on the Sign In form**_
- _A User can **view the entire Sign In form**_
- _A User can **sign-in using the Sign In form**_
- _A User can **breathe in**_
- _A User can **breathe out...**_
> - A User can **view the Username field on the Sign In form**
> - A User can **view the Password field on the Sign In form**
> - A User can **view the 'Sign In' button on the Sign In form**
> - A User can **view the entire Sign In form**
> - A User can **sign-in using the Sign In form**
> - A User can **breathe in**
> - A User can **breathe out...**
Your team collaborates, "If we complete the two or three stories, is the Sign In form going to provide real value to our users?" The answer is no! Delivering a sign-in form to production that doesn't work does is not going to help your users. If anything, it's more likely to frustrate them, or put the product into an unreleasable state. In this case, _User can sign in_ was an appropriately-sized story.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,15 @@ as the `routes` and `env` labels.
```java
@BeforeEach
public void setUp() throws Exception {
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setUrl(System.getenv("SPRING_DATASOURCE_URL"));
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setUrl(System.getenv("SPRING_DATASOURCE_URL"));
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
jdbcTemplate.execute("TRUNCATE time_entries");
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
jdbcTemplate.execute("TRUNCATE time_entries");
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
}
```
```bash
Expand Down
Loading

0 comments on commit c867cd7

Please sign in to comment.