View Javadoc

1   /**
2    * $Id: LoggerTest.java,v 1.4 2011/01/03 17:10:27 oboehm Exp $
3    *
4    * Copyright (c) 2007 by Oliver Boehm
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express orimplied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   *
18   * (c)reated 04.12.2007 by oliver (ob@oasd.de)
19   */
20  package patterntesting.tool.aspectj;
21  
22  import static org.junit.Assert.*;
23  
24  import java.io.File;
25  
26  import org.aspectj.lang.reflect.SourceLocation;
27  import org.junit.Test;
28  
29  import static org.easymock.EasyMock.*;
30  
31  /**
32   * @author <a href="boehm@javatux.de">oliver</a>
33   * @since 04.12.2007
34   */
35  public final class LoggerTest {
36  
37  	private final Logger logger = Logger.getInstance();
38  
39  	/**
40  	 * Test method for {@link patterntesting.tool.aspectj.Logger#getInstance()}.
41  	 */
42  	@Test
43  	public void testGetInstance() {
44  		Logger instance = Logger.getInstance();
45  		assertNotNull(instance);
46  	}
47  
48  	/**
49  	 * Test method for {@link patterntesting.tool.aspectj.Logger#getResultFile()}.
50  	 */
51  	@Test
52  	public void testGetResultFile() {
53  		File file = logger.getResultFile();
54  		assertTrue(file + " can't be deleted", file.delete());
55  		logger.reset();
56  		logger.logPTViolation(getSourceLocationMock(), "test-message");
57  		assertTrue(file + " doesn't exist", file.exists());
58  	}
59  
60  	private SourceLocation getSourceLocationMock() {
61  		SourceLocation mock = createMock(SourceLocation.class);
62  		reset(mock);
63  		expect(mock.getFileName()).andStubReturn("mock-file");
64  		expect(mock.getLine()).andStubReturn(42);
65  		replay(mock);
66  		return mock;
67  	}
68  
69  }