removed empty beggining lines & added override annotation

This commit is contained in:
Erhan Karakaya 2019-06-20 11:00:12 +03:00
parent ac850bbc0b
commit d0b2aa8635
4 changed files with 4 additions and 10 deletions

View File

@ -6,9 +6,8 @@ import java.util.Locale;
@AutoService(TranslationService.class) @AutoService(TranslationService.class)
public class BingTranslationServiceProvider implements TranslationService { public class BingTranslationServiceProvider implements TranslationService {
@Override
public String translate(String message, Locale from, Locale to) { public String translate(String message, Locale from, Locale to) {
// implementation details // implementation details
return message + " (translated by Bing)"; return message + " (translated by Bing)";
} }

View File

@ -6,9 +6,8 @@ import java.util.Locale;
@AutoService(TranslationService.class) @AutoService(TranslationService.class)
public class GoogleTranslationServiceProvider implements TranslationService { public class GoogleTranslationServiceProvider implements TranslationService {
@Override
public String translate(String message, Locale from, Locale to) { public String translate(String message, Locale from, Locale to) {
// implementation details // implementation details
return message + " (translated by Google)"; return message + " (translated by Google)";
} }

View File

@ -3,6 +3,5 @@ package com.baeldung.autoservice;
import java.util.Locale; import java.util.Locale;
public interface TranslationService { public interface TranslationService {
String translate(String message, Locale from, Locale to); String translate(String message, Locale from, Locale to);
} }

View File

@ -15,20 +15,17 @@ public class TranslationServiceUnitTest {
@Before @Before
public void setUp() { public void setUp() {
loader = ServiceLoader.load(TranslationService.class); loader = ServiceLoader.load(TranslationService.class);
} }
@Test @Test
public void whenServiceLoaderLoads_thenLoadsAllProviders() { public void whenServiceLoaderLoads_thenLoadsAllProviders() {
long count = StreamSupport.stream(loader.spliterator(), false).count(); long count = StreamSupport.stream(loader.spliterator(), false).count();
assertEquals(2, count); assertEquals(2, count);
} }
@Test @Test
public void whenServiceLoaderLoadsGoogleService_thenGoogleIsLoaded() { public void whenServiceLoaderLoadsGoogleService_thenGoogleIsLoaded() {
TranslationService googleService = StreamSupport.stream(loader.spliterator(), false) TranslationService googleService = StreamSupport.stream(loader.spliterator(), false)
.filter(p -> p.getClass().getSimpleName().equals("GoogleTranslationServiceProvider")) .filter(p -> p.getClass().getSimpleName().equals("GoogleTranslationServiceProvider"))
.findFirst() .findFirst()