🎨 Gradle 6 - Format code
This commit is contained in:
parent
dfb9147fc9
commit
3a26ab3460
|
@ -2,17 +2,19 @@ package com.baeldung.gradle;
|
|||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import io.reactivex.Observable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** Demonstrates a library type that returns an RxJava type. */
|
||||
public class RxHelloWorld {
|
||||
|
||||
/** @return an {@link Observable} that emits events "hello" and "world" before completing. */
|
||||
public static Observable<String> hello() {
|
||||
// Guava ImmutableList class is an implementation detail.
|
||||
List<String> values = ImmutableList.of("hello", "world");
|
||||
return Observable.fromIterable(values);
|
||||
}
|
||||
/** @return an {@link Observable} that emits events "hello" and "world" before completing. */
|
||||
public static Observable<String> hello() {
|
||||
// Guava ImmutableList class is an implementation detail.
|
||||
List<String> values = ImmutableList.of("hello", "world");
|
||||
return Observable.fromIterable(values);
|
||||
}
|
||||
|
||||
private RxHelloWorld() {}
|
||||
private RxHelloWorld() {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
package com.baeldung.gradle;
|
||||
|
||||
import static com.baeldung.gradle.RxHelloWorld.hello;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static com.baeldung.gradle.RxHelloWorld.hello;
|
||||
|
||||
/** Unit test for {@link RxHelloWorld}. */
|
||||
final class RxHelloWorldUnitTest {
|
||||
|
||||
@Test
|
||||
void it_emits_hello_world_values() {
|
||||
hello().test().assertValues("hello", "world").assertComplete();
|
||||
}
|
||||
@Test void it_emits_hello_world_values() {
|
||||
hello().test().assertValues("hello", "world").assertComplete();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,17 +4,15 @@ import com.baeldung.fibonacci.FibonacciSequenceGenerator;
|
|||
import com.google.auto.service.AutoService;
|
||||
|
||||
/** Recursive implementation of the {@link FibonacciSequenceGenerator}. */
|
||||
@AutoService(FibonacciSequenceGenerator.class)
|
||||
public final class RecursiveFibonacci implements FibonacciSequenceGenerator {
|
||||
@AutoService(FibonacciSequenceGenerator.class) public final class RecursiveFibonacci implements FibonacciSequenceGenerator {
|
||||
|
||||
@Override
|
||||
public int generate(int nth) {
|
||||
if (nth < 0) {
|
||||
throw new IllegalArgumentException("sequence number must be 0 or greater");
|
||||
@Override public int generate(int nth) {
|
||||
if (nth < 0) {
|
||||
throw new IllegalArgumentException("sequence number must be 0 or greater");
|
||||
}
|
||||
if (nth <= 1) {
|
||||
return nth;
|
||||
}
|
||||
return generate(nth - 1) + generate(nth - 2);
|
||||
}
|
||||
if (nth <= 1) {
|
||||
return nth;
|
||||
}
|
||||
return generate(nth - 1) + generate(nth - 2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,9 +8,7 @@ import com.baeldung.fibonacci.FibonacciSequenceGeneratorFixture;
|
|||
* the fibonacci-spi project.
|
||||
*/
|
||||
final class RecursiveFibonacciUnitTest implements FibonacciSequenceGeneratorFixture {
|
||||
|
||||
@Override
|
||||
public FibonacciSequenceGenerator provide() {
|
||||
return new RecursiveFibonacci();
|
||||
}
|
||||
@Override public FibonacciSequenceGenerator provide() {
|
||||
return new RecursiveFibonacci();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,9 @@ package com.baeldung.fibonacci;
|
|||
/** Describes an SPI for a Fibonacci sequence generator function. */
|
||||
public interface FibonacciSequenceGenerator {
|
||||
|
||||
/**
|
||||
* @param nth the index of the number in the fibonacci sequence
|
||||
* @return the nth number in the fibonacci sequence
|
||||
*/
|
||||
int generate(int nth);
|
||||
/**
|
||||
* @param nth the index of the number in the fibonacci sequence
|
||||
* @return the nth number in the fibonacci sequence
|
||||
*/
|
||||
int generate(int nth);
|
||||
}
|
||||
|
|
|
@ -1,31 +1,29 @@
|
|||
package com.baeldung.fibonacci;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Reusable test fixture for {@link FibonacciSequenceGenerator} implementations. Tests will be
|
||||
* skipped if no such implementation exists.
|
||||
*/
|
||||
public interface FibonacciSequenceGeneratorFixture {
|
||||
|
||||
/** @return the implementation of {@link FibonacciSequenceGenerator} to test. Must not be null */
|
||||
FibonacciSequenceGenerator provide();
|
||||
/** @return the implementation of {@link FibonacciSequenceGenerator} to test. Must not be null */
|
||||
FibonacciSequenceGenerator provide();
|
||||
|
||||
@Test
|
||||
default void when_sequence_index_is_negative_then_throws() {
|
||||
final FibonacciSequenceGenerator generator = provide();
|
||||
assertThrows(IllegalArgumentException.class, () -> generator.generate(-1));
|
||||
}
|
||||
|
||||
@Test
|
||||
default void when_given_index_then_generates_fibonacci_number() {
|
||||
final FibonacciSequenceGenerator generator = provide();
|
||||
final int[] sequence = {0, 1, 1, 2, 3, 5, 8};
|
||||
for (int i = 0; i < sequence.length; i++) {
|
||||
assertEquals(sequence[i], generator.generate(i));
|
||||
@Test default void when_sequence_index_is_negative_then_throws() {
|
||||
final FibonacciSequenceGenerator generator = provide();
|
||||
assertThrows(IllegalArgumentException.class, () -> generator.generate(-1));
|
||||
}
|
||||
|
||||
@Test default void when_given_index_then_generates_fibonacci_number() {
|
||||
final FibonacciSequenceGenerator generator = provide();
|
||||
final int[] sequence = { 0, 1, 1, 2, 3, 5, 8 };
|
||||
for (int i = 0; i < sequence.length; i++) {
|
||||
assertEquals(sequence[i], generator.generate(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue