Skip to content

Commit 5ed5aac

Browse files
Further refinement on refactors to make code even simpler
1 parent 387b9ae commit 5ed5aac

File tree

4 files changed

+19
-29
lines changed

4 files changed

+19
-29
lines changed

jmeter-java-dsl-azure/src/main/java/us/abstracta/jmeter/javadsl/azure/AzureClient.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import java.io.File;
66
import java.io.IOException;
7+
import java.net.HttpURLConnection;
78
import java.nio.charset.StandardCharsets;
89
import java.time.Instant;
910
import java.util.Base64;
@@ -51,7 +52,6 @@ public class AzureClient extends BaseRemoteEngineApiClient {
5152

5253
private static final Logger LOG = LoggerFactory.getLogger(AzureClient.class);
5354
private static final String USER_AGENT = getUserAgent();
54-
private static final int HTTP_NOT_FOUND = 404;
5555

5656
private final String tenantId;
5757
private final String clientId;
@@ -267,7 +267,7 @@ public ResourceGroup findResourceGroup(String name, Subscription subscription)
267267
private <T> Optional<T> execOptionalApiCall(Call<T> call) throws IOException {
268268
retrofit2.Response<T> response = call.execute();
269269
if (!response.isSuccessful()) {
270-
if (response.code() == HTTP_NOT_FOUND) {
270+
if (response.code() == HttpURLConnection.HTTP_NOT_FOUND) {
271271
return Optional.empty();
272272
}
273273
try (ResponseBody errorBody = response.errorBody()) {

jmeter-java-dsl-dashboard/src/test/java/us/abstracta/jmeter/javadsl/dashboard/DashboardVisualizerTest.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ public void shouldDisplayGraphsAndSummaryWhenRunTestPlanWithDashboard(TestInfo t
3636
);
3737
}
3838

39-
@Test
40-
public void shouldThrowUnsupportedOperationWhenShowInGuiOnDashboardVisualizer() {
41-
DashboardVisualizer dashboardVisualizer = new DashboardVisualizer();
42-
43-
assertThrows(UnsupportedOperationException.class, dashboardVisualizer::showInGui);
44-
}
39+
@Test
40+
public void shouldThrowUnsupportedOperationWhenShowInGuiOnDashboardVisualizer() {
41+
assertThrows(UnsupportedOperationException.class, () -> new DashboardVisualizer().showInGui());
42+
}
4543

4644
}

jmeter-java-dsl-graphql/src/test/java/us/abstracta/jmeter/javadsl/graphql/DslGraphqlSamplerTest.java

+1-8
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,13 @@ public void shouldSendGraphqlQueryToServerWhenGraphqlSamplerWithHttpGet()
138138
).run();
139139
verify(getRequestedFor(anyUrl()).withQueryParam("query", equalTo(QUERY)));
140140
}
141+
141142
@Test
142143
public void shouldThrowIllegalArgumentWhenGraphqlSamplerWithInvalidVariable() {
143144
DslGraphqlSampler sampler = graphqlSampler("http://localhost", "{ user(id: 1){ name } }");
144145
assertThrows(IllegalArgumentException.class, () -> sampler.variable("invalidVar", new Object()));
145146
}
146147

147-
@Test
148-
public void shouldHandleInvalidJsonInput() {
149-
DslGraphqlSampler sampler = graphqlSampler("http://localhost", "{ user(id: 1){ name } }");
150-
sampler.variablesJson("invalidJson");
151-
}
152-
153-
154-
155148
@Nested
156149
public class CodeBuilderTest extends MethodCallBuilderTest {
157150

jmeter-java-dsl/src/main/java/us/abstracta/jmeter/javadsl/core/threadgroups/DslDefaultThreadGroup.java

+12-13
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,10 @@ private void addStage(Stage stage) {
167167

168168
private boolean isSimpleThreadGroup() {
169169
return stages.size() <= 1
170-
|| stages.size() == 2 && (
171-
ZERO.equals(stages.get(0).threadCount())
172-
|| stages.get(0).threadCount().equals(stages.get(1).threadCount()))
173-
|| stages.size() == 3 && (
174-
ZERO.equals(stages.get(0).threadCount())
175-
&& stages.get(1).threadCount().equals(stages.get(2).threadCount()));
170+
|| stages.size() == 2 && (ZERO.equals(stages.get(0).threadCount()) || stages.get(0)
171+
.threadCount().equals(stages.get(1).threadCount()))
172+
|| stages.size() == 3 && (ZERO.equals(stages.get(0).threadCount()) && stages.get(1)
173+
.threadCount().equals(stages.get(2).threadCount()));
176174
}
177175

178176
/**
@@ -246,10 +244,9 @@ private Object getPrevThreadsCount() {
246244
* termination condition).
247245
* <p>
248246
* <b>Setting this property to -1 is in general not advised</b>, since you
249-
* might
250-
* inadvertently end up running a test plan without limits consuming unnecessary
251-
* computing power. Prefer specifying a big value as a safe limit for iterations
252-
* or duration instead.
247+
* might inadvertently end up running a test plan without limits consuming
248+
* unnecessary computing power. Prefer specifying a big value as a safe limit
249+
* for iterations or duration instead.
253250
* @return the thread group for further configuration or usage.
254251
* @throws IllegalStateException when adding iterations would result in not supported JMeter
255252
* thread group.
@@ -286,10 +283,12 @@ public DslDefaultThreadGroup holdIterating(String iterations) {
286283

287284
private void checkIterationsPreConditions() {
288285
boolean isJustRamp = stages.size() == 1 && !ZERO.equals(stages.get(0).threadCount());
289-
boolean isJustDelayAndRamp = stages.size() == 2 && ZERO.equals(stages.get(0).threadCount()) && !ZERO.equals(stages.get(1).threadCount());
290-
286+
boolean isJustDelayAndRamp =
287+
stages.size() == 2 && ZERO.equals(stages.get(0).threadCount()) && !ZERO.equals(
288+
stages.get(1).threadCount());
291289
if (!(isJustRamp || isJustDelayAndRamp)) {
292-
throw new IllegalStateException("Holding for iterations is only supported after initial hold and ramp, or ramp.");
290+
throw new IllegalStateException(
291+
"Holding for iterations is only supported after initial hold and ramp, or ramp.");
293292
}
294293
if (ZERO.equals(getLastStage().threadCount())) {
295294
throw new IllegalStateException("Can't hold for iterations with no threads.");

0 commit comments

Comments
 (0)