Finished libpit 1.1.0. Added change operations (priority, category, etc)
Began unit testing of libpit. Made most of the changes to pit-cli needed to incorporate the new libpit features.
This commit is contained in:
@ -14,6 +14,12 @@
|
||||
<fileset dir="${lib.dir}">
|
||||
<include name="**/*.jar"/>
|
||||
</fileset>
|
||||
<pathelement path="${build.dir}/classes"/>
|
||||
</path>
|
||||
|
||||
<path id="test.classpath">
|
||||
<path refid="groovyc.classpath"/>
|
||||
<pathelement path="${build.dir}/tests"/>
|
||||
</path>
|
||||
|
||||
<taskdef name="groovyc"
|
||||
@ -68,7 +74,27 @@
|
||||
classpathref="groovyc.classpath"/>
|
||||
</target>
|
||||
|
||||
<target name="build" depends="compile">
|
||||
<target name="compile-tests" depends="init,compile">
|
||||
<mkdir dir="${build.dir}/tests"/>
|
||||
<groovyc
|
||||
srcdir="${test.dir}"
|
||||
destdir="${build.dir}/tests"
|
||||
classpathref="groovyc.classpath"/>
|
||||
</target>
|
||||
|
||||
<target name="run-tests" depends="compile-tests">
|
||||
<junit fork="yes" haltonfailure="yes">
|
||||
<classpath refid="test.classpath"/>
|
||||
<formatter type="brief" usefile="false" />
|
||||
<batchtest>
|
||||
<fileset dir="${build.dir}/tests">
|
||||
<include name="**/*.class"/>
|
||||
</fileset>
|
||||
</batchtest>
|
||||
</junit>
|
||||
</target>
|
||||
|
||||
<target name="build" depends="compile,run-tests">
|
||||
<mkdir dir="${build.dir}/jar"/>
|
||||
<jar
|
||||
destfile="${build.dir}/jar/pit-${application.version}.${build.number.final}.jar"
|
||||
|
@ -1,8 +1,10 @@
|
||||
#Mon Feb 15 21:53:26 CST 2010
|
||||
expected.application.version=1.1.0
|
||||
build.number=2
|
||||
src.dir=src
|
||||
release.dir=release
|
||||
#Thu Feb 18 10:56:00 CST 2010
|
||||
build.dir=build
|
||||
src.dir=src
|
||||
lib.shared.dir=../shared-libs
|
||||
test.dir=test
|
||||
build.number=58
|
||||
expected.application.version=1.1.0
|
||||
lib.dir=lib
|
||||
release.dir=release
|
||||
release.jar=pit-${application.version}.jar
|
||||
|
BIN
libpit/release/pit-1.1.0.jar
Normal file
BIN
libpit/release/pit-1.1.0.jar
Normal file
Binary file not shown.
@ -11,4 +11,6 @@ public enum Category {
|
||||
if (c.toString().startsWith(s.toUpperCase())) return c
|
||||
throw new IllegalArgumentException("No category matches ${s}.")
|
||||
}
|
||||
|
||||
public String getSymbol() { toString()[0].toLowerCase() }
|
||||
}
|
||||
|
@ -7,8 +7,11 @@ class Filter {
|
||||
List<String> ids = null
|
||||
int priority = 9
|
||||
boolean acceptProjects = true
|
||||
Closure projectSorter
|
||||
Closure issueSorter
|
||||
Closure projectSorter = defaultIssueSorter
|
||||
Closure issueSorter = defaultProjectSorter
|
||||
|
||||
public static Closure defaultIssueSorter = { it.id.toInteger() }
|
||||
public static Closure defaultProjectSorter = { it.name }
|
||||
|
||||
public boolean accept(Issue i) {
|
||||
return (i.priority <= priority &&
|
||||
|
@ -26,16 +26,22 @@ public class Issue {
|
||||
|
||||
void setCategory(Category c) {
|
||||
this.category = c
|
||||
source.renameTo(getFilename())
|
||||
source.renameTo(new File(source.canonicalFile.parentFile, getFilename()))
|
||||
}
|
||||
|
||||
void setPriority(int p) {
|
||||
if (p < 0) priority = 0
|
||||
else if (p > 9) priority = 9
|
||||
else priority = p
|
||||
source.renameTo(getFilename())
|
||||
source.renameTo(new File(source.canonicalFile.parentFile, getFilename()))
|
||||
}
|
||||
|
||||
String getFilename() { return id + category.symbol + priority + ".rst"; }
|
||||
String getFilename() { return makeFilename(id, category, priority) }
|
||||
|
||||
static String makeFilename(String id, Category category, int priority) {
|
||||
return id + category.symbol + priority + ".rst";
|
||||
}
|
||||
|
||||
@Override
|
||||
String toString() { return "${id}(${priority}): ${category} ${title}" }
|
||||
}
|
||||
|
@ -38,16 +38,26 @@ class Project {
|
||||
}
|
||||
}
|
||||
|
||||
public void rename(String newName) { source.renameTo(newName) }
|
||||
public void rename(String newName) {
|
||||
this.name = newName
|
||||
source.renameTo(new File(source.canonicalFile.parentFile, newName))
|
||||
}
|
||||
|
||||
public void setName(String name) { rename(name) }
|
||||
|
||||
public void eachIssue(Closure c) {
|
||||
for (i in issues.values()) c.call(i)
|
||||
for (p in projects.values()) p.eachIssue(c)
|
||||
public void eachIssue(Filter filter = null, Closure c) {
|
||||
def sorter = filter?.issueSorter ?: Filter.defaultIssueSorter
|
||||
for (i in issues.values().sort(sorter)) c.call(i)
|
||||
}
|
||||
|
||||
public void eachProject(Filter filter = null, Closure c) {
|
||||
def sorter = filter?.projectSorter ?: Filter.defaultProjectSorter
|
||||
for (p in projects.values().sort(sorter)) c.call(p)
|
||||
}
|
||||
|
||||
public void each(Filter filter = null, Closure c) {
|
||||
def is = filter?.issueSorter ?: { it.id.toInteger() }
|
||||
def ps = filter?.projectSorter ?: { it.name }
|
||||
def is = filter?.issueSorter ?: Filter.defaultIssueSorter
|
||||
def ps = filter?.projectSorter ?: Filter.defaultProjectSorter
|
||||
|
||||
for (issue in issues.values().sort(is)) {
|
||||
if (filter && !filter.accept(issue))
|
||||
@ -61,23 +71,25 @@ class Project {
|
||||
return
|
||||
|
||||
c.call(project)
|
||||
project.each(c)
|
||||
}
|
||||
}
|
||||
|
||||
public void list(Map options = [:]) {
|
||||
if (!options.offset) options.offset = ""
|
||||
if (!options.verbose) options.verbose = false
|
||||
public Issue createNewIssue(Map options) {
|
||||
if (!options.category) options.category = Category.TASK
|
||||
if (!options.priority) options.priority = 5
|
||||
if (!options.text) options.text = "Default issue title.\n" +
|
||||
"====================\n"
|
||||
String id = (issues.values().max { it.id.toInteger() }).id
|
||||
|
||||
each(options.filter) {
|
||||
if (it instanceof Project) {
|
||||
println "\n${options.offset}${it.name}"
|
||||
println "${options.offset}${'-'.multiply(it.name.length())}"
|
||||
} else {
|
||||
println "${options.offset}${it.id}(${it.priority}): " +
|
||||
"${it.category} ${it.title}"
|
||||
if (options.verbose) println "\n${it.text}"
|
||||
}
|
||||
}
|
||||
def issueFile = new File(source, Issue.makeFilename(id, options.category, options.priority))
|
||||
assert !issueFile.exists()
|
||||
issueFile.createNewFile()
|
||||
issueFile.write(options.text)
|
||||
|
||||
return new Issue(issueFile)
|
||||
}
|
||||
|
||||
@Override
|
||||
String toString() { return name }
|
||||
|
||||
}
|
||||
|
12
libpit/test/com/jdbernard/pit/FilterTest.groovy
Normal file
12
libpit/test/com/jdbernard/pit/FilterTest.groovy
Normal file
@ -0,0 +1,12 @@
|
||||
package com.jdbernard.pit
|
||||
|
||||
import org.junit.Test
|
||||
import static org.junit.Assert.assertTrue
|
||||
|
||||
class FilterTest {
|
||||
|
||||
@Test void emptyTest() {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,10 @@
|
||||
package com.jdbernard.pit
|
||||
|
||||
class IssueTest
|
||||
import org.junit.*
|
||||
import static org.junit.Assert.assertTrue
|
||||
import static org.junit.Assert.assertFalse
|
||||
|
||||
class IssueTest {
|
||||
|
||||
def issues
|
||||
File testDir
|
||||
@ -23,43 +27,60 @@ class IssueTest
|
||||
issueFile.write(
|
||||
"Obtain donuts.\n" +
|
||||
"==============\n\n" +
|
||||
"The office is seriously lacking in sugary donuts.\n\n
|
||||
"The office is seriously lacking in sugary donuts.\n\n" +
|
||||
"We must rectify this at once!")
|
||||
issues << new Issue(issueFile)
|
||||
}
|
||||
|
||||
@AfterClass void deleteIssueFiles() {
|
||||
@After void deleteIssueFiles() {
|
||||
testDir.deleteDir()
|
||||
}
|
||||
|
||||
@Test void testSetCategory() {
|
||||
|
||||
assert issues[0].category == Category.FEATURE
|
||||
assert issues[1].category == Category.TASK
|
||||
assertTrue issues[0].category == Category.FEATURE
|
||||
assertTrue issues[1].category == Category.TASK
|
||||
|
||||
issues[0].category == Category.CLOSED
|
||||
issues[1].category == Category.TASK
|
||||
issues[0].category = Category.CLOSED
|
||||
issues[1].category = Category.BUG
|
||||
|
||||
assert issues[0].category == Category.CLOSED
|
||||
assert issues[1].category == Category.BUG
|
||||
assertTrue issues[0].category == Category.CLOSED
|
||||
assertTrue issues[1].category == Category.BUG
|
||||
|
||||
assert new File(testDir, '0001c1.rst').exists()
|
||||
assert new File(testDir, '0002b5.rst').exists()
|
||||
assertTrue new File(testDir, '0001c1.rst').exists()
|
||||
assertTrue new File(testDir, '0002b5.rst').exists()
|
||||
assertFalse new File(testDir, '0001f1.rst').exists()
|
||||
assertFalse new File(testDir, '0002t5.rst').exists()
|
||||
}
|
||||
|
||||
@Test void testIssueConstructor() {
|
||||
@Test void testSetPriority() {
|
||||
|
||||
assertTrue issues[0].priority == 1
|
||||
assertTrue issues[1].priority == 5
|
||||
|
||||
issues[0].priority = 2
|
||||
issues[1].priority = 9
|
||||
|
||||
assertTrue issues[0].priority == 2
|
||||
assertTrue issues[1].priority == 9
|
||||
|
||||
assertTrue new File(testDir, '0001f2.rst').exists()
|
||||
assertTrue new File(testDir, '0002t9.rst').exists()
|
||||
assertFalse new File(testDir, '0001f1.rst').exists()
|
||||
assertFalse new File(testDir, '0002t5.rst').exists()
|
||||
}
|
||||
|
||||
@Test void testConstruction() {
|
||||
File issueFile = new File(testDir, '0001f1.rst')
|
||||
Issue issue = new Issue(issueFile)
|
||||
|
||||
assert issue.id == "0001"
|
||||
assert issue.category == Category.FEATURE
|
||||
assert issue.priority == 1
|
||||
assert issue.title == "Add the killer feature to the killer app."
|
||||
assert issue.text == "Add the killer feature to the killer app.\n" +
|
||||
assertTrue issue.id == "0001"
|
||||
assertTrue issue.category == Category.FEATURE
|
||||
assertTrue issue.priority == 1
|
||||
assertTrue issue.title == "Add the killer feature to the killer app."
|
||||
assertTrue issue.text == "Add the killer feature to the killer app.\n" +
|
||||
"=========================================\n\n" +
|
||||
"Make our killer app shine!."
|
||||
assert issue.source == issueFile
|
||||
assertTrue issue.source == issueFile
|
||||
}
|
||||
}
|
||||
|
115
libpit/test/com/jdbernard/pit/ProjectTest.groovy
Normal file
115
libpit/test/com/jdbernard/pit/ProjectTest.groovy
Normal file
@ -0,0 +1,115 @@
|
||||
package com.jdbernard.pit
|
||||
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import static org.junit.Assert.assertTrue
|
||||
import static org.junit.Assert.assertFalse
|
||||
|
||||
class ProjectTest {
|
||||
|
||||
File testDir
|
||||
Project rootProj
|
||||
|
||||
@Before void createTestProjects() {
|
||||
testDir = new File('testdir')
|
||||
testDir.mkdirs()
|
||||
|
||||
def issueFile = new File(testDir, '0001t5.rst')
|
||||
issueFile.createNewFile()
|
||||
issueFile.write('Test Issue 1\n' +
|
||||
'============\n\n' +
|
||||
'This is the first test issue.')
|
||||
|
||||
issueFile = new File(testDir, '0002b5.rst')
|
||||
issueFile.createNewFile()
|
||||
issueFile.write('Test Bug\n' +
|
||||
'========\n\n' +
|
||||
'Yeah, it is a test bug.')
|
||||
|
||||
issueFile = new File(testDir, '0003f2.rst')
|
||||
issueFile.createNewFile()
|
||||
issueFile.write('Important Feature Request\n' +
|
||||
'=========================\n\n' +
|
||||
'Here is our sweet feature. Please implement it!')
|
||||
|
||||
def subDir = new File(testDir, 'subproj1')
|
||||
subDir.mkdirs()
|
||||
|
||||
issueFile = new File(subDir, '0001f3.rst')
|
||||
issueFile.createNewFile()
|
||||
issueFile.write('First feature in subproject\n' +
|
||||
'===========================\n\n' +
|
||||
'Please make the grubblers grobble.')
|
||||
|
||||
issueFile = new File(subDir, '0002b4.rst')
|
||||
issueFile.createNewFile()
|
||||
issueFile.write('Zippners are not zippning.\n' +
|
||||
'==========================\n\n' +
|
||||
'For some reason, the Zippners are bilperring, not zippning.')
|
||||
|
||||
rootProj = new Project(testDir)
|
||||
}
|
||||
|
||||
@After void deleteTestProjects() {
|
||||
testDir.delete()
|
||||
}
|
||||
|
||||
@Test void testConstruction() {
|
||||
Project proj = new Project(testDir, null)
|
||||
|
||||
assertTrue proj.name == 'testdir'
|
||||
assertTrue proj.issues.size() == 3
|
||||
assertTrue proj.projects.size() == 1
|
||||
|
||||
// Issue construction in general is under test in IssueTest
|
||||
// just check that the issues actually exists
|
||||
assertTrue proj.issues['0001'].id == '0001'
|
||||
assertTrue proj.issues['0001'].title == 'Test Issue 1'
|
||||
|
||||
assertTrue proj.issues['0002'].id == '0002'
|
||||
assertTrue proj.issues['0002'].title == 'Test Bug'
|
||||
|
||||
assertTrue proj.issues['0003'].id == '0003'
|
||||
assertTrue proj.issues['0003'].title == 'Important Feature Request'
|
||||
|
||||
// check sub-project behaviour
|
||||
assertTrue proj.projects.subproj1 != null
|
||||
assertTrue proj.projects.subproj1.name == 'subproj1'
|
||||
assertTrue proj.projects.subproj1.issues.size() == 2
|
||||
assertTrue proj.projects.subproj1.projects.size() == 0
|
||||
assertTrue proj.projects.subproj1.issues['0001'].id == '0001'
|
||||
assertTrue proj.projects.subproj1.issues['0001'].title == 'First feature in subproject'
|
||||
assertTrue proj.projects.subproj1.issues['0002'].id == '0002'
|
||||
assertTrue proj.projects.subproj1.issues['0002'].title == 'Zippners are not zippning.'
|
||||
}
|
||||
|
||||
@Test void testRename() {
|
||||
assert rootProj.name == 'testdir'
|
||||
|
||||
rootProj.rename('renamedTestDir')
|
||||
|
||||
assertTrue rootProj.name == 'renamedTestDir'
|
||||
assertTrue new File('renamedTestDir').exists()
|
||||
}
|
||||
|
||||
/*@Test void testEachIssue() {
|
||||
def expectedList = [rootProj.issues['0001'],
|
||||
rootProj.issues['0002'], rootProj.issues['0003']]
|
||||
|
||||
// sort using default ordering (ids ascending)
|
||||
def actualList = []
|
||||
rootProj.eachIssue { actualList << it }
|
||||
|
||||
assertArrayEquals expectedList, actualList
|
||||
|
||||
// sort using reverse ordering (ids descending)
|
||||
expectedList = expectedList.reverse()
|
||||
actualList = []
|
||||
|
||||
rootProj.eachIssue(
|
||||
new Filter(issueSorter: { -(it.id.toInteger()) }))
|
||||
{ actualList << it }
|
||||
}*/
|
||||
|
||||
}
|
Reference in New Issue
Block a user