Merge branch 'eugenp:master' into master
This commit is contained in:
commit
290eefa062
|
@ -22,4 +22,9 @@ public class Car implements Vehicle {
|
|||
public String slowDown() {
|
||||
return "The car is slowing down.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getSpeed() {
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -22,4 +22,9 @@ public class Motorbike implements Vehicle {
|
|||
public String slowDown() {
|
||||
return "The motorbike is slowing down.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getSpeed() {
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -32,4 +32,9 @@ public class MultiAlarmCar implements Vehicle, Alarm {
|
|||
public String turnAlarmOff() {
|
||||
return Vehicle.super.turnAlarmOff() + " " + Alarm.super.turnAlarmOff();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getSpeed() {
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -19,4 +19,10 @@ public interface Vehicle {
|
|||
static int getHorsePower(int rpm, int torque) {
|
||||
return (rpm * torque) / 5252;
|
||||
}
|
||||
|
||||
double getSpeed();
|
||||
|
||||
default double getSpeedInKMH(double speed) {
|
||||
return speed * 1.60934;
|
||||
}
|
||||
}
|
|
@ -84,5 +84,14 @@ public class Pizza {
|
|||
this.setStatus(PizzaStatusEnum.DELIVERED);
|
||||
}
|
||||
}
|
||||
|
||||
public int getDeliveryTimeInDays() {
|
||||
switch (status) {
|
||||
case ORDERED: return 5;
|
||||
case READY: return 2;
|
||||
case DELIVERED: return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -70,7 +70,7 @@ public class PizzaUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void whenDelivered_thenPizzaGetsDeliveredAndStatusChanges() {
|
||||
public void givenPizaOrder_whenDelivered_thenPizzaGetsDeliveredAndStatusChanges() {
|
||||
Pizza pz = new Pizza();
|
||||
pz.setStatus(Pizza.PizzaStatusEnum.READY);
|
||||
pz.deliver();
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package com.baeldung.reduce.entities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Rating {
|
||||
|
||||
double points;
|
||||
List<Review> reviews = new ArrayList<>();
|
||||
|
||||
public Rating() {}
|
||||
|
||||
public void add(Review review) {
|
||||
reviews.add(review);
|
||||
computeRating();
|
||||
}
|
||||
|
||||
private double computeRating() {
|
||||
double totalPoints = reviews.stream().map(Review::getPoints).reduce(0, Integer::sum);
|
||||
this.points = totalPoints / reviews.size();
|
||||
return this.points;
|
||||
}
|
||||
|
||||
public static Rating average(Rating r1, Rating r2) {
|
||||
Rating combined = new Rating();
|
||||
combined.reviews = new ArrayList<>(r1.reviews);
|
||||
combined.reviews.addAll(r2.reviews);
|
||||
combined.computeRating();
|
||||
return combined;
|
||||
}
|
||||
|
||||
public double getPoints() {
|
||||
return points;
|
||||
}
|
||||
|
||||
public List<Review> getReviews() {
|
||||
return reviews;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.baeldung.reduce.entities;
|
||||
|
||||
public class Review {
|
||||
|
||||
int points;
|
||||
String review;
|
||||
|
||||
public Review(int points, String review) {
|
||||
this.points = points;
|
||||
this.review = review;
|
||||
}
|
||||
|
||||
public int getPoints() {
|
||||
return points;
|
||||
}
|
||||
|
||||
public void setPoints(int points) {
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
public String getReview() {
|
||||
return review;
|
||||
}
|
||||
|
||||
public void setReview(String review) {
|
||||
this.review = review;
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ import com.baeldung.jersey.client.filter.AddHeaderOnRequestFilter;
|
|||
import org.glassfish.jersey.media.sse.SseFeature;
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
import org.glassfish.jersey.test.JerseyTest;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.ws.rs.core.Application;
|
||||
|
@ -16,6 +17,7 @@ import java.util.Map;
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
@Ignore
|
||||
public class EchoHeadersUnitTest extends JerseyTest {
|
||||
|
||||
private static final String SIMPLE_HEADER_KEY = "my-header-key";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.baeldung.s;
|
||||
|
||||
public class GoodBook {
|
||||
public class Book {
|
||||
|
||||
private String name;
|
||||
private String author;
|
|
@ -34,7 +34,7 @@ public class CasCadeTypeUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testPersist() {
|
||||
public void whenParentSavedThenChildSaved() {
|
||||
Person person = new Person();
|
||||
Address address = new Address();
|
||||
address.setPerson(person);
|
||||
|
@ -45,7 +45,7 @@ public class CasCadeTypeUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMerge() {
|
||||
public void whenParentSavedThenMerged() {
|
||||
int addressId;
|
||||
Person person = buildPerson("devender");
|
||||
Address address = buildAddress(person);
|
||||
|
@ -64,7 +64,7 @@ public class CasCadeTypeUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testRemove() {
|
||||
public void whenParentRemovedThenChildRemoved() {
|
||||
int personId;
|
||||
Person person = buildPerson("devender");
|
||||
Address address = buildAddress(person);
|
||||
|
@ -80,12 +80,13 @@ public class CasCadeTypeUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDetach() {
|
||||
public void whenParentDetachedThenChildDetached() {
|
||||
Person person = buildPerson("devender");
|
||||
Address address = buildAddress(person);
|
||||
person.setAddresses(Arrays.asList(address));
|
||||
session.persist(person);
|
||||
session.flush();
|
||||
|
||||
Assertions.assertThat(session.contains(person)).isTrue();
|
||||
Assertions.assertThat(session.contains(address)).isTrue();
|
||||
|
||||
|
@ -95,12 +96,13 @@ public class CasCadeTypeUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testLock() {
|
||||
public void whenDetachedAndLockedThenBothReattached() {
|
||||
Person person = buildPerson("devender");
|
||||
Address address = buildAddress(person);
|
||||
person.setAddresses(Arrays.asList(address));
|
||||
session.persist(person);
|
||||
session.flush();
|
||||
|
||||
Assertions.assertThat(session.contains(person)).isTrue();
|
||||
Assertions.assertThat(session.contains(address)).isTrue();
|
||||
|
||||
|
@ -116,7 +118,7 @@ public class CasCadeTypeUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testRefresh() {
|
||||
public void whenParentRefreshedThenChildRefreshed() {
|
||||
Person person = buildPerson("devender");
|
||||
Address address = buildAddress(person);
|
||||
person.setAddresses(Arrays.asList(address));
|
||||
|
@ -125,12 +127,13 @@ public class CasCadeTypeUnitTest {
|
|||
person.setName("Devender Kumar");
|
||||
address.setHouseNumber(24);
|
||||
session.refresh(person);
|
||||
|
||||
Assertions.assertThat(person.getName()).isEqualTo("devender");
|
||||
Assertions.assertThat(address.getHouseNumber()).isEqualTo(23);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReplicate() {
|
||||
public void whenParentReplicatedThenChildReplicated() {
|
||||
Person person = buildPerson("devender");
|
||||
person.setId(2);
|
||||
Address address = buildAddress(person);
|
||||
|
|
|
@ -56,5 +56,9 @@ public interface UserRepository extends JpaRepository<User, Integer> {
|
|||
List<User> findByNameOrderByName(String name);
|
||||
|
||||
List<User> findByNameOrderByNameDesc(String name);
|
||||
|
||||
List<User> findByNameIsNotNull();
|
||||
|
||||
List<User> findByNameOrderByNameAsc(String name);
|
||||
|
||||
}
|
||||
|
|
|
@ -32,4 +32,9 @@ public class CircularDependencyIntegrationTest {
|
|||
|
||||
Assert.assertEquals("Hi!", circA.getCircB().getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenCircularDependency_whenConstructorInjection_thenItFails() {
|
||||
// Empty test; we just want the context to load
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package com.baeldung.sample;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackages="com.baeldung.primary")
|
||||
public class Config {
|
||||
|
||||
@Bean
|
||||
public Employee johnEmployee(){
|
||||
return new Employee("John");
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public Employee tonyEmployee(){
|
||||
return new Employee("Tony");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.baeldung.sample;
|
||||
|
||||
/**
|
||||
* Created by Gebruiker on 7/17/2018.
|
||||
*/
|
||||
public class Employee {
|
||||
|
||||
private String name;
|
||||
|
||||
public Employee(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Employee{" +
|
||||
"name='" + name + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -9,25 +9,25 @@ import com.baeldung.mutation.Palindrome;
|
|||
|
||||
public class PalindromeUnitTest {
|
||||
@Test
|
||||
public void whenEmptyString_thanAccept() {
|
||||
public void whenEmptyString_thenAccept() {
|
||||
Palindrome palindromeTester = new Palindrome();
|
||||
assertTrue(palindromeTester.isPalindrome(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPalindrom_thanAccept() {
|
||||
public void whenPalindrom_thenAccept() {
|
||||
Palindrome palindromeTester = new Palindrome();
|
||||
assertTrue(palindromeTester.isPalindrome("noon"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNotPalindrom_thanReject(){
|
||||
public void whenNotPalindrom_thenReject(){
|
||||
Palindrome palindromeTester = new Palindrome();
|
||||
assertFalse(palindromeTester.isPalindrome("box"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNearPalindrom_thanReject(){
|
||||
public void whenNearPalindrom_thenReject(){
|
||||
Palindrome palindromeTester = new Palindrome();
|
||||
assertFalse(palindromeTester.isPalindrome("neon"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue