Skip to content

Commit

Permalink
Switch to JUnit 5 in the core projects
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffgbutler committed Jul 12, 2018
1 parent 9c63347 commit 1d9344a
Show file tree
Hide file tree
Showing 78 changed files with 993 additions and 581 deletions.
21 changes: 18 additions & 3 deletions core/mybatis-generator-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,24 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2006-2017 the original author or authors.
* Copyright 2006-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -78,7 +78,7 @@ public String getTargetProject() {
*/
@Override
public String toString() {
return getFormattedContent();
return getFileName();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@
*/
package org.mybatis.generator;

import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.*;

import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.mybatis.generator.api.GeneratedJavaFile;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
Expand All @@ -34,17 +32,11 @@
import com.github.javaparser.JavaParser;
import com.github.javaparser.ParseProblemException;

@RunWith(Parameterized.class)
public class JavaCodeGenerationTest {

private GeneratedJavaFile generatedJavaFile;

public JavaCodeGenerationTest(GeneratedJavaFile generatedJavaFile) {
this.generatedJavaFile = generatedJavaFile;
}

@Test
public void testJavaParse() {
@ParameterizedTest
@MethodSource("generateJavaFiles")
public void testJavaParse(GeneratedJavaFile generatedJavaFile) {
ByteArrayInputStream is = new ByteArrayInputStream(
generatedJavaFile.getCompilationUnit().getFormattedContent().getBytes());
try {
Expand All @@ -54,7 +46,6 @@ public void testJavaParse() {
}
}

@Parameters
public static List<GeneratedJavaFile> generateJavaFiles() throws Exception {
List<GeneratedJavaFile> generatedFiles = new ArrayList<>();
generatedFiles.addAll(generateJavaFilesMybatis());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/
package org.mybatis.generator;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.*;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.ConnectionFactoryConfiguration;
Expand All @@ -33,24 +33,24 @@

public class MyBatisGeneratorTest {

@Test(expected = InvalidConfigurationException.class)
@Test
public void testGenerateMyBatis3WithInvalidConfig() throws Exception {
List<String> warnings = new ArrayList<>();
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(this.getClass().getClassLoader().getResourceAsStream("generatorConfigMyBatis3_badConfig.xml"));

DefaultShellCallback shellCallback = new DefaultShellCallback(true);

try {
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
myBatisGenerator.generate(null, null, null, false);
} catch (InvalidConfigurationException e) {
assertEquals(2, e.getErrors().size());
throw e;
}
InvalidConfigurationException e =
assertThrows(InvalidConfigurationException.class, () -> {
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
myBatisGenerator.generate(null, null, null, false);
});

assertEquals(2, e.getErrors().size());
}

@Test(expected = InvalidConfigurationException.class)
@Test
public void testGenerateInvalidConfigWithNoConnectionSources() throws Exception {
List<String> warnings = new ArrayList<>();
Configuration config = new Configuration();
Expand All @@ -60,16 +60,15 @@ public void testGenerateInvalidConfigWithNoConnectionSources() throws Exception

DefaultShellCallback shellCallback = new DefaultShellCallback(true);

try {
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
myBatisGenerator.generate(null, null, null, false);
} catch (InvalidConfigurationException e) {
assertEquals(3, e.getErrors().size());
throw e;
}
InvalidConfigurationException e =
assertThrows(InvalidConfigurationException.class, () -> {
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
myBatisGenerator.generate(null, null, null, false);
});
assertEquals(3, e.getErrors().size());
}

@Test(expected = InvalidConfigurationException.class)
@Test
public void testGenerateInvalidConfigWithTwoConnectionSources() throws Exception {
List<String> warnings = new ArrayList<>();
Configuration config = new Configuration();
Expand All @@ -81,12 +80,11 @@ public void testGenerateInvalidConfigWithTwoConnectionSources() throws Exception

DefaultShellCallback shellCallback = new DefaultShellCallback(true);

try {
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
myBatisGenerator.generate(null, null, null, false);
} catch (InvalidConfigurationException e) {
assertEquals(3, e.getErrors().size());
throw e;
}
InvalidConfigurationException e =
assertThrows(InvalidConfigurationException.class, () -> {
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
myBatisGenerator.generate(null, null, null, false);
});
assertEquals(3, e.getErrors().size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.mybatis.generator;

import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.*;

import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand All @@ -25,10 +25,8 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.mybatis.generator.api.GeneratedXmlFile;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
Expand All @@ -40,17 +38,11 @@
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

@RunWith(Parameterized.class)
public class XmlCodeGenerationTest {

private GeneratedXmlFile generatedXmlFile;

public XmlCodeGenerationTest(GeneratedXmlFile generatedXmlFile) {
this.generatedXmlFile = generatedXmlFile;
}

@Test
public void testXmlParse() {
@ParameterizedTest
@MethodSource("generateXmlFiles")
public void testXmlParse(GeneratedXmlFile generatedXmlFile) {
ByteArrayInputStream is = new ByteArrayInputStream(
generatedXmlFile.getFormattedContent().getBytes());
try {
Expand All @@ -65,7 +57,6 @@ public void testXmlParse() {
}
}

@Parameters
public static List<GeneratedXmlFile> generateXmlFiles() throws Exception {
List<GeneratedXmlFile> generatedFiles = new ArrayList<>();
generatedFiles.addAll(generateXmlFilesMybatis());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
*/
package org.mybatis.generator.api;

import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;

import org.hamcrest.core.Is;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mybatis.generator.config.DomainObjectRenamingRule;

public class FullyQualifiedTableTest {
Expand All @@ -27,14 +26,14 @@ public class FullyQualifiedTableTest {
public void testNormalCase() {
FullyQualifiedTable fqt = new FullyQualifiedTable(null, "myschema", "mytable", null, null, false, null, null, null, false, null, null);

assertThat(fqt.getDomainObjectName(), Is.is("Mytable"));
assertThat(fqt.getDomainObjectName()).isEqualTo("Mytable");
}

@Test
public void testNormalCaseWithPrefix() {
FullyQualifiedTable fqt = new FullyQualifiedTable(null, "myschema", "sys_mytable", null, null, false, null, null, null, false, null, null);

assertThat(fqt.getDomainObjectName(), Is.is("SysMytable"));
assertThat(fqt.getDomainObjectName()).isEqualTo("SysMytable");
}

@Test
Expand All @@ -44,7 +43,7 @@ public void testRenamingRule() {
renamingRule.setReplaceString("");
FullyQualifiedTable fqt = new FullyQualifiedTable(null, "myschema", "sys_mytable", null, null, false, null, null, null, false, renamingRule, null);

assertThat(fqt.getDomainObjectName(), Is.is("Mytable"));
assertThat(fqt.getDomainObjectName()).isEqualTo("Mytable");
}

@Test
Expand All @@ -54,6 +53,6 @@ public void testRenamingRuleNoUnderscore() {
renamingRule.setReplaceString("");
FullyQualifiedTable fqt = new FullyQualifiedTable(null, "myschema", "sysmytable", null, null, false, null, null, null, false, renamingRule, null);

assertThat(fqt.getDomainObjectName(), Is.is("Mytable"));
assertThat(fqt.getDomainObjectName()).isEqualTo("Mytable");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2006-2017 the original author or authors.
* Copyright 2006-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,8 +15,9 @@
*/
package org.mybatis.generator.api;

import static org.junit.Assert.*;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.mybatis.generator.api.dom.DefaultJavaFormatter;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.api.dom.java.Interface;
Expand All @@ -30,8 +31,8 @@ public void testReqularInterface() {
JavaFormatter jf = new DefaultJavaFormatter();
GeneratedJavaFile gjf = new GeneratedJavaFile(ifc, "src", jf);

assertEquals("TestInterface.java", gjf.getFileName());
assertEquals("org.mybatis.test", gjf.getTargetPackage());
assertThat(gjf.getFileName()).isEqualTo("TestInterface.java");
assertThat(gjf.getTargetPackage()).isEqualTo("org.mybatis.test");
}

@Test
Expand All @@ -42,7 +43,7 @@ public void testGenericInterface() {
JavaFormatter jf = new DefaultJavaFormatter();
GeneratedJavaFile gjf = new GeneratedJavaFile(ifc, "src", jf);

assertEquals("TestInterface.java", gjf.getFileName());
assertEquals("org.mybatis.test", gjf.getTargetPackage());
assertThat(gjf.getFileName()).isEqualTo("TestInterface.java");
assertThat(gjf.getTargetPackage()).isEqualTo("org.mybatis.test");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@
*/
package org.mybatis.generator.api.dom.java;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

import java.util.Set;
import java.util.TreeSet;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mybatis.generator.api.dom.OutputUtilities;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;

/**
* @author Jeff Butler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2006-2016 the original author or authors.
* Copyright 2006-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,9 +15,9 @@
*/
package org.mybatis.generator.api.dom.java;

import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;

import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;

public class InnerClassTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2006-2017 the original author or authors.
* Copyright 2006-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,14 +15,9 @@
*/
package org.mybatis.generator.api.dom.java;

import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;

import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import org.junit.jupiter.api.Test;

public class InnerInterfaceTest {

Expand Down
Loading

0 comments on commit 1d9344a

Please sign in to comment.