Skip to content
Permalink
Browse files

[Test Generation] Major Test template refactoring and upgrading Junit…

…-templates to JUnit5 jupiter/jupiter-api
  • Loading branch information
SultanEid committed Mar 10, 2020
1 parent ba0f76b commit 7514bec15074473f77572853151b9f1effa1a55e
@@ -63,7 +63,13 @@ class JUnitGenerator {



import org.junit.*;
import java.sql.Time;
import java.sql.Date;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;

////---- Tests for <<=model.getFile()>>----/////

@@ -9,7 +9,7 @@ This file generates depends classes for test model

for (Depend dep : model.getDepends())
{
appendln(realSb, "import {0};",dep.getName()) ;
appendln(realSb, "//import {0};",dep.getName()) ;
}
appendln(realSb,"");

@@ -6,24 +6,24 @@ members_AllAssertions <<!<</*members_AllAssertions*/>><<#
if(as.getType().equals("assertTrue"))
{
#>>
Assert.assertTrue (<<=as.getAssertCode()>>);
assertTrue (<<=as.getAssertCode()>>);
<<#}

if(as.getType().equals("assertFalse"))
{#>>
Assert.assertFalse (<<=as.getAssertCode()>>);<<#}
assertFalse (<<=as.getAssertCode()>>);<<#}

if(as.getType().equals("assertEqual"))
{#>>
Assert.assertEquals (<<=as.getAssertCode()>>);<<#}
assertEquals (<<=as.getAssertCode()>>);<<#}

if(as.getType().equals("assertNull"))
{#>>
Assert.assertNull (<<=as.getAssertCode()>>);<<#}
assertNull (<<=as.getAssertCode()>>);<<#}

if(as.getType().equals("assertMethod"))
{#>>
UmpleAssert.assertMethod (<<=as.getAssertCode()>>);<<#}
assertMethod (<<=as.getAssertCode()>>);<<#}
#>>
!>>

@@ -48,7 +48,7 @@ else{ #>>
if (act.getLocOrder() == i)
{//include Action Code if there is actions in a TestCAse
#>>
<<=act.getCode()>>
<<=act.getCode()>>;
<<#
}

@@ -2,8 +2,8 @@ class UmpleTToJUnit{

members_Setup <<!<</*members_Setup*/>>

@Before
public void setup(){
@BeforeAll
public static void setup(){

}

@@ -2,8 +2,8 @@ class UmpleTToJUnit{

members_TearDown <<!<</*members_tearDown*/>>

@After
public void teardown(){
@AfterAll
public static void teardown(){


}
@@ -131,7 +131,7 @@ class TestClassGenerator {

#>>

<<=isAbstract>>Test <<=uClass.getName() >> {
<<=isAbstract>>test <<=uClass.getName() >> {

generate <<=unitLanguage>> ;

@@ -71,8 +71,16 @@ class TestModelGenerator {

////---- Tests for <<=model.getUmpleFile().getFileName().subSequence(0, model.getUmpleFile().getFileName().length()-4)>> ----/////

Test <<=model.getUmpleFile().getFileName() >> {
<<@ UmpleToTest.depends >> <<@ UmpleToTest.members_AllAssociations >>
test <<=model.getUmpleFile().getFileName().subSequence(0, model.getUmpleFile().getFileName().length()-4)>> {

generate JUnit;

<<@ UmpleToTest.depends >>

GIVEN:
<<=model.getUmpleFile().getFileName()>>;
THEN:
<<@ UmpleToTest.members_AllAssociations >>


<<#// appendln(realSb, gen.translate("afterCode", uClass));
@@ -16,10 +16,10 @@ This file creates the necessary for Optional One To Many Association

<<=gen.dependencyInjection(av.getRelatedAssociation().getUmpleClass())>>
<<=av.getRelatedAssociation().getUmpleClass().getName()>> <<=gen.initiateClass(av.getRelatedAssociation().getUmpleClass())>>;
<<=buffName>>.add<<=av.getRelatedAssociation().getUmpleClass().getName()>>(<<=buffName2>>);
<<=buffName>>.remove<<=av.getRelatedAssociation().getUmpleClass().getName()>>(<<=buffName2>>);
assertTrue(<<=buffName>>.set<<=av.getRelatedAssociation().getUmpleClass().getName()>>(<<=buffName2>>));
a<<=av.getRelatedAssociation().getUmpleClass().getName()>>.delete();

assertTrue (a<<=av.getUmpleClass().getName()>>.get<<=av.getName()>>At(0) == null);
assertTrue (a<<=av.getUmpleClass().getName()>>.get<<=av.getRelatedAssociation().getUmpleClass().getName()>>() == null);
}


@@ -9,7 +9,7 @@ This file creates the necessary for Optional One To Many Association
/////// Association: -- <<=theirEnd.getMultiplicity().getRange()>> <<=av.getRelatedAssociation().getUmpleClass().getName()>> ///////
//create ... without ...
Test Create<<=uClass.getName()>>Without<<=av.getRelatedAssociation().getUmpleClass().getName()>> {
<<=uClass.getName()>> <<=buffName>> = new <<=uClass.getName()>>(); \n",,));

AssertF (some<<=av.getRelatedAssociation().getUmpleClass().getName()>>.get<<=theirEnd.getRoleName().toUpperCase()>>()!= null);
}
//replace
@@ -7,45 +7,57 @@ This file creates the necessary for Optional One To Many Association


String buffName = "some" +uClass.getName();
String buffName2 = "some"+av.getRelatedAssociation().getUmpleClass().getName();#>>
String buffName2 = "some"+av.getRelatedAssociation().getUmpleClass().getName();
String myClass = uClass.getName();
String otherClass = av.getRelatedAssociation().getUmpleClass().getName();
#>>
/////// Association: -- <<=av.getRelatedAssociation().getMultiplicity().getRange()>> <<=av.getRelatedAssociation().getUmpleClass().getName()>> ///////
//create ... without ...
Test Create<<=uClass.getName()>>Without<<=av.getRelatedAssociation().getUmpleClass().getName()>> {
<<=uClass.getName()>> <<=buffName>> = new <<=uClass.getName()>>();
AssertTrue (some<<=av.getRelatedAssociation().getUmpleClass().getName()>>.get<<=av.getRelatedAssociation().getName().toUpperCase()>>()!= null);
test Create<<=uClass.getName()>>Without<<=av.getRelatedAssociation().getUmpleClass().getName()>> {

<<=gen.dependencyInjection(uClass)>>
<<=uClass.getName()>> <<=gen.initiateClass(uClass)>>;
int size = a<<=myClass>>.get<<=otherClass>>s().size();
assertTrue ( size == 0);

}
//replace
<<#buffName = "some"+av.getRelatedAssociation().getUmpleClass().getName();#>>
Test Replace<<=av.getRelatedAssociation().getUmpleClass().getName()>>In<<=uClass.getName()>> {

<<=av.getRelatedAssociation().getUmpleClass().getName()>> <<=buffName2>> = new <<=av.getRelatedAssociation().getUmpleClass().getName()>>();
<<=av.getRelatedAssociation().getUmpleClass().getName()>> <<=buffName2>>2 = new <<=av.getRelatedAssociation().getUmpleClass().getName()>>();
<<=buffName>>.add<<=av.getRelatedAssociation().getUmpleClass().getName()>>(some<<=av.getUmpleClass().getName()>>);
AssertEqual (1, <<=buffName>>.getNumberOf<<=av.getUmpleClass().getName()>>s());
AssertEqual (1, <<=buffName>>.getNumberOf<<=av.getUmpleClass().getName()>>s());
some<<=av.getUmpleClass().getName()>>.set<<=av.getRelatedAssociation().getUmpleClass().getName()>>(<<=buffName>>2);
AssertEqual (some<<=av.getUmpleClass().getName()>>, <<=buffName>>2.get<<=av.getUmpleClass().getName()>>(0));
test Replace<<=uClass.getName()>>In<<=av.getRelatedAssociation().getUmpleClass().getName()>> {

<<=av.getRelatedAssociation().getUmpleClass().getName()>> <<=gen.initiateClass(av.getRelatedAssociation().getUmpleClass())>>;
<<=av.getRelatedAssociation().getUmpleClass().getName()>> b<<=gen.initiateClass(av.getRelatedAssociation().getUmpleClass())>>;
<<=uClass.getName()>> <<=gen.initiateClass(uClass)>>;
<<=uClass.getName()>> b<<=gen.initiateClass(uClass)>>;


assertTrue(a<<=uClass.getName()>>.add<<=av.getRelatedAssociation().getUmpleClass().getName()>>(a<<=av.getRelatedAssociation().getUmpleClass().getName()>>));
assertEqual ( a<<=myClass>>.get<<=otherClass>>(0),a<<=otherClass>>);

assertTrue(a<<=av.getRelatedAssociation().getUmpleClass().getName()>>.set<<=uClass.getName()>>(ba<<=uClass.getName()>>));
assertTrue ( a<<=av.getRelatedAssociation().getUmpleClass().getName()>>.get<<=uClass.getName()>>() == ba<<=uClass.getName()>>);
}
//delete
Test Delete<<=av.getRelatedAssociation().getUmpleClass().getName()>> {

test delete<<=av.getRelatedAssociation().getUmpleClass().getName()>> {
// delete <<=av.getRelatedAssociation().getUmpleClass().getName()>> in <<=uClass.getName()>>
<<=buffName>>2.delete();
AssertEqual (null, <<=buffName>>2.get<<=av.getUmpleClass().getName()>>(0));


<<=gen.dependencyInjection(av.getRelatedAssociation().getUmpleClass())>>
<<=otherClass>> b<<=gen.initiateClass(av.getRelatedAssociation().getUmpleClass())>>;

<<=gen.dependencyInjection(uClass)>>
<<=uClass.getName()>> <<=gen.initiateClass(uClass)>>;

assertTrue(a<<=myClass>>.add<<=otherClass>>(ba<<=otherClass>>));

ba<<=otherClass>>.delete();

int size = a<<=myClass>>.get<<=otherClass>>s().size();
assertTrue ( size == 0);
}
//add to new B

Test Add<<=av.getRelatedAssociation().getUmpleClass().getName()>>ToNew<<=uClass.getName()>> {
<<=av.getRelatedAssociation().getUmpleClass().getName()>> <<=buffName2>> = new <<=av.getRelatedAssociation().getUmpleClass().getName()>>();
<<=av.getRelatedAssociation().getUmpleClass().getName()>> <<=buffName2>>2 = new <<=av.getRelatedAssociation().getUmpleClass().getName()>>();

<<=av.getUmpleClass().getName()>> some<<=av.getUmpleClass().getName()>> = new <<=av.getUmpleClass().getName()>>();
<<=buffName>>.add<<=av.getRelatedAssociation().getUmpleClass().getName()>>(some<<=av.getRelatedAssociation().getUmpleClass().getName()>>);
<<=buffName>>.add<<=av.getRelatedAssociation().getUmpleClass().getName()>>(some<<=av.getRelatedAssociation().getUmpleClass().getName()>>2);

AssertEqual(some<<=av.getRelatedAssociation().getUmpleClass().getName()>>2, <<=buffName>>.get<<=av.getRelatedAssociation().getUmpleClass().getName()>>();
AssertEqual (<<=buffName>>, some<<=av.getRelatedAssociation().getUmpleClass().getName()>>2.get<<=av.getUmpleClass().getName()>>(0));
AssertEqual (<<=buffName>>, some<<=av.getRelatedAssociation().getUmpleClass().getName()>>.getNumberOf<<=av.getUmpleClass().getName()>>s());
}<<#


<<#


#>>!>>
@@ -4,25 +4,25 @@ attribute_Defaulted <<!<</*attribute_Defaulted*/>><<#

if(at.getType() == "String" || at.getType() == null)
{
AssertTrue( <<=uClass.getName().toLowerCase()>>.get<<=attrName>>(), initialValue##Fix );
AssertTrue( <<=uClass.getName().toLowerCase()>>.set<<=attrName>>("someString123"));
AssertTrue( <<=uClass.getName().toLowerCase()>>.get<<=attrName>>() =="someString123")>>");
AssertTrue( <<=uClass.getName().toLowerCase()>>.reset<<=attrName>>());
AssertFalse( <<=uClass.getName().toLowerCase()>>.get<<=attrName>>(),"randomString123"));
AssertTrue( <<=uClass.getName().toLowerCase()>>.get<<=attrName>>(),initialValue##Fix);
#>assertTrue( a<<=uClass.getName()>>.get<<=attrName>>(), <<=at.getValue()>> );
assertTrue( a<<=uClass.getName()>>.set<<=attrName>>("someString123"));
assertTrue( a<<=uClass.getName()>>.get<<=attrName>>() =="someString123")>>");
assertTrue( a<<=uClass.getName()>>.reset<<=attrName>>());
assertFalse( a<<=uClass.getName()>>.get<<=attrName>>(),"randomString123"));
assertTrue( a<<=uClass.getName()>>.get<<=attrName>>(),<<=at.getValue()>>);
<<#
}

if(at.getType().equals("Double") || at.getType().equals("Integer"))
{#>>
AssertTrue( <<=uClass.getName().toLowerCase()>>.set<<=attrName>>(<<=gen.translate("AttIntManu")>>)));
AssertTrue( <<=uClass.getName().toLowerCase()>>.get<<=attrName>>() == <<=gen.translate("AttIntManu")>>));
assertTrue( a<<=uClass.getName()>>.set<<=attrName>>(<<=gen.translate("AttIntManu")>>)));
assertTrue( a<<=uClass.getName()>>.get<<=attrName>>() == <<=gen.translate("AttIntManu")>>));
<<#}

if(at.getType().equals("Float"))
{#>>
AssertTrue( <<=uClass.getName().toLowerCase()>>.set<<=attrName>>(<<=gen.translate("AttFloatManu")>>)));
AssertTrue( <<=uClass.getName().toLowerCase()>>.get<<=attrName>>() == <<=gen.translate("AttFloatManu")>>));
assertTrue( a<<=uClass.getName()>>.set<<=attrName>>(<<=gen.translate("AttFloatManu")>>)));
assertTrue( a<<=uClass.getName()>>.get<<=attrName>>() == <<=gen.translate("AttFloatManu")>>));
<<#}
/*if(at.getType().equals("Boolean"))
{
@@ -2,8 +2,10 @@ class UmpleToTest{

attribute_Immutable <<!<</*attribute_Immutable*/>>

AssertMethodFalse( <<=uClass.getName().toLowerCase()>>.set<<=attrName>>());
AssertTrue( <<=uClass.getName().toLowerCase()>>.get<<=attrName>>() == <<=at.getValue()>>);
<<=gen.dependencyInjection(uClass)>>
<<=uClass.getName()>> <<=gen.initiateClass(uClass)>>;
//assertMethod(set<<=attrName>>());
assertTrue( a<<=uClass.getName()>>.get<<=attrName>>() == <<=at.getValue()>>);

!>>

@@ -2,25 +2,36 @@ class UmpleToTest{

attribute_Lazy <<!<</*attribute_Lazy*/>>

assertTrue (!<<=at.getName()>>.equals(null));<<#
<<#
//TODO: testGenerator, add assertion for lazy, we want to see if the object has the lazy-specific LOC in the constructor, Note this is still abstrac ( not language oriented)
// AssertLOC : student={ method=Student(), LOC="name = null;"}
#>>assertTrue (a<<=uClass.getName()>>.get<<=attrName>>() == null );<<#

if(at.getType() == "String" || at.getType() == null)
{#>>
assertTrue (<<=uClass.getName()>>.get<<=attrName>>() != null)
if(at.getValue() != "null")
{

}

else {

#>>assertTrue (a<<=uClass.getName()>>.get<<=at.getName()>>() == null );<<#

if(at.getType().equals( "String") || at.getType().equals(null))
{
#>>
assertTrue (a<<=uClass.getName()>>.get<<=attrName>>() == null);
<<#}
if(at.getType() == "Double" || at.getType() == "Integer")
if(at.getType().equals("Double") || at.getType().equals( "Integer"))
{#>>
assertTrue (<<=uClass.getName()>>.get<<=attrName>>() != null)
assertTrue (a<<=uClass.getName()>>.get<<=attrName>>() == null);
<<#}
if(at.getType() == "Float")
{#>>
assertTrue (<<=uClass.getName()>>.get<<=attrName>>() != null)
assertTrue (a<<=uClass.getName()>>.get<<=attrName>>() == null);
<<#}
if(at.getType() == "Boolean")
{#>>
assertTrue (<<=uClass.getName()>>.get<<=attrName>>() != null)
assertTrue (a<<=uClass.getName()>>.get<<=attrName>>() == null);
<<#}

if (at.getType() == "")
@@ -30,6 +41,7 @@ attribute_Lazy <<!<</*attribute_Lazy*/>>

else{

}
}
#>>
!>>

0 comments on commit 7514bec

Please sign in to comment.
You can’t perform that action at this time.