EMMA Coverage Report (generated Thu May 22 12:08:10 CDT 2014)
[all classes][org.springframework.batch.test]

COVERAGE SUMMARY FOR SOURCE FILE [ExecutionContextTestUtils.java]

nameclass, %method, %block, %line, %
ExecutionContextTestUtils.java100% (1/1)75%  (3/4)96%  (66/69)93%  (14/15)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ExecutionContextTestUtils100% (1/1)75%  (3/4)96%  (66/69)93%  (14/15)
ExecutionContextTestUtils (): void 0%   (0/1)0%   (0/3)0%   (0/1)
getValueFromJob (JobExecution, String): Object 100% (1/1)100% (5/5)100% (1/1)
getValueFromStep (StepExecution, String): Object 100% (1/1)100% (5/5)100% (1/1)
getValueFromStepInJob (JobExecution, String, String): Object 100% (1/1)100% (56/56)100% (12/12)

1/*
2 * Copyright 2006-2009 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 
17package org.springframework.batch.test;
18 
19import java.util.ArrayList;
20import java.util.List;
21 
22import org.springframework.batch.core.JobExecution;
23import org.springframework.batch.core.StepExecution;
24import org.springframework.batch.item.ExecutionContext;
25 
26/**
27 * Convenience class for accessing {@link ExecutionContext} values from job and
28 * step executions.
29 * 
30 * @author Dave Syer
31 * @since 2.1.4
32 * 
33 */
34public class ExecutionContextTestUtils {
35 
36        @SuppressWarnings("unchecked")
37        public static <T> T getValueFromJob(JobExecution jobExecution, String key) {
38                return (T) jobExecution.getExecutionContext().get(key);
39        }
40 
41        public static <T> T getValueFromStepInJob(JobExecution jobExecution, String stepName, String key) {
42                StepExecution stepExecution = null;
43                List<String> stepNames = new ArrayList<String>();
44                for (StepExecution candidate : jobExecution.getStepExecutions()) {
45                        String name = candidate.getStepName();
46                        stepNames.add(name);
47                        if (name.equals(stepName)) {
48                                stepExecution = candidate;
49                        }
50                }
51                if (stepExecution == null) {
52                        throw new IllegalArgumentException("No such step in this job execution: " + stepName + " not in "
53                                        + stepNames);
54                }
55                @SuppressWarnings("unchecked")
56                T result = (T) stepExecution.getExecutionContext().get(key);
57                return result;
58        }
59 
60        @SuppressWarnings("unchecked")
61        public static <T> T getValueFromStep(StepExecution stepExecution, String key) {
62                return (T) stepExecution.getExecutionContext().get(key);
63        }
64 
65}

[all classes][org.springframework.batch.test]
EMMA 2.0.5312 (C) Vladimir Roubtsov