Skip to content

Commit 5ee6f56

Browse files
authored
chore: resolve a bunch of linter warnings, no logic changes (#334)
1 parent f3e2dd5 commit 5ee6f56

File tree

11 files changed

+49
-57
lines changed

11 files changed

+49
-57
lines changed

src/main/java/io/getunleash/DefaultUnleash.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import io.getunleash.event.IsEnabledImpressionEvent;
99
import io.getunleash.event.ToggleEvaluated;
1010
import io.getunleash.event.VariantImpressionEvent;
11-
import io.getunleash.metric.UnleashMetricService;
1211
import io.getunleash.repository.FeatureRepository;
1312
import io.getunleash.repository.YggdrasilAdapters;
1413
import io.getunleash.strategy.*;
@@ -27,7 +26,6 @@ public class DefaultUnleash implements Unleash {
2726

2827
private static ConcurrentHashMap<String, LongAdder> initCounts = new ConcurrentHashMap<>();
2928

30-
private final UnleashMetricService metricService;
3129
private final FeatureRepository featureRepository;
3230
private final UnleashContextProvider contextProvider;
3331
private final EventDispatcher eventDispatcher;
@@ -69,7 +67,6 @@ public DefaultUnleash(
6967

7068
this.config = unleashConfig;
7169
this.featureRepository = engineProxy;
72-
this.metricService = engineProxy;
7370
this.contextProvider = contextProvider;
7471
this.eventDispatcher = eventDispatcher;
7572
initCounts.compute(

src/main/java/io/getunleash/metric/UnleashMetricServiceImpl.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88
import java.time.LocalDateTime;
99
import java.time.ZoneId;
1010
import java.util.Set;
11-
import org.slf4j.Logger;
12-
import org.slf4j.LoggerFactory;
1311

1412
public class UnleashMetricServiceImpl implements UnleashMetricService {
15-
private static final Logger LOGGER = LoggerFactory.getLogger(UnleashMetricServiceImpl.class);
1613
private final LocalDateTime started;
1714
private final UnleashConfig unleashConfig;
1815
private final MetricSender metricSender;

src/main/java/io/getunleash/util/UnleashScheduledExecutorImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ public void setInterval(Runnable command, long initialDelaySec, long periodSec)
4848

4949
@Override
5050
public Future<Void> scheduleOnce(Runnable runnable) {
51-
return (Future<Void>) executorService.submit(runnable);
51+
return executorService.submit(
52+
() -> {
53+
runnable.run();
54+
return null;
55+
});
5256
}
5357

5458
@Override

src/test/java/io/getunleash/DefaultUnleashTest.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
import io.getunleash.util.UnleashConfig;
2424
import java.net.URI;
2525
import java.net.URISyntaxException;
26-
import java.util.HashMap;
2726
import java.util.List;
28-
import java.util.Map;
2927
import java.util.Optional;
3028
import org.junit.jupiter.api.BeforeEach;
3129
import org.junit.jupiter.api.Test;
@@ -56,7 +54,6 @@ public void setup() {
5654
UnleashConfig unleashConfig =
5755
UnleashConfig.builder().unleashAPI("http://fakeAPI").appName("fakeApp").build();
5856
engineProxy = mock(EngineProxy.class);
59-
Map<String, Strategy> strategyMap = new HashMap<>();
6057
contextProvider = mock(UnleashContextProvider.class);
6158
eventDispatcher = mock(EventDispatcher.class);
6259

@@ -145,7 +142,7 @@ public void not_setting_current_time_falls_back_to_correct_now_instant() {
145142

146143
@Test
147144
public void multiple_instantiations_of_the_same_config_gives_errors() {
148-
ListAppender<ILoggingEvent> appender = new ListAppender();
145+
ListAppender<ILoggingEvent> appender = new ListAppender<>();
149146
appender.start();
150147
Logger unleashLogger = (Logger) LoggerFactory.getLogger(DefaultUnleash.class);
151148
unleashLogger.addAppender(appender);
@@ -158,13 +155,13 @@ public void multiple_instantiations_of_the_same_config_gives_errors() {
158155
.apiKey("default:development:1234567890123456")
159156
.instanceId(instanceId)
160157
.build();
161-
Unleash unleash1 = new DefaultUnleash(config);
158+
new DefaultUnleash(config);
162159
// We've only instantiated the client once, so no errors should've been logged
163160
assertThat(appender.list).isEmpty();
164-
Unleash unleash2 = new DefaultUnleash(config);
161+
new DefaultUnleash(config);
165162
// We've now instantiated the client twice, so we expect an error log line.
166163
assertThat(appender.list).hasSize(1);
167-
String id = config.getClientIdentifier();
164+
config.getClientIdentifier();
168165
assertThat(appender.list)
169166
.extracting(ILoggingEvent::getFormattedMessage)
170167
.containsExactly(
@@ -174,7 +171,7 @@ public void multiple_instantiations_of_the_same_config_gives_errors() {
174171
+ instanceId
175172
+ "] running. Please double check your code where you are instantiating the Unleash SDK");
176173
appender.list.clear();
177-
Unleash unleash3 = new DefaultUnleash(config);
174+
new DefaultUnleash(config);
178175
// We've now instantiated the client twice, so we expect an error log line.
179176
assertThat(appender.list).hasSize(1);
180177
assertThat(appender.list)
@@ -197,10 +194,10 @@ public void supports_failing_hard_on_multiple_instantiations() {
197194
.instanceId("multiple_connection_exception")
198195
.build();
199196
String id = config.getClientIdentifier();
200-
Unleash unleash1 = new DefaultUnleash(config);
197+
new DefaultUnleash(config);
201198
assertThatThrownBy(
202199
() -> {
203-
Unleash unleash2 = new DefaultUnleash(config, null, null, null, true);
200+
new DefaultUnleash(config, null, null, null, true);
204201
})
205202
.isInstanceOf(RuntimeException.class)
206203
.withFailMessage(
@@ -294,7 +291,7 @@ public void asynchronous_fetch_on_initialisation_fails_silently_and_retries()
294291
.unleashFeatureFetcherFactory((UnleashConfig c) -> fetcher)
295292
.build();
296293

297-
Unleash unleash = new DefaultUnleash(config);
294+
new DefaultUnleash(config);
298295
Thread.sleep(1);
299296
verify(fetcher, times(1)).fetchFeatures();
300297
Thread.sleep(1200);

src/test/java/io/getunleash/SynchronousTestExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void setInterval(Runnable command, long initialDelaySec, long periodSec)
2020
}
2121

2222
@Override
23-
public ScheduledFuture scheduleOnce(Runnable runnable) {
23+
public ScheduledFuture<Void> scheduleOnce(Runnable runnable) {
2424
runnable.run();
2525
return new AlreadyCompletedScheduledFuture();
2626
}

src/test/java/io/getunleash/UnleashTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public void fallback_function_should_be_invoked_and_return_true() {
5959
.thenReturn(new FlatResponse<Boolean>(false, null));
6060
Unleash unleash = new DefaultUnleash(baseConfig, engineProxy);
6161

62+
@SuppressWarnings("unchecked")
6263
BiPredicate<String, UnleashContext> fallbackAction = mock(BiPredicate.class);
6364
when(fallbackAction.test(eq("test"), any(UnleashContext.class))).thenReturn(true);
6465

@@ -73,6 +74,7 @@ public void fallback_function_should_be_invoked_also_with_context() {
7374
.thenReturn(new FlatResponse<Boolean>(false, null));
7475
Unleash unleash = new DefaultUnleash(baseConfig, engineProxy);
7576

77+
@SuppressWarnings("unchecked")
7678
BiPredicate<String, UnleashContext> fallbackAction = mock(BiPredicate.class);
7779
when(fallbackAction.test(eq("test"), any(UnleashContext.class))).thenReturn(true);
7880

@@ -89,6 +91,7 @@ void fallback_function_should_be_invoked_and_return_false() {
8991
.thenReturn(new FlatResponse<Boolean>(false, null));
9092
Unleash unleash = new DefaultUnleash(baseConfig, engineProxy);
9193

94+
@SuppressWarnings("unchecked")
9295
BiPredicate<String, UnleashContext> fallbackAction = mock(BiPredicate.class);
9396
when(fallbackAction.test(eq("test"), any(UnleashContext.class))).thenReturn(false);
9497

@@ -103,6 +106,7 @@ void fallback_function_should_not_be_called_when_toggle_is_defined() {
103106
.thenReturn(new FlatResponse<Boolean>(true, true));
104107
Unleash unleash = new DefaultUnleash(baseConfig, engineProxy);
105108

109+
@SuppressWarnings("unchecked")
106110
BiPredicate<String, UnleashContext> fallbackAction = mock(BiPredicate.class);
107111
when(fallbackAction.test(eq("test"), any(UnleashContext.class))).thenReturn(false);
108112

src/test/java/io/getunleash/metric/UnleashMetricServiceImplTest.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public void should_register_future_for_sending_interval_regualry() {
2828
.unleashAPI("http://unleash.com")
2929
.build();
3030
UnleashScheduledExecutor executor = mock(UnleashScheduledExecutor.class);
31-
UnleashMetricService unleashMetricService =
32-
new UnleashMetricServiceImpl(config, executor, null);
31+
32+
new UnleashMetricServiceImpl(config, executor, null);
3333

3434
verify(executor, times(1)).setInterval(any(Runnable.class), eq(interval), eq(interval));
3535
}
@@ -106,8 +106,7 @@ public void should_send_metrics() {
106106
DefaultHttpMetricsSender sender = mock(DefaultHttpMetricsSender.class);
107107
UnleashEngine engine = new UnleashEngine();
108108

109-
UnleashMetricService unleashMetricService =
110-
new UnleashMetricServiceImpl(config, sender, executor, engine);
109+
new UnleashMetricServiceImpl(config, sender, executor, engine);
111110

112111
ArgumentCaptor<Runnable> sendMetricsCallback = ArgumentCaptor.forClass(Runnable.class);
113112
verify(executor).setInterval(sendMetricsCallback.capture(), anyLong(), anyLong());
@@ -131,8 +130,7 @@ public void should_record_and_send_metrics()
131130
DefaultHttpMetricsSender sender = mock(DefaultHttpMetricsSender.class);
132131
UnleashEngine engine = new UnleashEngine();
133132

134-
UnleashMetricService unleashMetricService =
135-
new UnleashMetricServiceImpl(config, sender, executor, engine);
133+
new UnleashMetricServiceImpl(config, sender, executor, engine);
136134

137135
engine.isEnabled("someToggle", new Context());
138136
engine.isEnabled("someToggle", new Context());
@@ -374,8 +372,7 @@ public void should_add_new_metrics_data_to_bucket() {
374372
DefaultHttpMetricsSender sender = mock(DefaultHttpMetricsSender.class);
375373
UnleashEngine engine = new UnleashEngine();
376374

377-
UnleashMetricService unleashMetricService =
378-
new UnleashMetricServiceImpl(config, sender, executor, engine);
375+
new UnleashMetricServiceImpl(config, sender, executor, engine);
379376

380377
ArgumentCaptor<Runnable> sendMetricsCallback = ArgumentCaptor.forClass(Runnable.class);
381378
verify(executor).setInterval(sendMetricsCallback.capture(), anyLong(), anyLong());

src/test/java/io/getunleash/repository/FeatureRepositoryTest.java

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import io.getunleash.DefaultUnleash;
1212
import io.getunleash.FeatureDefinition;
13-
import io.getunleash.Unleash;
1413
import io.getunleash.engine.UnleashEngine;
1514
import io.getunleash.event.ClientFeaturesResponse;
1615
import io.getunleash.streaming.StreamingFeatureFetcher;
@@ -147,14 +146,13 @@ public void should_perform_synchronous_fetch_on_initialisation() {
147146
ClientFeaturesResponse.updated(loadMockFeatures("unleash-repo-v2.json"));
148147
when(fetcher.fetchFeatures()).thenReturn(response);
149148

150-
FeatureRepository featureRepository =
151-
new FeatureRepositoryImpl(
152-
config,
153-
backupHandler,
154-
new UnleashEngine(),
155-
fetcher,
156-
streamingFetcher,
157-
bootstrapHandler);
149+
new FeatureRepositoryImpl(
150+
config,
151+
backupHandler,
152+
new UnleashEngine(),
153+
fetcher,
154+
streamingFetcher,
155+
bootstrapHandler);
158156

159157
verify(fetcher, times(1)).fetchFeatures();
160158
}
@@ -171,14 +169,13 @@ public void should_not_perform_synchronous_fetch_on_initialisation() {
171169

172170
when(fetcher.fetchFeatures()).thenReturn(response);
173171

174-
FeatureRepositoryImpl featureRepository =
175-
new FeatureRepositoryImpl(
176-
config,
177-
backupHandler,
178-
new UnleashEngine(),
179-
fetcher,
180-
streamingFetcher,
181-
bootstrapHandler);
172+
new FeatureRepositoryImpl(
173+
config,
174+
backupHandler,
175+
new UnleashEngine(),
176+
fetcher,
177+
streamingFetcher,
178+
bootstrapHandler);
182179

183180
verify(fetcher, times(0)).fetchFeatures();
184181
}
@@ -233,14 +230,13 @@ public void should_not_read_bootstrap_if_backup_was_found() {
233230
UnleashConfig config =
234231
defaultConfigBuilder().toggleBootstrapProvider(bootstrapHandler).build();
235232

236-
FeatureRepositoryImpl featureRepository =
237-
new FeatureRepositoryImpl(
238-
config,
239-
backupHandler,
240-
new UnleashEngine(),
241-
fetcher,
242-
streamingFetcher,
243-
bootstrapHandler);
233+
new FeatureRepositoryImpl(
234+
config,
235+
backupHandler,
236+
new UnleashEngine(),
237+
fetcher,
238+
streamingFetcher,
239+
bootstrapHandler);
244240

245241
verify(bootstrapHandler, times(0)).read();
246242
}
@@ -263,7 +259,7 @@ public void shouldCallStartupExceptionHandlerIfStartupFails() {
263259
.toggleBootstrapProvider(toggleBootstrapProvider)
264260
.build();
265261

266-
Unleash unleash = new DefaultUnleash(config);
262+
new DefaultUnleash(config);
267263
assertThat(failed).isTrue();
268264
}
269265

src/test/java/io/getunleash/repository/OkHttpFeatureFetcherTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public void should_not_set_empty_ifNoneMatchHeader() throws URISyntaxException {
245245
URI uri = new URI("http://localhost:" + serverMock.getPort() + "/api/");
246246
UnleashConfig config = UnleashConfig.builder().appName("test").unleashAPI(uri).build();
247247
OkHttpFeatureFetcher okHttpToggleFetcher = new OkHttpFeatureFetcher(config);
248-
ClientFeaturesResponse response = okHttpToggleFetcher.fetchFeatures();
248+
okHttpToggleFetcher.fetchFeatures();
249249

250250
verify(getRequestedFor(urlMatching("/api/client/features")).withoutHeader("If-None-Match"));
251251
}
@@ -265,7 +265,7 @@ public void should_add_project_filter_to_toggles_url_if_config_has_it_set()
265265
UnleashConfig config =
266266
UnleashConfig.builder().appName("test").unleashAPI(uri).projectName("name").build();
267267
OkHttpFeatureFetcher okHttpFeatureFetcher = new OkHttpFeatureFetcher(config);
268-
ClientFeaturesResponse response = okHttpFeatureFetcher.fetchFeatures();
268+
okHttpFeatureFetcher.fetchFeatures();
269269
verify(getRequestedFor(urlMatching("/api/client/features\\?project=name")));
270270
}
271271

src/test/java/io/getunleash/streaming/StreamingFeatureFetchingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.getunleash.integration;
1+
package io.getunleash.streaming;
22

33
import static com.github.tomakehurst.wiremock.client.WireMock.*;
44
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;

0 commit comments

Comments
 (0)