01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.tools.ant;
20:
21: import java.util.Vector;
22:
23: import junit.framework.Assert;
24:
25: public class MockBuildListener extends Assert implements BuildListener {
26:
27: private final Vector buffer = new Vector();
28: private final Project project;
29:
30: public MockBuildListener(final Project project) {
31: this .project = project;
32: }
33:
34: public void buildStarted(BuildEvent event) {
35: }
36:
37: public void buildFinished(BuildEvent event) {
38: }
39:
40: public void targetStarted(BuildEvent event) {
41: }
42:
43: public void targetFinished(BuildEvent event) {
44: }
45:
46: public void taskStarted(BuildEvent event) {
47: }
48:
49: public void taskFinished(BuildEvent event) {
50: }
51:
52: public void messageLogged(final BuildEvent actual) {
53: if (actual.getPriority() == Project.MSG_DEBUG)
54: return;
55: assertTrue("unexpected messageLogged: " + actual.getMessage(),
56: !buffer.isEmpty());
57: assertEquals("unexpected project ", project, actual
58: .getProject());
59:
60: BuildEvent expected = (BuildEvent) buffer.elementAt(0);
61: buffer.removeElementAt(0);
62: assertEquals("unexpected messageLogged ",
63: expected.getMessage(), actual.getMessage());
64: assertEquals("unexpected priority ", expected.getPriority(),
65: actual.getPriority());
66: }
67:
68: public void assertEmpty() {
69: assertTrue("MockBuildListener is not empty", buffer.isEmpty());
70: }
71:
72: public void addBuildEvent(final String message, final int priority) {
73: final BuildEvent be = new BuildEvent(project);
74: be.setMessage(message, priority);
75: buffer.addElement(be);
76: }
77:
78: }
|