Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.envimate.messageMate.internal.reflections.ForbiddenUseCaseMethods.NOT_ALLOWED_USECASE_PUBLIC_METHODS;
import static com.envimate.messageMate.internal.reflections.ReflectionUtils.getAllPublicMethods;
import static com.envimate.messageMate.useCases.useCaseAdapter.methodInvoking.SerializingMethodInvoker.serializingMethodInvoker;
import static java.util.function.Predicate.not;
import static lombok.AccessLevel.PRIVATE;

/**
Expand All @@ -59,8 +61,11 @@ public static <U> SinglePublicUseCaseMethodCaller<U> singlePublicUseCaseMethodCa
return new SinglePublicUseCaseMethodCaller<>(methodInvoker);
}

private static Method locateUseCaseMethod(final Class<?> useCaseClass) {
final List<Method> useCaseMethods = getAllPublicMethods(useCaseClass, NOT_ALLOWED_USECASE_PUBLIC_METHODS);
static Method locateUseCaseMethod(final Class<?> useCaseClass) {
final List<Method> useCaseMethods =
getAllPublicMethods(useCaseClass, NOT_ALLOWED_USECASE_PUBLIC_METHODS).stream()
.filter(not(Method::isBridge))
.collect(Collectors.toList());
if (useCaseMethods.size() == 1) {
return useCaseMethods.get(0);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2019 envimate GmbH - https://envimate.com/.
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package com.envimate.messageMate.useCases.useCaseAdapter.usecaseCalling;

public interface GenericMethodInterface<I, O> {
O invoke(I request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2019 envimate GmbH - https://envimate.com/.
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package com.envimate.messageMate.useCases.useCaseAdapter.usecaseCalling;

public class GenericMethodUseCase implements GenericMethodInterface<String, String> {
@Override
public String invoke(final String in) {
return in.replace("in", "out");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2019 envimate GmbH - https://envimate.com/.
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package com.envimate.messageMate.useCases.useCaseAdapter.usecaseCalling;

import org.junit.jupiter.api.Test;

import java.lang.reflect.Method;

import static org.junit.jupiter.api.Assertions.assertEquals;

class SinglePublicUseCaseMethodCallerTest {
@Test
void locatesGenericMethods_aka_ignoresBridgeMethods() throws Exception {
final Method actualMethod = SinglePublicUseCaseMethodCaller.locateUseCaseMethod(GenericMethodUseCase.class);
final Method expectedMethod = GenericMethodUseCase.class.getMethod("invoke", String.class);
assertEquals(expectedMethod, actualMethod, "located method");
}
}