removed empty beggining lines & added override annotation
This commit is contained in:
parent
ac850bbc0b
commit
d0b2aa8635
@ -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)";
|
||||||
}
|
}
|
||||||
|
@ -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)";
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
@ -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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user