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