1   /*
2   	StatCvs - CVS statistics generation 
3   	Copyright (C) 2002  Lukasz Pekacki <lukasz@pekacki.de>
4   	http://statcvs.sf.net/
5       
6   	This library is free software; you can redistribute it and/or
7   	modify it under the terms of the GNU Lesser General Public
8   	License as published by the Free Software Foundation; either
9   	version 2.1 of the License, or (at your option) any later version.
10  
11  	This library is distributed in the hope that it will be useful,
12  	but WITHOUT ANY WARRANTY; without even the implied warranty of
13  	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  	Lesser General Public License for more details.
15  
16  	You should have received a copy of the GNU Lesser General Public
17  	License along with this library; if not, write to the Free Software
18  	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20  package net.sf.statsvn.input;
21  
22  import java.util.Date;
23  import java.util.LinkedList;
24  import java.util.Map;
25  
26  import junit.framework.Assert;
27  
28  /**
29   * Mock Object implementing {@link SvnLogBuilder}
30   * 
31   * @author Richard Cyganiak <richard@cyganiak.de>
32   * @version $Id: MockLogBuilder.java,v 1.4 2004/12/14 13:38:13 squig Exp $
33   */
34  public class MockLogBuilder implements SvnLogBuilder {
35  	private final LinkedList expectedMethods = new LinkedList();
36  
37  	private final LinkedList expectedData = new LinkedList();
38  
39  	/*
40  	 *  (non-Javadoc)
41  	 * @see net.sf.statsvn.input.SvnLogBuilder#addToAttic(java.lang.String)
42  	 * @todo implementation
43  	 */
44  	public void addToAttic(final String filename) {
45  	}
46  
47  	/* (non-Javadoc)
48  	 * @see net.sf.statsvn.input.SvnLogBuilder#buildModule(java.lang.String)
49  	 */
50  	public void buildModule(final String moduleName) {
51  		Assert.assertEquals(expectedMethods.removeFirst(), "buildModule");
52  		Assert.assertEquals(expectedData.removeFirst(), moduleName);
53  	}
54  
55  	/* (non-Javadoc)
56  	 * @see net.sf.statsvn.input.SvnLogBuilder#buildFile(java.lang.String, boolean, boolean)
57  	 */
58  	public void buildFile(final String filename, final boolean isBinary, final boolean isInAttic, final Map revBySymnames) {
59  		Assert.assertEquals(expectedMethods.removeFirst(), "buildFile");
60  		Assert.assertEquals(expectedData.removeFirst(), filename);
61  		Assert.assertEquals(expectedData.removeFirst(), Boolean.valueOf(isBinary));
62  		Assert.assertEquals(expectedData.removeFirst(), Boolean.valueOf(isInAttic));
63  	}
64  
65  	/* (non-Javadoc)
66  	 * @see net.sf.statsvn.input.SvnLogBuilder#buildRevision(net.sf.statsvn.input.RevisionData)
67  	 */
68  	public void buildRevision(final RevisionData data) {
69  		if (expectedMethods.isEmpty()) {
70  			Assert.fail("expected no more revisions");
71  		}
72  		if (!"buildRevision".equals(expectedMethods.getFirst()) && !"nextRevision".equals(expectedMethods.getFirst())
73  		        && !((String) expectedMethods.getFirst()).startsWith("current")) {
74  			Assert.assertEquals(expectedMethods.getFirst(), "buildRevision");
75  		}
76  		if ("buildRevision".equals(expectedMethods.getFirst())) {
77  			Assert.assertEquals(expectedMethods.removeFirst(), "buildRevision");
78  			final RevisionData expected = (RevisionData) expectedData.removeFirst();
79  			Assert.assertEquals(expected.getRevisionNumber(), data.getRevisionNumber());
80  			Assert.assertEquals(expected.getDate().getTime() / 1000, data.getDate().getTime() / 1000);
81  			Assert.assertEquals(expected.getLoginName(), data.getLoginName());
82  			//Assert.assertEquals(expected.isAddOnSubbranch(), data.isAddOnSubbranch());
83  			Assert.assertEquals(expected.isDeletion(), data.isDeletion());
84  			Assert.assertEquals(expected.isCreationOrRestore(), data.isCreationOrRestore());
85  			Assert.assertEquals(expected.isChange(), data.isChange());
86  			Assert.assertEquals(expected.getComment(), data.getComment());
87  			Assert.assertEquals(expected.getLinesAdded(), data.getLinesAdded());
88  			Assert.assertEquals(expected.getLinesRemoved(), data.getLinesRemoved());
89  			return;
90  		}
91  		while (!expectedMethods.isEmpty() && ((String) expectedMethods.getFirst()).startsWith("current")) {
92  			final String expected = (String) expectedMethods.removeFirst();
93  			if ("currentRevisionNumber".equals(expected)) {
94  				Assert.assertEquals(expectedData.removeFirst(), data.getRevisionNumber());
95  			} else if ("currentDate".equals(expected)) {
96  				Assert.assertEquals(((Date) expectedData.removeFirst()).getTime() / 1000, data.getDate().getTime() / 1000);
97  			} else if ("currentAuthor".equals(expected)) {
98  				Assert.assertEquals(expectedData.removeFirst(), data.getLoginName());
99  			} else if ("currentComment".equals(expected)) {
100 				Assert.assertEquals(expectedData.removeFirst(), data.getComment());
101 			} else if ("currentStateExp".equals(expected)) {
102 				Assert.assertTrue(data.isStateExp());
103 			} else if ("currentStateDead".equals(expected)) {
104 				Assert.assertTrue(data.isStateDead());
105 			} else if ("currentLines".equals(expected)) {
106 				Assert.assertEquals(expectedData.removeFirst(), new Integer(data.getLinesAdded()));
107 				Assert.assertEquals(expectedData.removeFirst(), new Integer(data.getLinesRemoved()));
108 			} else if ("currentNoLines".equals(expected)) {
109 				Assert.assertTrue(data.hasNoLines());
110 			} else { // can't happen
111 				Assert.fail("bad state: " + expected);
112 			}
113 		}
114 		if (!expectedMethods.isEmpty() && "nextRevision".equals(expectedMethods.getFirst())) {
115 			expectedMethods.removeFirst();
116 		}
117 	}
118 
119 	public void expectBuildModule(final String moduleName) {
120 		expectedMethods.add("buildModule");
121 		expectedData.add(moduleName);
122 	}
123 
124 	public void expectBuildFile(final String filename, final boolean isBinary, final boolean isInAttic) {
125 		expectedMethods.add("buildFile");
126 		expectedData.add(filename);
127 		expectedData.add(Boolean.valueOf(isBinary));
128 		expectedData.add(Boolean.valueOf(isInAttic));
129 	}
130 
131 	public void expectBuildRevision(final RevisionData data) {
132 		expectedMethods.add("buildRevision");
133 		expectedData.add(data);
134 	}
135 
136 	public void expectNextRevision() {
137 		expectedMethods.add("nextRevision");
138 	}
139 
140 	public void expectCurrentRevisionNumber(final String revision) {
141 		expectedMethods.add("currentRevisionNumber");
142 		expectedData.add(revision);
143 	}
144 
145 	public void expectCurrentDate(final Date date) {
146 		expectedMethods.add("currentDate");
147 		expectedData.add(date);
148 	}
149 
150 	public void expectCurrentAuthor(final String name) {
151 		expectedMethods.add("currentAuthor");
152 		expectedData.add(name);
153 	}
154 
155 	public void expectCurrentComment(final String comment) {
156 		expectedMethods.add("currentComment");
157 		expectedData.add(comment);
158 	}
159 
160 	public void expectCurrentStateExp() {
161 		expectedMethods.add("currentStateExp");
162 	}
163 
164 	public void expectCurrentStateDead() {
165 		expectedMethods.add("currentStateDead");
166 	}
167 
168 	public void expectCurrentNoLines() {
169 		expectedMethods.add("currentNoLines");
170 	}
171 
172 	public void expectCurrentLines(final int added, final int removed) {
173 		expectedMethods.add("currentLines");
174 		expectedData.add(new Integer(added));
175 		expectedData.add(new Integer(removed));
176 	}
177 
178 	public void verify() {
179 		if (!expectedMethods.isEmpty()) {
180 			Assert.fail("expected " + expectedMethods.getFirst());
181 		}
182 	}
183 
184 	/**
185 	 * @todo implementation
186 	 */
187 	public Map getFileBuilders() {
188 		return null;
189 	}
190 
191 	/**
192 	 * @todo implementation
193 	 */
194 	public void updateRevision(final String filename, final String revisionNumber, final int linesAdded, final int linesRemoved) {
195 	}
196 
197 	public void buildFile(final String filename, final boolean isBinary, final boolean isInAttic, final Map revBySymnames, final Map dateBySymnames) {
198 		// TODO Auto-generated method stub
199 
200 	}
201 
202 	public boolean matchesPatterns(final String filename) {
203 		// TODO Auto-generated method stub
204 		return false;
205 	}
206 
207 	public boolean matchesTagPatterns(final String tag) {
208 		// TODO Auto-generated method stub
209 		return false;
210 	}
211 }