[EGIT PATCH2/2] fixed-toString-for-CommitTimeRevFilter-wrote-JUnit-tests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>From 72dd9d071ce140f267b8b4effd34d122627135e6 Mon Sep 17 00:00:00 2001
From: Mark Struberg <struberg@xxxxxxxx>
Date: Mon, 15 Jun 2009 08:07:53 +0200
Subject: [PATCH] fixed toString for CommitTimeRevFilter + wrote JUnit tests for after, before and between walks

---
 .../spearce/jgit/revwalk/RevWalkFilterTest.java    |   62 ++++++++++++++++++++
 .../jgit/revwalk/filter/CommitTimeRevFilter.java   |   21 +++++--
 2 files changed, 78 insertions(+), 5 deletions(-)

diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/revwalk/RevWalkFilterTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/revwalk/RevWalkFilterTest.java
index 6a26d2e..c9ed18c 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/revwalk/RevWalkFilterTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/revwalk/RevWalkFilterTest.java
@@ -38,11 +38,13 @@
 package org.spearce.jgit.revwalk;
 
 import java.io.IOException;
+import java.util.Date;
 
 import org.spearce.jgit.errors.IncorrectObjectTypeException;
 import org.spearce.jgit.errors.MissingObjectException;
 import org.spearce.jgit.errors.StopWalkException;
 import org.spearce.jgit.revwalk.filter.AndRevFilter;
+import org.spearce.jgit.revwalk.filter.CommitTimeRevFilter;
 import org.spearce.jgit.revwalk.filter.NotRevFilter;
 import org.spearce.jgit.revwalk.filter.OrRevFilter;
 import org.spearce.jgit.revwalk.filter.RevFilter;
@@ -215,6 +217,66 @@ public void testFilter_NO_MERGES() throws Exception {
 		assertCommit(a, rw.next());
 		assertNull(rw.next());
 	}
+	
+	public void testCommitTimeRevFilter() throws Exception {
+		final RevCommit a = commit();
+		tick(100);
+		
+		final RevCommit b = commit(a);
+		tick(100);
+		
+		Date since = new Date(nowTick);
+		final RevCommit c1 = commit(b);
+		tick(100);
+
+		final RevCommit c2 = commit(b);
+		tick(100);
+
+		Date until =  new Date(nowTick);
+		final RevCommit d = commit(c1, c2);
+		tick(100);
+
+		final RevCommit e = commit(d);
+
+		{
+			RevFilter after = CommitTimeRevFilter.after(since);
+			assertNotNull(after);
+			System.out.println(after.toString());
+			rw.setRevFilter(after);
+			markStart(e);
+			assertCommit(e, rw.next());
+			assertCommit(d, rw.next());
+			assertCommit(c2, rw.next());
+			assertCommit(c1, rw.next());
+			assertNull(rw.next());
+		}
+		
+		{
+			RevFilter before = CommitTimeRevFilter.before(until);
+			assertNotNull(before);
+			System.out.println(before.toString());
+			rw.reset();
+			rw.setRevFilter(before);
+			markStart(e);
+			assertCommit(c2, rw.next());
+			assertCommit(c1, rw.next());
+			assertCommit(b, rw.next());
+			assertCommit(a, rw.next());
+			assertNull(rw.next());
+		}
+
+		{
+			RevFilter between = CommitTimeRevFilter.between(since, until);
+			assertNotNull(between);
+			System.out.println(between.toString());
+			rw.reset();
+			rw.setRevFilter(between);
+			markStart(e);
+			assertCommit(c2, rw.next());
+			assertCommit(c1, rw.next());
+			assertNull(rw.next());
+		}
+	}
 
 	private static class MyAll extends RevFilter {
 		@Override
diff --git a/org.spearce.jgit/src/org/spearce/jgit/revwalk/filter/CommitTimeRevFilter.java b/org.spearce.jgit/src/org/spearce/jgit/revwalk/filter/CommitTimeRevFilter.java
index 0aaa78d..2af9862 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/revwalk/filter/CommitTimeRevFilter.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/revwalk/filter/CommitTimeRevFilter.java
@@ -93,11 +93,6 @@ public RevFilter clone() {
 		return this;
 	}
 
-	@Override
-	public String toString() {
-		return super.toString() + "(" + new Date(when * 1000) + ")";
-	}
-
 	private static class Before extends CommitTimeRevFilter {
 		Before(final long ts) {
 			super(ts);
@@ -109,6 +104,11 @@ public boolean include(final RevWalk walker, final RevCommit cmit)
 				IncorrectObjectTypeException, IOException {
 			return cmit.getCommitTime() <= when;
 		}
+
+		@Override
+		public String toString() {
+			return super.toString() + "(" + new Date(when * 1000L) + ")";
+		}
 	}
 
 	private static class After extends CommitTimeRevFilter {
@@ -128,6 +128,11 @@ public boolean include(final RevWalk walker, final RevCommit cmit)
 				throw StopWalkException.INSTANCE;
 			return true;
 		}
+
+		@Override
+		public String toString() {
+			return super.toString() + "(" + new Date(when * 1000L) + ")";
+		}
 	}
 
 	private static class Between extends CommitTimeRevFilter {
@@ -144,6 +149,12 @@ public boolean include(final RevWalk walker, final RevCommit cmit)
 				IncorrectObjectTypeException, IOException {
 			return cmit.getCommitTime() <= until && cmit.getCommitTime() >= when;
 		}
+
+		@Override
+		public String toString() {
+			return super.toString() + "(" + new Date(when * 1000L) + " - " + new Date(until * 1000L) + ")";
+		}
+
 	}
 
 }
-- 
1.6.0.6



      
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]