* Added code for checking if a class is abstract or not.

* Renamed test name as per review comments.

* Added code to get database URL from Connection object.

* Refactored code to break lines.
This commit is contained in:
Umang Budhwar 2020-10-16 19:22:25 +05:30 committed by GitHub
parent a1ca807059
commit 5709eee956
4 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,29 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung.core-java-persistence-2</groupId>
<artifactId>core-java-persistence-2</artifactId>
<version>0.1.0-SNAPSHOT</version>
<name>core-java-persistence-2</name>
<packaging>jar</packaging>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>persistence-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
</dependency>
</dependencies>
<properties>
<h2.version>1.4.200</h2.version>
</properties>
</project>

View File

@ -0,0 +1,13 @@
package com.baeldung.getdburl;
import java.sql.Connection;
import java.sql.DriverManager;
public class DBConfiguration {
public static Connection getConnection() throws Exception {
Class.forName("org.h2.Driver");
String url = "jdbc:h2:mem:testdb";
return DriverManager.getConnection(url, "user", "password");
}
}

View File

@ -0,0 +1,18 @@
package com.baeldung.getdburl;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.sql.Connection;
import org.junit.jupiter.api.Test;
class DBConfigurationUnitTest {
@Test
void givenConnectionObject_whenExtractMetaData_thenGetDbURL() throws Exception {
Connection connection = DBConfiguration.getConnection();
String dbUrl = connection.getMetaData().getURL();
assertEquals("jdbc:h2:mem:testdb", dbUrl);
}
}

View File

@ -17,6 +17,7 @@
<module>apache-bookkeeper</module><!-- BAEL-2322 -->
<module>apache-cayenne</module>
<module>core-java-persistence</module>
<module>core-java-persistence-2</module>
<module>deltaspike</module>
<module>elasticsearch</module>
<module>flyway</module>