Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE in case of missed executor type #2284

Merged
merged 2 commits into from
Jan 10, 2024
Merged
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 @@ -156,15 +156,17 @@ private static Optional<String> getHostSafe(final String url) {
return Optional.empty();
}

private static String getExecutorType(final List<LaunchResults> launchesResults) {
/* package-private */
static String getExecutorType(final List<LaunchResults> launchesResults) {
return launchesResults.stream()
.map(results -> results.<ExecutorInfo>getExtra(EXECUTORS_BLOCK_NAME))
.filter(Optional::isPresent)
.findFirst()
.filter(Optional::isPresent)
.map(Optional::get)
.map(ExecutorInfo::getType)
.map(String::trim)
.map(String::toLowerCase)
.findFirst()
.orElse(LOCAL);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright 2016-2023 Qameta Software OÜ
*
* Licensed 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 io.qameta.allure.ga;

import io.qameta.allure.DefaultLaunchResults;
import io.qameta.allure.entity.ExecutorInfo;
import io.qameta.allure.executor.ExecutorPlugin;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Map;
import java.util.Set;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author charlie (Dmitry Baev).
*/
class GaPluginTest {

@Test
void shouldGetDefaultExecutor() {
final String executorType = GaPlugin.getExecutorType(
List.of(
new DefaultLaunchResults(Set.of(), Map.of(), Map.of())
)
);

assertThat(executorType)
.isEqualTo("local");
}

@Test
void shouldProcessNullExecutor() {
final String executorType = GaPlugin.getExecutorType(
List.of(
new DefaultLaunchResults(Set.of(), Map.of(), Map.of(
ExecutorPlugin.EXECUTORS_BLOCK_NAME,
new ExecutorInfo()
))
)
);

assertThat(executorType)
.isEqualTo("local");
}

@Test
void shouldProcessExecutor() {
final String executorType = GaPlugin.getExecutorType(
List.of(
new DefaultLaunchResults(Set.of(), Map.of(), Map.of(
ExecutorPlugin.EXECUTORS_BLOCK_NAME,
new ExecutorInfo()
.setType("some executor type")
))
)
);

assertThat(executorType)
.isEqualTo("some executor type");
}
}
3 changes: 2 additions & 1 deletion gradle/quality-configs/pmd/pmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<description>
General Java quality rules.
</description>

<!-- Best practices (https://pmd.github.io/pmd-6.0.1/pmd_rules_java_bestpractices.html) -->
<rule ref="category/java/bestpractices.xml">
<exclude name="AbstractClassWithoutAbstractMethod"/>
Expand All @@ -32,6 +32,7 @@
<exclude name="CallSuperInConstructor"/>
<exclude name="CommentDefaultAccessModifier"/>
<exclude name="ConfusingTernary"/>
<exclude name="DefaultPackage"/>
<exclude name="GenericsNaming"/>
<exclude name="LinguisticNaming"/>
<exclude name="LocalHomeNamingConvention"/> <!-- earlier j2ee group-->
Expand Down
Loading