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)
public class BingTranslationServiceProvider implements TranslationService {
@Override
public String translate(String message, Locale from, Locale to) {
// implementation details
return message + " (translated by Bing)";
}

View File

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

View File

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

View File

@ -10,25 +10,22 @@ import java.util.stream.StreamSupport;
import static org.junit.Assert.assertEquals;
public class TranslationServiceUnitTest {
private ServiceLoader<TranslationService> loader;
@Before
public void setUp() {
loader = ServiceLoader.load(TranslationService.class);
}
@Test
public void whenServiceLoaderLoads_thenLoadsAllProviders() {
long count = StreamSupport.stream(loader.spliterator(), false).count();
assertEquals(2, count);
}
@Test
public void whenServiceLoaderLoadsGoogleService_thenGoogleIsLoaded() {
TranslationService googleService = StreamSupport.stream(loader.spliterator(), false)
.filter(p -> p.getClass().getSimpleName().equals("GoogleTranslationServiceProvider"))
.findFirst()