Skip to content

Instantly share code, notes, and snippets.

@gabanox
Created October 17, 2014 17:41
Show Gist options
  • Save gabanox/c73eb696c168060b9513 to your computer and use it in GitHub Desktop.
Save gabanox/c73eb696c168060b9513 to your computer and use it in GitHub Desktop.
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