[JAVA-621] core-java-lang-oop-constructors module
* Creation * Moved code from https://www.baeldung.com/java-constructors * Moved code from https://www.baeldung.com/java-copy-constructor * Moved code from https://www.baeldung.com/java-cannot-reference-x-before-supertype-constructor-error * Moved article references to the new README.md
This commit is contained in:
parent
e25ce92d5e
commit
117cb9ce46
|
@ -4,15 +4,12 @@ This module contains articles about Object-oriented programming (OOP) in Java
|
|||
|
||||
### Relevant Articles:
|
||||
- [Generic Constructors in Java](https://www.baeldung.com/java-generic-constructors)
|
||||
- [Cannot Reference “X” Before Supertype Constructor Has Been Called](https://www.baeldung.com/java-cannot-reference-x-before-supertype-constructor-error)
|
||||
- [Anonymous Classes in Java](https://www.baeldung.com/java-anonymous-classes)
|
||||
- [Raw Types in Java](https://www.baeldung.com/raw-types-java)
|
||||
- [Marker Interfaces in Java](https://www.baeldung.com/java-marker-interfaces)
|
||||
- [Java equals() and hashCode() Contracts](https://www.baeldung.com/java-equals-hashcode-contracts)
|
||||
- [Immutable Objects in Java](https://www.baeldung.com/java-immutable-object)
|
||||
- [Inheritance and Composition (Is-a vs Has-a relationship) in Java](https://www.baeldung.com/java-inheritance-composition)
|
||||
- [A Guide to Constructors in Java](https://www.baeldung.com/java-constructors)
|
||||
- [Static and Default Methods in Interfaces in Java](https://www.baeldung.com/java-static-default-methods)
|
||||
- [Java Copy Constructor](https://www.baeldung.com/java-copy-constructor)
|
||||
- [Abstract Classes in Java](https://www.baeldung.com/java-abstract-class)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-lang-oop)[[More -->]](/core-java-modules/core-java-lang-oop-3)
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
## Core Java Lang OOP - Constructors
|
||||
|
||||
This module contains article about constructors in Java
|
||||
|
||||
### Relevant Articles:
|
||||
- [A Guide to Constructors in Java](https://www.baeldung.com/java-constructors)
|
||||
- [Java Copy Constructor](https://www.baeldung.com/java-copy-constructor)
|
||||
- [Cannot Reference “X” Before Supertype Constructor Has Been Called](https://www.baeldung.com/java-cannot-reference-x-before-supertype-constructor-error)
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>core-java-lang-oop-modules</artifactId>
|
||||
<groupId>com.baeldung.core-java-lang-oop-modules</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>core-java-lang-oop-constructors</artifactId>
|
||||
<name>core-java-lang-oop-constructors</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj-core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<assertj-core.version>3.10.0</assertj-core.version>
|
||||
</properties>
|
||||
</project>
|
|
@ -54,7 +54,6 @@ class BankAccountCopyConstructor extends BankAccount {
|
|||
this.balance = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
class BankAccountChainedConstructors extends BankAccount {
|
||||
public BankAccountChainedConstructors(String name, LocalDateTime opened, double balance) {
|
||||
this.name = name;
|
|
@ -1,20 +1,19 @@
|
|||
package com.baeldung.constructors;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Month;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ConstructorUnitTest {
|
||||
final static Logger LOGGER = Logger.getLogger(ConstructorUnitTest.class.getName());
|
||||
|
||||
@Test
|
||||
public void givenNoExplicitContructor_whenUsed_thenFails() {
|
||||
BankAccount account = new BankAccount();
|
||||
assertThatThrownBy(() -> {
|
||||
Assertions.assertThatThrownBy(() -> {
|
||||
account.toString();
|
||||
}).isInstanceOf(Exception.class);
|
||||
}
|
||||
|
@ -22,7 +21,7 @@ public class ConstructorUnitTest {
|
|||
@Test
|
||||
public void givenNoArgumentConstructor_whenUsed_thenSucceeds() {
|
||||
BankAccountEmptyConstructor account = new BankAccountEmptyConstructor();
|
||||
assertThatCode(() -> {
|
||||
Assertions.assertThatCode(() -> {
|
||||
account.toString();
|
||||
}).doesNotThrowAnyException();
|
||||
}
|
||||
|
@ -33,7 +32,7 @@ public class ConstructorUnitTest {
|
|||
BankAccountParameterizedConstructor account =
|
||||
new BankAccountParameterizedConstructor("Tom", opened, 1000.0f);
|
||||
|
||||
assertThatCode(() -> {
|
||||
Assertions.assertThatCode(() -> {
|
||||
account.toString();
|
||||
}).doesNotThrowAnyException();
|
||||
}
|
|
@ -9,7 +9,12 @@
|
|||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>core-java-oop-modules</artifactId>
|
||||
|
||||
<groupId>com.baeldung.core-java-lang-oop-modules</groupId>
|
||||
<artifactId>core-java-lang-oop-modules</artifactId>
|
||||
<name>core-java-lang-oop-modules</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>core-java-lang-oop-constructors</module>
|
||||
</modules>
|
||||
</project>
|
Loading…
Reference in New Issue