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

temporalio / sdk-java / #169

pending completion
#169

push

github-actions

web-flow
Remove use of deprecated API (#1758)

4 of 4 new or added lines in 1 file covered. (100.0%)

17345 of 21558 relevant lines covered (80.46%)

0.8 hits per line

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

92.45
/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

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

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

99
  public WorkflowMethodType getType() {
100
    return type;
1✔
101
  }
102

103
  public Method getMethod() {
104
    return method;
1✔
105
  }
106

107
  public Optional<String> getNameFromAnnotation() {
108
    return nameFromAnnotation;
1✔
109
  }
110

111
  /** Compare and hash on method only. */
112
  @Override
113
  public boolean equals(Object o) {
114
    if (this == o) return true;
1✔
115
    if (o == null || getClass() != o.getClass()) return false;
1✔
116
    POJOWorkflowMethod that = (POJOWorkflowMethod) o;
1✔
117
    return type == that.type && com.google.common.base.Objects.equal(method, that.method);
1✔
118
  }
119

120
  /** Compare and hash on method only. */
121
  @Override
122
  public int hashCode() {
123
    return com.google.common.base.Objects.hashCode(method);
1✔
124
  }
125
}
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

© 2026 Coveralls, Inc