init
This commit is contained in:
parent
255ae3b234
commit
af38c30c00
|
@ -14,6 +14,19 @@
|
|||
<relativePath>../../parent-java</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>${h2.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<h2.version>1.4.199</h2.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<finalName>core-java-lang-oop-2</finalName>
|
||||
<resources>
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package com.baeldung.accessmodifiers;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class Student {
|
||||
|
||||
private BigDecimal grades; //new representation
|
||||
private String name;
|
||||
private int age;
|
||||
|
||||
public int getGrades() {
|
||||
return grades.intValue(); //Backward compatibility
|
||||
}
|
||||
|
||||
public Connection getConnection() throws SQLException {
|
||||
|
||||
final String URL = "jdbc:h2:~/test";
|
||||
return DriverManager.getConnection(URL, "sa", "");
|
||||
|
||||
}
|
||||
|
||||
public BigDecimal bigDecimalGrades() {
|
||||
return grades;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
if (age < 0 || age > 150)
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.baeldung.accessmodifiers;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@TestInstance(Lifecycle.PER_CLASS)
|
||||
public class PublicAccessModifierTest {
|
||||
|
||||
@Test
|
||||
public void whenUsingIntValue_valuesAreEqual() {
|
||||
|
||||
assertEquals(0, new BigDecimal(0).intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingToLowerCase_valuesAreEqual() {
|
||||
|
||||
assertEquals("alex", "ALEX".toLowerCase());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenConnectingToH2_connectionInstanceIsReturned() throws SQLException {
|
||||
|
||||
final String URL = "jdbc:h2:~/test";
|
||||
Connection conn = DriverManager.getConnection(URL, "sa", "");
|
||||
assertNotNull(conn);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue