Created
October 17, 2014 17:41
-
-
Save gabanox/c73eb696c168060b9513 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.telcel.aspects; | |
import static org.junit.Assert.*; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.test.context.ContextConfiguration; | |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | |
import com.telcel.aspects.ExceptionLoggingAspect; | |
import com.telcel.repository.MyRepository; | |
import com.telcel.service.MyService; | |
@RunWith(SpringJUnit4ClassRunner.class) | |
@ContextConfiguration("/system-configuration.xml") | |
public class ExceptionLoggingAspectTest { | |
@Autowired | |
ExceptionLoggingAspect exceptionLoggingAspect; | |
@Autowired | |
MyService myService; | |
@Autowired | |
MyRepository myRepository; | |
@Before | |
public void setUp() { | |
exceptionLoggingAspect.resetCalled(); | |
} | |
@Test | |
public void exceptionLoggingIsNotCalledIfNoExceptionIsThrown() { | |
assertFalse(exceptionLoggingAspect.isCalled()); | |
myRepository.doIt(); | |
assertFalse(exceptionLoggingAspect.isCalled()); | |
} | |
@Test(expected = RuntimeException.class) | |
public void exceptionLoggingIsCalledIfExceptionIsThrown() { | |
assertFalse(exceptionLoggingAspect.isCalled()); | |
try { | |
myRepository.throwsException(); | |
} finally { | |
assertTrue(exceptionLoggingAspect.isCalled()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment