Merge pull request #13118 from freelansam/JAVA-16260

JAVA-16301: Check Article Code Matches GitHub
This commit is contained in:
kwoyke 2022-12-07 20:59:38 +01:00 committed by GitHub
commit 85fded9b10
15 changed files with 164 additions and 13 deletions

View File

@ -22,4 +22,9 @@ public class Car implements Vehicle {
public String slowDown() {
return "The car is slowing down.";
}
@Override
public double getSpeed() {
return 0;
}
}

View File

@ -22,4 +22,9 @@ public class Motorbike implements Vehicle {
public String slowDown() {
return "The motorbike is slowing down.";
}
@Override
public double getSpeed() {
return 0;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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();

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -1,6 +1,6 @@
package com.baeldung.s;
public class GoodBook {
public class Book {
private String name;
private String author;

View File

@ -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);

View File

@ -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);
}

View File

@ -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
}
}

View File

@ -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");
}
}

View File

@ -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 + '\'' +
'}';
}
}

View File

@ -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"));
}