Skip to content

Commit 52d3dc1

Browse files
committed
Fixing issue with junits - TablesMap retained old data between tests.
1 parent a930053 commit 52d3dc1

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/main/java/org/ngbsn/generator/ModelGenerator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ public static List<Table> parse(final String sqlScript) {
4646
return null;
4747
}
4848

49+
/**
50+
* Clears the tables map. This is needed to have a clean start between junits
51+
*/
52+
public static void clearTablesMap(){
53+
tablesMap.clear();
54+
}
4955
/**
5056
* Iterate over all the Create Table statements and prepare the list of Table Model
5157
* @param statements set of statements

src/test/java/org/ngbsn/maven/CodeGenTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import freemarker.template.TemplateException;
44
import org.apache.commons.io.FileUtils;
5+
import org.junit.Before;
56
import org.junit.Test;
7+
import org.ngbsn.generator.ModelGenerator;
68
import org.slf4j.Logger;
79
import org.slf4j.LoggerFactory;
810

@@ -16,9 +18,14 @@
1618
public class CodeGenTest {
1719
private static final Logger logger = LoggerFactory.getLogger(CodeGenTest.class);
1820

21+
22+
@Before
23+
public void beforeTest(){
24+
ModelGenerator.clearTablesMap();
25+
}
1926
@Test
2027
public void testMySql() throws TemplateException, IOException {
21-
logger.info("Starting test");
28+
logger.info("Starting testMySql");
2229
ClassLoader classLoader = getClass().getClassLoader();
2330
File file = new File(Objects.requireNonNull(classLoader.getResource("sql/mysql.sql")).getFile());
2431
String sqlScript = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
@@ -28,7 +35,7 @@ public void testMySql() throws TemplateException, IOException {
2835

2936
@Test
3037
public void testPostgres() throws TemplateException, IOException {
31-
logger.info("Starting test");
38+
logger.info("Starting testPostgres");
3239
ClassLoader classLoader = getClass().getClassLoader();
3340
File file = new File(Objects.requireNonNull(classLoader.getResource("sql/postgres.sql")).getFile());
3441
String sqlScript = FileUtils.readFileToString(file, StandardCharsets.UTF_8);

0 commit comments

Comments
 (0)