mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-20 18:24:15 +00:00
deps: Refactor dependencies (#3224)
* remove spring dep move junit, logging, mockito under dep mgmt * upgrade anti-corruption-layer deps * async method invocation * balking, bloc * bridge to bytecode * caching * callback - cqrs * component - health check * hexagonal - metadata mapping * rest of the patterns * remove checkstyle, take spotless into use
This commit is contained in:
@@ -35,8 +35,11 @@ import org.junit.jupiter.api.Test;
|
||||
* tests, so they're easier to read, maintain and enhance.
|
||||
*
|
||||
* <p>It breaks tests down into three clear and distinct steps:
|
||||
*
|
||||
* <p>1. Arrange: Perform the setup and initialization required for the test.
|
||||
*
|
||||
* <p>2. Act: Take action(s) required for the test.
|
||||
*
|
||||
* <p>3. Assert: Verify the outcome(s) of the test.
|
||||
*
|
||||
* <p>This pattern has several significant benefits. It creates a clear separation between a test's
|
||||
@@ -48,53 +51,52 @@ import org.junit.jupiter.api.Test;
|
||||
* clearly about the three steps your test will perform. But it makes tests more natural to write at
|
||||
* the same time since you already have an outline.
|
||||
*
|
||||
* <p>In ({@link CashAAATest}) we have four test methods. Each of them has only one reason to
|
||||
* change and one reason to fail. In a large and complicated code base, tests that honor the single
|
||||
* <p>In ({@link CashAAATest}) we have four test methods. Each of them has only one reason to change
|
||||
* and one reason to fail. In a large and complicated code base, tests that honor the single
|
||||
* responsibility principle are much easier to troubleshoot.
|
||||
*/
|
||||
|
||||
class CashAAATest {
|
||||
|
||||
@Test
|
||||
void testPlus() {
|
||||
//Arrange
|
||||
// Arrange
|
||||
var cash = new Cash(3);
|
||||
//Act
|
||||
// Act
|
||||
cash.plus(4);
|
||||
//Assert
|
||||
// Assert
|
||||
assertEquals(7, cash.count());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMinus() {
|
||||
//Arrange
|
||||
// Arrange
|
||||
var cash = new Cash(8);
|
||||
//Act
|
||||
// Act
|
||||
var result = cash.minus(5);
|
||||
//Assert
|
||||
// Assert
|
||||
assertTrue(result);
|
||||
assertEquals(3, cash.count());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInsufficientMinus() {
|
||||
//Arrange
|
||||
// Arrange
|
||||
var cash = new Cash(1);
|
||||
//Act
|
||||
// Act
|
||||
var result = cash.minus(6);
|
||||
//Assert
|
||||
// Assert
|
||||
assertFalse(result);
|
||||
assertEquals(1, cash.count());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdate() {
|
||||
//Arrange
|
||||
// Arrange
|
||||
var cash = new Cash(5);
|
||||
//Act
|
||||
// Act
|
||||
cash.plus(6);
|
||||
var result = cash.minus(3);
|
||||
//Assert
|
||||
// Assert
|
||||
assertTrue(result);
|
||||
assertEquals(8, cash.count());
|
||||
}
|
||||
|
||||
@@ -37,23 +37,22 @@ import org.junit.jupiter.api.Test;
|
||||
* single responsibility principle. If this test method failed after a small code change, it might
|
||||
* take some digging to discover why.
|
||||
*/
|
||||
|
||||
class CashAntiAAATest {
|
||||
|
||||
@Test
|
||||
void testCash() {
|
||||
//initialize
|
||||
// initialize
|
||||
var cash = new Cash(3);
|
||||
//test plus
|
||||
// test plus
|
||||
cash.plus(4);
|
||||
assertEquals(7, cash.count());
|
||||
//test minus
|
||||
// test minus
|
||||
cash = new Cash(8);
|
||||
assertTrue(cash.minus(5));
|
||||
assertEquals(3, cash.count());
|
||||
assertFalse(cash.minus(6));
|
||||
assertEquals(3, cash.count());
|
||||
//test update
|
||||
// test update
|
||||
cash.plus(5);
|
||||
assertTrue(cash.minus(5));
|
||||
assertEquals(3, cash.count());
|
||||
|
||||
Reference in New Issue
Block a user