Browse Source

Polishing

(cherry picked from commit 1e491f1)
pull/1057/head
Juergen Hoeller 10 years ago
parent
commit
d6a4981a92
  1. 9
      spring-context/src/main/java/org/springframework/scheduling/config/TriggerTask.java
  2. 31
      src/test/java/org/springframework/scheduling/annotation/ScheduledAndTransactionalAnnotationIntegrationTests.java

9
spring-context/src/main/java/org/springframework/scheduling/config/TriggerTask.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,8 +19,8 @@ package org.springframework.scheduling.config; @@ -19,8 +19,8 @@ package org.springframework.scheduling.config;
import org.springframework.scheduling.Trigger;
/**
* {@link Task} implementation defining a {@code Runnable} to be executed according to a
* given {@link Trigger}.
* {@link Task} implementation defining a {@code Runnable} to be executed
* according to a given {@link Trigger}.
*
* @author Chris Beams
* @since 3.2
@ -45,6 +45,7 @@ public class TriggerTask extends Task { @@ -45,6 +45,7 @@ public class TriggerTask extends Task {
public Trigger getTrigger() {
return trigger;
return this.trigger;
}
}

31
src/test/java/org/springframework/scheduling/annotation/ScheduledAndTransactionalAnnotationIntegrationTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,6 +20,7 @@ import java.util.concurrent.atomic.AtomicInteger; @@ -20,6 +20,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Before;
import org.junit.Test;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@ -47,6 +48,7 @@ import static org.mockito.BDDMockito.*; @@ -47,6 +48,7 @@ import static org.mockito.BDDMockito.*;
* @author Chris Beams
* @since 3.1
*/
@SuppressWarnings("resource")
public class ScheduledAndTransactionalAnnotationIntegrationTests {
@Before
@ -54,13 +56,14 @@ public class ScheduledAndTransactionalAnnotationIntegrationTests { @@ -54,13 +56,14 @@ public class ScheduledAndTransactionalAnnotationIntegrationTests {
Assume.group(TestGroup.PERFORMANCE);
}
@Test
public void failsWhenJdkProxyAndScheduledMethodNotPresentOnInterface() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config.class, JdkProxyTxConfig.class, RepoConfigA.class);
try {
ctx.refresh();
fail("expected exception");
fail("Should have thrown BeanCreationException");
}
catch (BeanCreationException ex) {
assertTrue(ex.getRootCause().getMessage().startsWith("@Scheduled method 'scheduled' found"));
@ -100,28 +103,36 @@ public class ScheduledAndTransactionalAnnotationIntegrationTests { @@ -100,28 +103,36 @@ public class ScheduledAndTransactionalAnnotationIntegrationTests {
@Configuration
@EnableTransactionManagement
static class JdkProxyTxConfig { }
static class JdkProxyTxConfig {
}
@Configuration
@EnableTransactionManagement(proxyTargetClass=true)
static class SubclassProxyTxConfig { }
static class SubclassProxyTxConfig {
}
@Configuration
static class RepoConfigA {
@Bean
public MyRepository repository() {
return new MyRepositoryImpl();
}
}
@Configuration
static class RepoConfigB {
@Bean
public MyRepositoryWithScheduledMethod repository() {
return new MyRepositoryWithScheduledMethodImpl();
}
}
@Configuration
@EnableScheduling
static class Config {
@ -138,15 +149,17 @@ public class ScheduledAndTransactionalAnnotationIntegrationTests { @@ -138,15 +149,17 @@ public class ScheduledAndTransactionalAnnotationIntegrationTests {
@Bean
public PersistenceExceptionTranslator peTranslator() {
PersistenceExceptionTranslator txlator = mock(PersistenceExceptionTranslator.class);
return txlator;
return mock(PersistenceExceptionTranslator.class);
}
}
public interface MyRepository {
int getInvocationCount();
}
@Repository
static class MyRepositoryImpl implements MyRepository {
@ -164,11 +177,15 @@ public class ScheduledAndTransactionalAnnotationIntegrationTests { @@ -164,11 +177,15 @@ public class ScheduledAndTransactionalAnnotationIntegrationTests {
}
}
public interface MyRepositoryWithScheduledMethod {
int getInvocationCount();
public void scheduled();
void scheduled();
}
@Repository
static class MyRepositoryWithScheduledMethodImpl implements MyRepositoryWithScheduledMethod {

Loading…
Cancel
Save