KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > MockBuildListener


1 /*
2  * Copyright 2001,2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 package org.apache.tools.ant;
19
20 import java.util.Vector JavaDoc;
21
22 import junit.framework.Assert;
23
24 public class MockBuildListener extends Assert implements BuildListener {
25
26     private final Vector JavaDoc buffer = new Vector JavaDoc();
27     private final Project project;
28
29     public MockBuildListener(final Project project) {
30         this.project = project;
31     }
32
33     public void buildStarted(BuildEvent event) {}
34     public void buildFinished(BuildEvent event) {}
35     public void targetStarted(BuildEvent event) {}
36     public void targetFinished(BuildEvent event) {}
37     public void taskStarted(BuildEvent event) {}
38     public void taskFinished(BuildEvent event) {}
39
40     public void messageLogged(final BuildEvent actual) {
41         if(actual.getPriority()==Project.MSG_DEBUG)
42             return;
43         assertTrue("unexpected messageLogged: "+actual.getMessage(), !buffer.isEmpty());
44         assertEquals("unexpected project ", project, actual.getProject());
45
46         BuildEvent expected = (BuildEvent) buffer.elementAt(0);
47         buffer.removeElementAt(0);
48         assertEquals("unexpected messageLogged ", expected.getMessage(), actual.getMessage());
49         assertEquals("unexpected priority ", expected.getPriority(), actual.getPriority());
50     }
51
52     public void assertEmpty() {
53         assertTrue("MockBuildListener is not empty", buffer.isEmpty());
54     }
55
56     public void addBuildEvent(final String JavaDoc message, final int priority) {
57         final BuildEvent be = new BuildEvent(project);
58         be.setMessage(message, priority);
59         buffer.addElement(be);
60     }
61
62 }
63
Popular Tags