• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

temporalio / sdk-java / #343

31 Oct 2024 06:31PM UTC coverage: 75.148% (-3.6%) from 78.794%
#343

push

github

web-flow
Fix jacoco coverage (#2304)

5139 of 8240 branches covered (62.37%)

Branch coverage included in aggregate %.

22841 of 28993 relevant lines covered (78.78%)

0.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.37
/temporal-sdk/src/main/java/io/temporal/common/metadata/POJOWorkflowMethod.java
1
/*
2
 * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
3
 *
4
 * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
 *
6
 * Modifications copyright (C) 2017 Uber Technologies, Inc.
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this material except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *   http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20

21
package io.temporal.common.metadata;
22

23
import com.google.common.base.Strings;
24
import io.temporal.workflow.*;
25
import java.lang.reflect.Method;
26
import java.util.Objects;
27
import java.util.Optional;
28

29
final class POJOWorkflowMethod {
30

31
  private final WorkflowMethodType type;
32
  private final Method method;
33
  private final Optional<String> nameFromAnnotation;
34
  private final Optional<String> descriptionFromAnnotation;
35

36
  POJOWorkflowMethod(Method method) {
1✔
37
    this.method = Objects.requireNonNull(method);
1✔
38
    WorkflowMethod workflowMethod = method.getAnnotation(WorkflowMethod.class);
1✔
39
    QueryMethod queryMethod = method.getAnnotation(QueryMethod.class);
1✔
40
    SignalMethod signalMethod = method.getAnnotation(SignalMethod.class);
1✔
41
    UpdateMethod updateMethod = method.getAnnotation(UpdateMethod.class);
1✔
42
    UpdateValidatorMethod updateValidatorMethod = method.getAnnotation(UpdateValidatorMethod.class);
1✔
43

44
    int count = 0;
1✔
45
    WorkflowMethodType type = null;
1✔
46
    String name = null;
1✔
47
    String description = null;
1✔
48
    if (workflowMethod != null) {
1✔
49
      type = WorkflowMethodType.WORKFLOW;
1✔
50
      count++;
1✔
51
      name = workflowMethod.name();
1✔
52
    }
53
    if (signalMethod != null) {
1✔
54
      type = WorkflowMethodType.SIGNAL;
1✔
55
      if (method.getReturnType() != Void.TYPE) {
1!
56
        throw new IllegalArgumentException(
×
57
            "Method annotated with @SignalMethod must have void return type: " + method);
58
      }
59
      count++;
1✔
60
      name = signalMethod.name();
1✔
61
      description = signalMethod.description();
1✔
62
    }
63
    if (queryMethod != null) {
1✔
64
      type = WorkflowMethodType.QUERY;
1✔
65
      if (method.getReturnType() == Void.TYPE) {
1!
66
        throw new IllegalArgumentException(
×
67
            "Method annotated with @QueryMethod cannot have void return type: " + method);
68
      }
69
      count++;
1✔
70
      name = queryMethod.name();
1✔
71
      description = queryMethod.description();
1✔
72
    }
73
    if (updateMethod != null) {
1✔
74
      type = WorkflowMethodType.UPDATE;
1✔
75
      count++;
1✔
76
      name = updateMethod.name();
1✔
77
      description = updateMethod.description();
1✔
78
    }
79
    if (updateValidatorMethod != null) {
1✔
80
      type = WorkflowMethodType.UPDATE_VALIDATOR;
1✔
81
      if (method.getReturnType() != Void.TYPE) {
1!
82
        throw new IllegalArgumentException(
×
83
            "Method annotated with @UpdateValidatorMethod must have a void return type: " + method);
84
      }
85
      count++;
1✔
86
      name = updateValidatorMethod.updateName();
1✔
87
    }
88
    if (count == 0) {
1✔
89
      type = WorkflowMethodType.NONE;
1✔
90
    } else if (count > 1) {
1!
91
      throw new IllegalArgumentException(
×
92
          method
93
              + " must contain exactly one annotation "
94
              + "of @WorkflowMethod, @QueryMethod @UpdateMethod or @SignalMethod");
95
    }
96
    if (Strings.isNullOrEmpty(name)) {
1✔
97
      this.nameFromAnnotation = Optional.empty();
1✔
98
    } else {
99
      this.nameFromAnnotation = Optional.of(name);
1✔
100
    }
101

102
    if (Strings.isNullOrEmpty(description)) {
1✔
103
      this.descriptionFromAnnotation = Optional.empty();
1✔
104
    } else {
105
      this.descriptionFromAnnotation = Optional.of(description);
1✔
106
    }
107
    this.type = Objects.requireNonNull(type);
1✔
108
  }
1✔
109

110
  public WorkflowMethodType getType() {
111
    return type;
1✔
112
  }
113

114
  public Method getMethod() {
115
    return method;
1✔
116
  }
117

118
  public Optional<String> getNameFromAnnotation() {
119
    return nameFromAnnotation;
1✔
120
  }
121

122
  public Optional<String> getDescriptionFromAnnotation() {
123
    return descriptionFromAnnotation;
1✔
124
  }
125

126
  /** Compare and hash on method only. */
127
  @Override
128
  public boolean equals(Object o) {
129
    if (this == o) return true;
1!
130
    if (o == null || getClass() != o.getClass()) return false;
1!
131
    POJOWorkflowMethod that = (POJOWorkflowMethod) o;
1✔
132
    return type == that.type && com.google.common.base.Objects.equal(method, that.method);
1!
133
  }
134

135
  /** Compare and hash on method only. */
136
  @Override
137
  public int hashCode() {
138
    return com.google.common.base.Objects.hashCode(method);
1✔
139
  }
140
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc