All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.test.stg Maven / Gradle / Ivy

Go to download

The goal of Quality-Immutable-Object is to provide a small Java library that generates automatically an immutable object class and corresponding builder based on an Java interface (only with accessor methods).

The newest version!
immutableTestCompilationUnit(settings) ::= <<


import static org.junit.Assert.*;
import java.util.*;
import org.junit.Test;
import net.sf.qualitycheck.exception.IllegalNullArgumentException;
import net.sf.qualitycheck.exception.IllegalNegativeArgumentException;





>>

immutableTestClass(settings) ::= <<
public final class Test {

	

	
	
	
	
	
	
	

}
>>

importStatement(i) ::= <<
import .;
>>


annotateTest() ::= <<
@Test
>>
annotateTestWithExpected(className) ::= <<
@Test(expected = .class)
>>

preconditionTests(settings) ::= <<

	
}>
>>

equalsBuilderTest(className) ::= <<

public void blueprintEqualsBuilder() {
	final  blueprint = new Blueprint().build();
	final . builder = new .(); 

	
	
	final  obj = builder.build();
	assertEquals(blueprint, obj);

}
>>

nullablilityTest(field, settings) ::= <<

public void precondition_() {
	new Blueprint().(null).build();
}
>>
negativeNumberTest(field, settings) ::= <<

public void precondition_() {
	new Blueprint().().build();
}
>>
negativeNumberValue(field) ::= <<
-1d-1f-1-1l-1
>>
callBuilderMethods(varName, settings) ::= <<

}>
>>
callSingleBuilderMethod(varName, field, settings) ::= <<

	.();

	// TODO: Fix setter name, capitalization is not yet supported	
	.();

>>
setter(fieldname) ::= <%
set
%>
defaultValue(field) ::= <<
false000d0f00l0"test"null
>>

copyOfTests(settings) ::= <<


public void copyOf_argIsNull() {
	.copyOf(null);
}


public void copyOf_successful() {
	assertNotNull(.copyOf(new Blueprint().build()));
}

>>

equalsAndHashCodeTests(settings) ::= <<

}>




public void equals_identical() {
	 a = new Blueprint().build();
	 b = new Blueprint().build();
	assertEquals(a, b);
	assertTrue(a.hashCode() == b.hashCode());
}


public void equals_null() {
	 a = new Blueprint().build();
	assertFalse(a.equals(null));
}


public void equals_otherClass() {
	 a = new Blueprint().build();
	assertFalse(a.equals(""));
}


public void equals_same() {
	 a = new Blueprint().build();
	assertEquals(a, a);
	assertSame(a, a);
	assertTrue(a.hashCode() == a.hashCode());
}

>>




equalsAndHashCodeTest(field, settings) ::= <<

public void equals_different_() {
	// TODO test equality and hash-code if field '' is different
	}; separator="\n">
	 a = new Blueprint().().build();
	 b = new Blueprint().().build();
	assertFalse(a.equals(b));
	assertFalse(a.hashCode() == b.hashCode());
}
>>

importedType(type) ::= <<
\<\>
>>


package(package) ::= <<
package ;
>>










blueprintClass(settings) ::= <<
private static final class Blueprint {

	

	public Blueprint() {
		// default constructor
	}

	

	

}
>>
annotate(annotation) ::= <<
@
>>
annotateNonnull(settings) ::= <<
@Nonnull
>>
annotateNotThreadSafe(settings) ::= <<
@NotThreadSafe
>>
setupField(field) ::= <<
private   = ; // TODO you must setup a default value for all test cases

>>
buildMethod(settings) ::= <<

public  build() {
	return new ();
}
>>
buildMethodAttribute(field) ::= <<

>>
mutatorMethods(settings) ::= <<
}>
>>
mutatorMethod(field, settings) ::= <<

public Blueprint (final  ) {
	this. = ;
	return this;
}

>>






© 2015 - 2025 Weber Informatics LLC | Privacy Policy