Merge branch 'master' of https://github.com/eugenp/tutorials into BAEL-15959
This commit is contained in:
commit
c676d35ab8
@ -54,3 +54,15 @@ class BankAccountCopyConstructor extends BankAccount {
|
|||||||
this.balance = 0.0f;
|
this.balance = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class BankAccountChainedConstructors extends BankAccount {
|
||||||
|
public BankAccountChainedConstructors(String name, LocalDateTime opened, double balance) {
|
||||||
|
this.name = name;
|
||||||
|
this.opened = opened;
|
||||||
|
this.balance = balance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BankAccountChainedConstructors(String name) {
|
||||||
|
this(name, LocalDateTime.now(), 0.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
package com.baeldung.constructors;
|
package com.baeldung.constructors;
|
||||||
|
|
||||||
import com.baeldung.constructors.*;
|
import com.google.common.collect.Comparators;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.Month;
|
import java.time.Month;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
||||||
|
|
||||||
public class ConstructorUnitTest {
|
public class ConstructorUnitTest {
|
||||||
final static Logger LOGGER = Logger.getLogger(ConstructorUnitTest.class.getName());
|
final static Logger LOGGER = Logger.getLogger(ConstructorUnitTest.class.getName());
|
||||||
@ -17,7 +16,9 @@ public class ConstructorUnitTest {
|
|||||||
@Test
|
@Test
|
||||||
public void givenNoExplicitContructor_whenUsed_thenFails() {
|
public void givenNoExplicitContructor_whenUsed_thenFails() {
|
||||||
BankAccount account = new BankAccount();
|
BankAccount account = new BankAccount();
|
||||||
assertThatThrownBy(() -> { account.toString(); }).isInstanceOf(Exception.class);
|
assertThatThrownBy(() -> {
|
||||||
|
account.toString();
|
||||||
|
}).isInstanceOf(Exception.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -50,4 +51,13 @@ public class ConstructorUnitTest {
|
|||||||
|
|
||||||
assertThat(newAccount.getBalance()).isEqualTo(0.0f);
|
assertThat(newAccount.getBalance()).isEqualTo(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenChainedConstructor_whenUsed_thenMaintainsLogic() {
|
||||||
|
BankAccountChainedConstructors account = new BankAccountChainedConstructors("Tim");
|
||||||
|
BankAccountChainedConstructors newAccount = new BankAccountChainedConstructors("Tim", LocalDateTime.now(), 0.0f);
|
||||||
|
|
||||||
|
assertThat(account.getName()).isEqualTo(newAccount.getName());
|
||||||
|
assertThat(account.getBalance()).isEqualTo(newAccount.getBalance());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,12 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-log4j2</artifactId>
|
<artifactId>spring-boot-starter-log4j2</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.4</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- for Graylog demo -->
|
<!-- for Graylog demo -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.baeldung.springbootlogging;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
//import lombok.extern.log4j.Log4j2;
|
||||||
|
//import lombok.extern.apachecommons.CommonsLog;
|
||||||
|
|
||||||
|
@RestController("LombokLoggingController")
|
||||||
|
@Slf4j
|
||||||
|
// @CommonsLog (Comment any other Lombok logging annotation and uncomment this
|
||||||
|
// to work with Apache Commons Logging)
|
||||||
|
// @Log4j2 (Comment any other Lombok logging annotation and uncomment this to
|
||||||
|
// work directly with Log4j2)
|
||||||
|
public class LombokLoggingController {
|
||||||
|
|
||||||
|
@GetMapping("/lombok")
|
||||||
|
public String index() {
|
||||||
|
log.trace("A TRACE Message");
|
||||||
|
log.debug("A DEBUG Message");
|
||||||
|
log.info("An INFO Message");
|
||||||
|
log.warn("A WARN Message");
|
||||||
|
log.error("An ERROR Message");
|
||||||
|
return "Howdy! Check out the Logs to see the output...";
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user