Merge remote-tracking branch 'eugenp/master'
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
package com.baeldung
|
||||
|
||||
class Car implements VehicleTrait {}
|
||||
@@ -22,7 +22,7 @@ trait UserTrait implements Human {
|
||||
msg
|
||||
}
|
||||
|
||||
def whoAmI() {
|
||||
def self() {
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.baeldung
|
||||
|
||||
trait VehicleTrait extends WheelTrait {
|
||||
|
||||
String showWheels() {
|
||||
return "Num of Wheels $noOfWheels"
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.baeldung
|
||||
|
||||
trait WheelTrait {
|
||||
|
||||
int noOfWheels
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.baeldung.map
|
||||
|
||||
import static org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
class MapUnitTest {
|
||||
|
||||
@Test
|
||||
void whenUsingEach_thenMapIsIterated() {
|
||||
def map = [
|
||||
'FF0000' : 'Red',
|
||||
'00FF00' : 'Lime',
|
||||
'0000FF' : 'Blue',
|
||||
'FFFF00' : 'Yellow'
|
||||
]
|
||||
|
||||
map.each { println "Hex Code: $it.key = Color Name: $it.value" }
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingEachWithEntry_thenMapIsIterated() {
|
||||
def map = [
|
||||
'E6E6FA' : 'Lavender',
|
||||
'D8BFD8' : 'Thistle',
|
||||
'DDA0DD' : 'Plum',
|
||||
]
|
||||
|
||||
map.each { entry -> println "Hex Code: $entry.key = Color Name: $entry.value" }
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingEachWithKeyAndValue_thenMapIsIterated() {
|
||||
def map = [
|
||||
'000000' : 'Black',
|
||||
'FFFFFF' : 'White',
|
||||
'808080' : 'Gray'
|
||||
]
|
||||
|
||||
map.each { key, val ->
|
||||
println "Hex Code: $key = Color Name $val"
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingEachWithIndexAndEntry_thenMapIsIterated() {
|
||||
def map = [
|
||||
'800080' : 'Purple',
|
||||
'4B0082' : 'Indigo',
|
||||
'6A5ACD' : 'Slate Blue'
|
||||
]
|
||||
|
||||
map.eachWithIndex { entry, index ->
|
||||
def indent = ((index == 0 || index % 2 == 0) ? " " : "")
|
||||
println "$indent Hex Code: $entry.key = Color Name: $entry.value"
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingEachWithIndexAndKeyAndValue_thenMapIsIterated() {
|
||||
def map = [
|
||||
'FFA07A' : 'Light Salmon',
|
||||
'FF7F50' : 'Coral',
|
||||
'FF6347' : 'Tomato',
|
||||
'FF4500' : 'Orange Red'
|
||||
]
|
||||
|
||||
map.eachWithIndex { key, val, index ->
|
||||
def indent = ((index == 0 || index % 2 == 0) ? " " : "")
|
||||
println "$indent Hex Code: $key = Color Name: $val"
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingForLoop_thenMapIsIterated() {
|
||||
def map = [
|
||||
'2E8B57' : 'Seagreen',
|
||||
'228B22' : 'Forest Green',
|
||||
'008000' : 'Green'
|
||||
]
|
||||
|
||||
for (entry in map) {
|
||||
println "Hex Code: $entry.key = Color Name: $entry.value"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ class TraitsUnitTest extends Specification {
|
||||
|
||||
def 'Should return employee instance when using Employee.whoAmI method' () {
|
||||
when:
|
||||
def emp = employee.whoAmI()
|
||||
def emp = employee.self()
|
||||
then:
|
||||
emp
|
||||
emp instanceof Employee
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.baeldung.streamreduce.application;
|
||||
|
||||
import com.baeldung.streamreduce.entities.User;
|
||||
import com.baeldung.streamreduce.utilities.NumberUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||
int result1 = numbers.stream().reduce(0, (a, b) -> a + b);
|
||||
System.out.println(result1);
|
||||
|
||||
int result2 = numbers.stream().reduce(0, Integer::sum);
|
||||
System.out.println(result2);
|
||||
|
||||
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
|
||||
String result3 = letters.stream().reduce("", (a, b) -> a + b);
|
||||
System.out.println(result3);
|
||||
|
||||
String result4 = letters.stream().reduce("", String::concat);
|
||||
System.out.println(result4);
|
||||
|
||||
String result5 = letters.stream().reduce("", (a, b) -> a.toUpperCase() + b.toUpperCase());
|
||||
System.out.println(result5);
|
||||
|
||||
List<User> users = Arrays.asList(new User("John", 30), new User("Julie", 35));
|
||||
int result6 = users.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
|
||||
System.out.println(result6);
|
||||
|
||||
String result7 = letters.parallelStream().reduce("", String::concat);
|
||||
System.out.println(result7);
|
||||
|
||||
int result8 = users.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
|
||||
System.out.println(result8);
|
||||
|
||||
List<User> userList = new ArrayList<>();
|
||||
for (int i = 0; i <= 1000000; i++) {
|
||||
userList.add(new User("John" + i, i));
|
||||
}
|
||||
|
||||
long t1 = System.currentTimeMillis();
|
||||
int result9 = userList.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
|
||||
long t2 = System.currentTimeMillis();
|
||||
System.out.println(result9);
|
||||
System.out.println("Sequential stream time: " + (t2 - t1) + "ms");
|
||||
|
||||
long t3 = System.currentTimeMillis();
|
||||
int result10 = userList.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
|
||||
long t4 = System.currentTimeMillis();
|
||||
System.out.println(result10);
|
||||
System.out.println("Parallel stream time: " + (t4 - t3) + "ms");
|
||||
|
||||
int result11 = NumberUtils.divideListElements(numbers, 1);
|
||||
System.out.println(result11);
|
||||
|
||||
int result12 = NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 0);
|
||||
System.out.println(result12);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.baeldung.streamreduce.entities;
|
||||
|
||||
public class User {
|
||||
|
||||
private final String name;
|
||||
private final int age;
|
||||
|
||||
public User(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" + "name=" + name + ", age=" + age + '}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.baeldung.streamreduce.utilities;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public abstract class NumberUtils {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(NumberUtils.class.getName());
|
||||
|
||||
public static int divideListElements(List<Integer> values, Integer divider) {
|
||||
return values.stream()
|
||||
.reduce(0, (a, b) -> {
|
||||
try {
|
||||
return a / divider + b / divider;
|
||||
} catch (ArithmeticException e) {
|
||||
LOGGER.log(Level.INFO, "Arithmetic Exception: Division by Zero");
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
public static int divideListElementsWithExtractedTryCatchBlock(List<Integer> values, int divider) {
|
||||
return values.stream().reduce(0, (a, b) -> divide(a, divider) + divide(b, divider));
|
||||
}
|
||||
|
||||
public static int divideListElementsWithApplyFunctionMethod(List<Integer> values, int divider) {
|
||||
BiFunction<Integer, Integer, Integer> division = (a, b) -> a / b;
|
||||
return values.stream().reduce(0, (a, b) -> applyFunction(division, a, divider) + applyFunction(division, b, divider));
|
||||
}
|
||||
|
||||
private static int divide(int value, int factor) {
|
||||
int result = 0;
|
||||
try {
|
||||
result = value / factor;
|
||||
} catch (ArithmeticException e) {
|
||||
LOGGER.log(Level.INFO, "Arithmetic Exception: Division by Zero");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int applyFunction(BiFunction<Integer, Integer, Integer> function, int a, int b) {
|
||||
try {
|
||||
return function.apply(a, b);
|
||||
}
|
||||
catch(Exception e) {
|
||||
LOGGER.log(Level.INFO, "Exception occurred!");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
package com.baeldung.streamreduce.tests;
|
||||
|
||||
import com.baeldung.streamreduce.entities.User;
|
||||
import com.baeldung.streamreduce.utilities.NumberUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import org.junit.Test;
|
||||
|
||||
public class StreamReduceManualTest {
|
||||
|
||||
@Test
|
||||
public void givenIntegerList_whenReduceWithSumAccumulatorLambda_thenCorrect() {
|
||||
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||
|
||||
int result = numbers.stream().reduce(0, (a, b) -> a + b);
|
||||
|
||||
assertThat(result).isEqualTo(21);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenIntegerList_whenReduceWithSumAccumulatorMethodReference_thenCorrect() {
|
||||
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||
|
||||
int result = numbers.stream().reduce(0, Integer::sum);
|
||||
|
||||
assertThat(result).isEqualTo(21);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStringList_whenReduceWithConcatenatorAccumulatorLambda_thenCorrect() {
|
||||
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
|
||||
|
||||
String result = letters.stream().reduce("", (a, b) -> a + b);
|
||||
|
||||
assertThat(result).isEqualTo("abcde");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStringList_whenReduceWithConcatenatorAccumulatorMethodReference_thenCorrect() {
|
||||
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
|
||||
|
||||
String result = letters.stream().reduce("", String::concat);
|
||||
|
||||
assertThat(result).isEqualTo("abcde");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStringList_whenReduceWithUppercaseConcatenatorAccumulator_thenCorrect() {
|
||||
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
|
||||
|
||||
String result = letters.stream().reduce("", (a, b) -> a.toUpperCase() + b.toUpperCase());
|
||||
|
||||
assertThat(result).isEqualTo("ABCDE");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenUserList_whenReduceWithAgeAccumulatorAndSumCombiner_thenCorrect() {
|
||||
List<User> users = Arrays.asList(new User("John", 30), new User("Julie", 35));
|
||||
|
||||
int result = users.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
|
||||
|
||||
assertThat(result).isEqualTo(65);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStringList_whenReduceWithParallelStream_thenCorrect() {
|
||||
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
|
||||
|
||||
String result = letters.parallelStream().reduce("", String::concat);
|
||||
|
||||
assertThat(result).isEqualTo("abcde");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNumberUtilsClass_whenCalledDivideListElements_thenCorrect() {
|
||||
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||
|
||||
assertThat(NumberUtils.divideListElements(numbers, 1)).isEqualTo(21);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNumberUtilsClass_whenCalledDivideListElementsWithExtractedTryCatchBlock_thenCorrect() {
|
||||
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||
|
||||
assertThat(NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 1)).isEqualTo(21);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNumberUtilsClass_whenCalledDivideListElementsWithExtractedTryCatchBlockAndListContainsZero_thenCorrect() {
|
||||
List<Integer> numbers = Arrays.asList(0, 1, 2, 3, 4, 5, 6);
|
||||
|
||||
assertThat(NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 1)).isEqualTo(21);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNumberUtilsClass_whenCalledDivideListElementsWithExtractedTryCatchBlockAndDividerIsZero_thenCorrect() {
|
||||
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||
|
||||
assertThat(NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 0)).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStream_whneCalleddivideListElementsWithApplyFunctionMethod_thenCorrect() {
|
||||
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||
|
||||
assertThat(NumberUtils.divideListElementsWithApplyFunctionMethod(numbers, 1)).isEqualTo(21);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoStreams_whenCalledReduceOnParallelizedStream_thenFasterExecutionTime() {
|
||||
List<User> userList = new ArrayList<>();
|
||||
for (int i = 0; i <= 1000000; i++) {
|
||||
userList.add(new User("John" + i, i));
|
||||
}
|
||||
long currentTime1 = System.currentTimeMillis();
|
||||
userList.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
|
||||
long sequentialExecutionTime = System.currentTimeMillis() -currentTime1;
|
||||
long currentTime2 = System.currentTimeMillis();
|
||||
userList.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
|
||||
long parallelizedExecutionTime = System.currentTimeMillis() - currentTime2;
|
||||
|
||||
assertThat(parallelizedExecutionTime).isLessThan(sequentialExecutionTime);
|
||||
}
|
||||
}
|
||||
@@ -27,3 +27,4 @@
|
||||
- [Flattening Nested Collections in Java](http://www.baeldung.com/java-flatten-nested-collections)
|
||||
- [Intersection of Two Lists in Java](https://www.baeldung.com/java-lists-intersection)
|
||||
- [Multi Dimensional ArrayList in Java](https://www.baeldung.com/java-multi-dimensional-arraylist)
|
||||
- [Determine If All Elements Are the Same in a Java List](https://www.baeldung.com/java-list-all-equal)
|
||||
|
||||
@@ -52,6 +52,17 @@
|
||||
<artifactId>colt</artifactId>
|
||||
<version>${colt.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
package com.baeldung.list.primitive;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import gnu.trove.list.array.TIntArrayList;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
import org.openjdk.jmh.runner.Runner;
|
||||
import org.openjdk.jmh.runner.options.Options;
|
||||
import org.openjdk.jmh.runner.options.OptionsBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@BenchmarkMode(Mode.SingleShotTime)
|
||||
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||
@Measurement(batchSize = 100000, iterations = 10)
|
||||
@Warmup(batchSize = 100000, iterations = 10)
|
||||
@State(Scope.Thread)
|
||||
public class PrimitivesListPerformance {
|
||||
|
||||
private List<Integer> arrayList = new ArrayList<>();
|
||||
private TIntArrayList tList = new TIntArrayList();
|
||||
private cern.colt.list.IntArrayList coltList = new cern.colt.list.IntArrayList();
|
||||
private IntArrayList fastUtilList = new IntArrayList();
|
||||
|
||||
private int getValue = 10;
|
||||
|
||||
@Benchmark
|
||||
public boolean addArrayList() {
|
||||
return arrayList.add(getValue);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public boolean addTroveIntList() {
|
||||
return tList.add(getValue);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void addColtIntList() {
|
||||
coltList.add(getValue);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public boolean addFastUtilIntList() {
|
||||
return fastUtilList.add(getValue);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public int getArrayList() {
|
||||
return arrayList.get(getValue);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public int getTroveIntList() {
|
||||
return tList.get(getValue);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public int getColtIntList() {
|
||||
return coltList.get(getValue);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public int getFastUtilIntList() {
|
||||
return fastUtilList.getInt(getValue);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public boolean containsArrayList() {
|
||||
return arrayList.contains(getValue);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public boolean containsTroveIntList() {
|
||||
return tList.contains(getValue);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public boolean containsColtIntList() {
|
||||
return coltList.contains(getValue);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public boolean containsFastUtilIntList() {
|
||||
return fastUtilList.contains(getValue);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Options options = new OptionsBuilder()
|
||||
.include(PrimitivesListPerformance.class.getSimpleName()).threads(1)
|
||||
.forks(1).shouldFailOnError(true)
|
||||
.shouldDoGC(true)
|
||||
.jvmArgs("-server").build();
|
||||
new Runner(options).run();
|
||||
}
|
||||
}
|
||||
+5
-4
@@ -9,10 +9,10 @@
|
||||
<description>DDD series examples</description>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.0.6.RELEASE</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
@@ -86,6 +86,7 @@
|
||||
<properties>
|
||||
<joda-money.version>1.0.1</joda-money.version>
|
||||
<maven-surefire-plugin.version>2.22.0</maven-surefire-plugin.version>
|
||||
<spring-boot.version>2.0.6.RELEASE</spring-boot.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
+1
-1
@@ -11,7 +11,7 @@ import org.joda.money.Money;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class OrderTest {
|
||||
class OrderUnitTest {
|
||||
@DisplayName("given order with two items, when calculate total cost, then sum is returned")
|
||||
@Test
|
||||
void test0() throws Exception {
|
||||
+1
-1
@@ -7,7 +7,7 @@ import java.math.BigDecimal;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ViolateOrderBusinessRulesTest {
|
||||
public class ViolateOrderBusinessRulesUnitTest {
|
||||
@DisplayName("given two non-zero order line items, when create an order with them, it's possible to set total cost to zero")
|
||||
@Test
|
||||
void test() throws Exception {
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.baeldung.gson.conversion;
|
||||
|
||||
import com.google.gson.*;
|
||||
import org.junit.Assert;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class JsonObjectConversionsUnitTest {
|
||||
|
||||
@Test
|
||||
void whenUsingJsonParser_thenConvertToJsonObject() throws Exception {
|
||||
// Example 1: Using JsonParser
|
||||
String json = "{ \"name\": \"Baeldung\", \"java\": true }";
|
||||
|
||||
JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();
|
||||
|
||||
Assert.assertTrue(jsonObject.isJsonObject());
|
||||
Assert.assertTrue(jsonObject.get("name").getAsString().equals("Baeldung"));
|
||||
Assert.assertTrue(jsonObject.get("java").getAsBoolean() == true);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingGsonInstanceFromJson_thenConvertToJsonObject() throws Exception {
|
||||
// Example 2: Using fromJson
|
||||
String json = "{ \"name\": \"Baeldung\", \"java\": true }";
|
||||
|
||||
JsonObject convertedObject = new Gson().fromJson(json, JsonObject.class);
|
||||
|
||||
Assert.assertTrue(convertedObject.isJsonObject());
|
||||
Assert.assertTrue(convertedObject.get("name").getAsString().equals("Baeldung"));
|
||||
Assert.assertTrue(convertedObject.get("java").getAsBoolean() == true);
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -21,7 +21,7 @@ import com.stackify.Application;
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class)
|
||||
@WebAppConfiguration
|
||||
public class EmployeeControllerTest {
|
||||
public class EmployeeControllerUnitTest {
|
||||
|
||||
private static final String CONTENT_TYPE = "application/json;charset=UTF-8";
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.baeldung.jackson.dtos;
|
||||
|
||||
public class Address {
|
||||
|
||||
String streetNumber;
|
||||
String streetName;
|
||||
String city;
|
||||
|
||||
public String getStreetNumber() {
|
||||
return streetNumber;
|
||||
}
|
||||
|
||||
public void setStreetNumber(String streetNumber) {
|
||||
this.streetNumber = streetNumber;
|
||||
}
|
||||
|
||||
public String getStreetName() {
|
||||
return streetName;
|
||||
}
|
||||
|
||||
public void setStreetName(String streetName) {
|
||||
this.streetName = streetName;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.baeldung.jackson.dtos;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
|
||||
|
||||
@JacksonXmlRootElement(localName = "person")
|
||||
public final class Person {
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private List<String> phoneNumbers = new ArrayList<>();
|
||||
private List<Address> address = new ArrayList<>();
|
||||
|
||||
public List<Address> getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(List<Address> address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public List<String> getPhoneNumbers() {
|
||||
return phoneNumbers;
|
||||
}
|
||||
|
||||
public void setPhoneNumbers(List<String> phoneNumbers) {
|
||||
this.phoneNumbers = phoneNumbers;
|
||||
}
|
||||
|
||||
}
|
||||
+69
-11
@@ -2,19 +2,25 @@ package com.baeldung.jackson.xml;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.jackson.dtos.Address;
|
||||
import com.baeldung.jackson.dtos.Person;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class XMLSerializeDeserializeUnitTest {
|
||||
|
||||
@@ -49,24 +55,76 @@ public class XMLSerializeDeserializeUnitTest {
|
||||
assertTrue(value.getX() == 1 && value.getY() == 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test
|
||||
public void whenJavaGotFromXmlStrWithCapitalElem_thenCorrect() throws IOException {
|
||||
XmlMapper xmlMapper = new XmlMapper();
|
||||
SimpleBeanForCapitalizedFields value = xmlMapper.
|
||||
readValue("<SimpleBeanForCapitalizedFields><X>1</X><y>2</y></SimpleBeanForCapitalizedFields>",
|
||||
SimpleBeanForCapitalizedFields.class);
|
||||
SimpleBeanForCapitalizedFields value = xmlMapper.readValue("<SimpleBeanForCapitalizedFields><X>1</X><y>2</y></SimpleBeanForCapitalizedFields>", SimpleBeanForCapitalizedFields.class);
|
||||
assertTrue(value.getX() == 1 && value.getY() == 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenJavaSerializedToXmlFileWithCapitalizedField_thenCorrect() throws IOException {
|
||||
XmlMapper xmlMapper = new XmlMapper();
|
||||
xmlMapper.writeValue(new File("target/simple_bean_capitalized.xml"),
|
||||
new SimpleBeanForCapitalizedFields());
|
||||
xmlMapper.writeValue(new File("target/simple_bean_capitalized.xml"), new SimpleBeanForCapitalizedFields());
|
||||
File file = new File("target/simple_bean_capitalized.xml");
|
||||
assertNotNull(file);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenJavaDeserializedFromXmlFile_thenCorrect() throws IOException {
|
||||
XmlMapper xmlMapper = new XmlMapper();
|
||||
|
||||
String xml = "<person><firstName>Rohan</firstName><lastName>Daye</lastName><phoneNumbers><phoneNumbers>9911034731</phoneNumbers><phoneNumbers>9911033478</phoneNumbers></phoneNumbers><address><address><streetNumber>1</streetNumber><streetName>Name1</streetName><city>City1</city></address><address><streetNumber>2</streetNumber><streetName>Name2</streetName><city>City2</city></address></address></person>";
|
||||
Person value = xmlMapper.readValue(xml, Person.class);
|
||||
|
||||
assertTrue(value.getAddress()
|
||||
.get(0)
|
||||
.getCity()
|
||||
.equalsIgnoreCase("city1")
|
||||
&& value.getAddress()
|
||||
.get(1)
|
||||
.getCity()
|
||||
.equalsIgnoreCase("city2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenJavaSerializedToXmlFile_thenSuccess() throws IOException {
|
||||
XmlMapper xmlMapper = new XmlMapper();
|
||||
|
||||
String expectedXml = "<person><firstName>Rohan</firstName><lastName>Daye</lastName><phoneNumbers><phoneNumbers>9911034731</phoneNumbers><phoneNumbers>9911033478</phoneNumbers></phoneNumbers><address><address><streetNumber>1</streetNumber><streetName>Name1</streetName><city>City1</city></address><address><streetNumber>2</streetNumber><streetName>Name2</streetName><city>City2</city></address></address></person>";
|
||||
|
||||
Person person = new Person();
|
||||
|
||||
person.setFirstName("Rohan");
|
||||
person.setLastName("Daye");
|
||||
|
||||
List<String> ph = new ArrayList<>();
|
||||
ph.add("9911034731");
|
||||
ph.add("9911033478");
|
||||
person.setPhoneNumbers(ph);
|
||||
|
||||
List<Address> addresses = new ArrayList<>();
|
||||
|
||||
Address address1 = new Address();
|
||||
address1.setStreetNumber("1");
|
||||
address1.setStreetName("Name1");
|
||||
address1.setCity("City1");
|
||||
|
||||
Address address2 = new Address();
|
||||
address2.setStreetNumber("2");
|
||||
address2.setStreetName("Name2");
|
||||
address2.setCity("City2");
|
||||
|
||||
addresses.add(address1);
|
||||
addresses.add(address2);
|
||||
|
||||
person.setAddress(addresses);
|
||||
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
xmlMapper.writeValue(byteArrayOutputStream, person);
|
||||
assertEquals(expectedXml, byteArrayOutputStream.toString());
|
||||
}
|
||||
|
||||
private static String inputStreamToString(InputStream is) throws IOException {
|
||||
BufferedReader br;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@@ -103,10 +161,10 @@ class SimpleBean {
|
||||
|
||||
}
|
||||
|
||||
class SimpleBeanForCapitalizedFields {
|
||||
@JsonProperty("X")
|
||||
private int x = 1;
|
||||
private int y = 2;
|
||||
class SimpleBeanForCapitalizedFields {
|
||||
@JsonProperty("X")
|
||||
private int x = 1;
|
||||
private int y = 2;
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
|
||||
+9
-4
@@ -9,8 +9,10 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.collections4.MultiMapUtils;
|
||||
import org.apache.commons.collections4.MultiSet;
|
||||
import org.apache.commons.collections4.MultiValuedMap;
|
||||
import org.apache.commons.collections4.multimap.ArrayListValuedHashMap;
|
||||
import org.apache.commons.collections4.multimap.HashSetValuedHashMap;
|
||||
@@ -65,25 +67,28 @@ public class MultiValuedMapUnitTest {
|
||||
@Test
|
||||
public void givenMultiValuesMap_whenUsingKeysMethod_thenReturningAllKeys() {
|
||||
MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
|
||||
|
||||
map.put("fruits", "apple");
|
||||
map.put("fruits", "orange");
|
||||
map.put("vehicles", "car");
|
||||
map.put("vehicles", "bike");
|
||||
|
||||
assertThat(((Collection<String>) map.keys())).contains("fruits", "vehicles");
|
||||
MultiSet<String> keys = map.keys();
|
||||
|
||||
assertThat((keys)).contains("fruits", "vehicles");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenMultiValuesMap_whenUsingKeySetMethod_thenReturningAllKeys() {
|
||||
MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
|
||||
|
||||
map.put("fruits", "apple");
|
||||
map.put("fruits", "orange");
|
||||
map.put("vehicles", "car");
|
||||
map.put("vehicles", "bike");
|
||||
|
||||
assertThat((Collection<String>) map.keySet()).contains("fruits", "vehicles");
|
||||
Set<String> keys = map.keySet();
|
||||
|
||||
assertThat(keys).contains("fruits", "vehicles");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,12 @@
|
||||
<version>${commons-collections4.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj-core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
@@ -86,6 +92,7 @@
|
||||
<jackson-databind.version>2.9.7</jackson-databind.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
<javax.version>1.1.2</javax.version>
|
||||
<assertj-core.version>3.11.1</assertj-core.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.baeldung.jsonobject.iterate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class JSONObjectIterator {
|
||||
|
||||
private Map<String, Object> keyValuePairs;
|
||||
|
||||
public JSONObjectIterator() {
|
||||
keyValuePairs = new HashMap<>();
|
||||
}
|
||||
|
||||
public void handleValue(String key, Object value) {
|
||||
if (value instanceof JSONArray) {
|
||||
handleJSONArray(key, (JSONArray) value);
|
||||
} else if (value instanceof JSONObject) {
|
||||
handleJSONObject((JSONObject) value);
|
||||
}
|
||||
keyValuePairs.put(key, value);
|
||||
}
|
||||
|
||||
public void handleJSONObject(JSONObject jsonObject) {
|
||||
Iterator<String> jsonObjectIterator = jsonObject.keys();
|
||||
jsonObjectIterator.forEachRemaining(key -> {
|
||||
Object value = jsonObject.get(key);
|
||||
handleValue(key, value);
|
||||
});
|
||||
}
|
||||
|
||||
public void handleJSONArray(String key, JSONArray jsonArray) {
|
||||
Iterator<Object> jsonArrayIterator = jsonArray.iterator();
|
||||
jsonArrayIterator.forEachRemaining(element -> {
|
||||
handleValue(key, element);
|
||||
});
|
||||
}
|
||||
|
||||
public Map<String, Object> getKeyValuePairs() {
|
||||
return keyValuePairs;
|
||||
}
|
||||
|
||||
public void setKeyValuePairs(Map<String, Object> keyValuePairs) {
|
||||
this.keyValuePairs = keyValuePairs;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.baeldung.jsonobject.iterate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Test;
|
||||
|
||||
public class JSONObjectIteratorUnitTest {
|
||||
|
||||
private JSONObjectIterator jsonObjectIterator = new JSONObjectIterator();
|
||||
|
||||
@Test
|
||||
public void givenJSONObject_whenIterating_thenGetKeyValuePairs() {
|
||||
JSONObject jsonObject = getJsonObject();
|
||||
|
||||
jsonObjectIterator.handleJSONObject(jsonObject);
|
||||
|
||||
Map<String, Object> keyValuePairs = jsonObjectIterator.getKeyValuePairs();
|
||||
assertThat(keyValuePairs.get("rType")).isEqualTo("Regular");
|
||||
assertThat(keyValuePairs.get("rId")).isEqualTo("1001");
|
||||
assertThat(keyValuePairs.get("cType")).isEqualTo("Chocolate");
|
||||
assertThat(keyValuePairs.get("cId")).isEqualTo("1002");
|
||||
assertThat(keyValuePairs.get("bType")).isEqualTo("BlueBerry");
|
||||
assertThat(keyValuePairs.get("bId")).isEqualTo("1003");
|
||||
assertThat(keyValuePairs.get("name")).isEqualTo("Cake");
|
||||
assertThat(keyValuePairs.get("cakeId")).isEqualTo("0001");
|
||||
assertThat(keyValuePairs.get("type")).isEqualTo("donut");
|
||||
assertThat(keyValuePairs.get("Type")).isEqualTo("Maple");
|
||||
assertThat(keyValuePairs.get("tId")).isEqualTo("5001");
|
||||
assertThat(keyValuePairs.get("batters")
|
||||
.toString()).isEqualTo("[{\"rType\":\"Regular\",\"rId\":\"1001\"},{\"cType\":\"Chocolate\",\"cId\":\"1002\"},{\"bType\":\"BlueBerry\",\"bId\":\"1003\"}]");
|
||||
assertThat(keyValuePairs.get("cakeShapes")
|
||||
.toString()).isEqualTo("[\"square\",\"circle\",\"heart\"]");
|
||||
assertThat(keyValuePairs.get("topping")
|
||||
.toString()).isEqualTo("{\"Type\":\"Maple\",\"tId\":\"5001\"}");
|
||||
}
|
||||
|
||||
private JSONObject getJsonObject() {
|
||||
JSONObject cake = new JSONObject();
|
||||
cake.put("cakeId", "0001");
|
||||
cake.put("type", "donut");
|
||||
cake.put("name", "Cake");
|
||||
|
||||
JSONArray batters = new JSONArray();
|
||||
JSONObject regular = new JSONObject();
|
||||
regular.put("rId", "1001");
|
||||
regular.put("rType", "Regular");
|
||||
batters.put(regular);
|
||||
JSONObject chocolate = new JSONObject();
|
||||
chocolate.put("cId", "1002");
|
||||
chocolate.put("cType", "Chocolate");
|
||||
batters.put(chocolate);
|
||||
JSONObject blueberry = new JSONObject();
|
||||
blueberry.put("bId", "1003");
|
||||
blueberry.put("bType", "BlueBerry");
|
||||
batters.put(blueberry);
|
||||
|
||||
JSONArray cakeShapes = new JSONArray();
|
||||
cakeShapes.put("square");
|
||||
cakeShapes.put("circle");
|
||||
cakeShapes.put("heart");
|
||||
|
||||
cake.put("cakeShapes", cakeShapes);
|
||||
|
||||
cake.put("batters", batters);
|
||||
|
||||
JSONObject topping = new JSONObject();
|
||||
topping.put("tId", "5001");
|
||||
topping.put("Type", "Maple");
|
||||
|
||||
cake.put("topping", topping);
|
||||
|
||||
return cake;
|
||||
}
|
||||
|
||||
}
|
||||
+5
-4
@@ -10,10 +10,10 @@
|
||||
<description>JEE JTA demo</description>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.0.4.RELEASE</version>
|
||||
<relativePath/>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
@@ -85,5 +85,6 @@
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<hsqldb.version>2.4.1</hsqldb.version>
|
||||
<spring-boot.version>2.0.4.RELEASE</spring-boot.version>
|
||||
</properties>
|
||||
</project>
|
||||
|
||||
+26
-5
@@ -223,6 +223,12 @@
|
||||
<artifactId>serenity-spring</artifactId>
|
||||
<version>${serenity.version}</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.serenity-bdd</groupId>
|
||||
@@ -318,6 +324,12 @@
|
||||
<artifactId>pact-jvm-consumer-junit_2.11</artifactId>
|
||||
<version>${pact.version}</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-all</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
@@ -675,6 +687,17 @@
|
||||
<version>${mockftpserver.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.asciidoctor</groupId>
|
||||
<artifactId>asciidoctor-maven-plugin</artifactId>
|
||||
<version>1.5.7.1</version>
|
||||
</dependency>
|
||||
<!-- Reflections -->
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
<version>${reflections.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -687,10 +710,6 @@
|
||||
<name>bintray</name>
|
||||
<url>http://dl.bintray.com/cuba-platform/main</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>Apache Staging</id>
|
||||
<url>https://repository.apache.org/content/groups/staging</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>nm-repo</id>
|
||||
<name>Numerical Method's Maven Repository</name>
|
||||
@@ -734,7 +753,7 @@
|
||||
<api>JDO</api>
|
||||
<props>${basedir}/datanucleus.properties</props>
|
||||
<log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration>
|
||||
<verbose>true</verbose>
|
||||
<verbose>false</verbose>
|
||||
<fork>false</fork>
|
||||
<!-- Solve windows line too long error -->
|
||||
</configuration>
|
||||
@@ -897,6 +916,8 @@
|
||||
<derive4j.version>1.1.0</derive4j.version>
|
||||
<mockftpserver.version>2.7.1</mockftpserver.version>
|
||||
<commons-net.version>3.6</commons-net.version>
|
||||
<reflections.version>0.9.11</reflections.version>
|
||||
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.derive4j.Make;
|
||||
|
||||
@Data(value = @Derive(
|
||||
inClass = "{ClassName}Impl",
|
||||
make = {Make.lazyConstructor, Make.constructors}
|
||||
make = {Make.lazyConstructor, Make.constructors, Make.getters}
|
||||
))
|
||||
public interface LazyRequest {
|
||||
interface Cases<R>{
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.baeldung.reflections;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.reflections.Reflections;
|
||||
import org.reflections.scanners.MethodAnnotationsScanner;
|
||||
import org.reflections.scanners.MethodParameterScanner;
|
||||
import org.reflections.scanners.ResourcesScanner;
|
||||
import org.reflections.scanners.Scanner;
|
||||
import org.reflections.scanners.SubTypesScanner;
|
||||
import org.reflections.util.ClasspathHelper;
|
||||
import org.reflections.util.ConfigurationBuilder;
|
||||
|
||||
public class ReflectionsApp {
|
||||
|
||||
public Set<Class<? extends Scanner>> getReflectionsSubTypes() {
|
||||
Reflections reflections = new Reflections("org.reflections");
|
||||
Set<Class<? extends Scanner>> scannersSet = reflections.getSubTypesOf(Scanner.class);
|
||||
return scannersSet;
|
||||
}
|
||||
|
||||
public Set<Class<?>> getJDKFunctinalInterfaces() {
|
||||
Reflections reflections = new Reflections("java.util.function");
|
||||
Set<Class<?>> typesSet = reflections.getTypesAnnotatedWith(FunctionalInterface.class);
|
||||
return typesSet;
|
||||
}
|
||||
|
||||
public Set<Method> getDateDeprecatedMethods() {
|
||||
Reflections reflections = new Reflections(java.util.Date.class, new MethodAnnotationsScanner());
|
||||
Set<Method> deprecatedMethodsSet = reflections.getMethodsAnnotatedWith(Deprecated.class);
|
||||
return deprecatedMethodsSet;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Set<Constructor> getDateDeprecatedConstructors() {
|
||||
Reflections reflections = new Reflections(java.util.Date.class, new MethodAnnotationsScanner());
|
||||
Set<Constructor> constructorsSet = reflections.getConstructorsAnnotatedWith(Deprecated.class);
|
||||
return constructorsSet;
|
||||
}
|
||||
|
||||
public Set<Method> getMethodsWithDateParam() {
|
||||
Reflections reflections = new Reflections(java.text.SimpleDateFormat.class, new MethodParameterScanner());
|
||||
Set<Method> methodsSet = reflections.getMethodsMatchParams(Date.class);
|
||||
return methodsSet;
|
||||
}
|
||||
|
||||
public Set<Method> getMethodsWithVoidReturn() {
|
||||
Reflections reflections = new Reflections(java.text.SimpleDateFormat.class, new MethodParameterScanner());
|
||||
Set<Method> methodsSet = reflections.getMethodsReturn(void.class);
|
||||
return methodsSet;
|
||||
}
|
||||
|
||||
public Set<String> getPomXmlPaths() {
|
||||
Reflections reflections = new Reflections(new ResourcesScanner());
|
||||
Set<String> resourcesSet = reflections.getResources(Pattern.compile(".*pom\\.xml"));
|
||||
return resourcesSet;
|
||||
}
|
||||
|
||||
public Set<Class<? extends Scanner>> getReflectionsSubTypesUsingBuilder() {
|
||||
Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage("org.reflections"))
|
||||
.setScanners(new SubTypesScanner()));
|
||||
|
||||
Set<Class<? extends Scanner>> scannersSet = reflections.getSubTypesOf(Scanner.class);
|
||||
return scannersSet;
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -26,7 +26,7 @@ import com.google.api.services.sheets.v4.model.ValueRange;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
public class GoogleSheetsIntegrationTest {
|
||||
public class GoogleSheetsLiveTest {
|
||||
|
||||
private static Sheets sheetsService;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user