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)
|
||||
public class BingTranslationServiceProvider implements TranslationService {
|
||||
|
||||
@Override
|
||||
public String translate(String message, Locale from, Locale to) {
|
||||
|
||||
// implementation details
|
||||
return message + " (translated by Bing)";
|
||||
}
|
||||
|
|
|
@ -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)";
|
||||
}
|
||||
|
|
|
@ -3,6 +3,5 @@ package com.baeldung.autoservice;
|
|||
import java.util.Locale;
|
||||
|
||||
public interface TranslationService {
|
||||
|
||||
String translate(String message, Locale from, Locale to);
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue