Merge pull request #9454 from kwoyke/JAVA-1782-main

JAVA-1782: Remove byte-buddy dep from the main pom.xml
This commit is contained in:
kwoyke
2020-06-08 08:35:42 +02:00
committed by GitHub
7 changed files with 66 additions and 14 deletions
@@ -0,0 +1,40 @@
package com.baeldung.varargs;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.junit.Assert.assertEquals;
public class HeapPollutionUnitTest {
@Test(expected = ClassCastException.class)
public void givenGenericVararg_whenUsedUnsafe_shouldThrowClassCastException() {
String one = firstOfFirst(Arrays.asList("one", "two"), Collections.emptyList());
assertEquals("one", one);
}
@Test(expected = ClassCastException.class)
public void givenGenericVararg_whenRefEscapes_mayCauseSubtleBugs() {
String[] args = returnAsIs("One", "Two");
}
private static String firstOfFirst(List<String>... strings) {
List<Integer> ints = Collections.singletonList(42);
Object[] objects = strings;
objects[0] = ints;
return strings[0].get(0);
}
private static <T> T[] toArray(T... arguments) {
return arguments;
}
private static <T> T[] returnAsIs(T a, T b) {
return toArray(a, b);
}
}
@@ -200,7 +200,7 @@ public class ReflectionUnitTest {
@Test
public void givenClassField_whenSetsAndGetsValue_thenCorrect() throws Exception {
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
final Bird bird = (Bird) birdClass.newInstance();
final Bird bird = (Bird) birdClass.getConstructor().newInstance();
final Field field = birdClass.getDeclaredField("walks");
field.setAccessible(true);
@@ -266,7 +266,7 @@ public class ReflectionUnitTest {
@Test
public void givenMethod_whenInvokes_thenCorrect() throws Exception {
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
final Bird bird = (Bird) birdClass.newInstance();
final Bird bird = (Bird) birdClass.getConstructor().newInstance();
final Method setWalksMethod = birdClass.getDeclaredMethod("setWalks", boolean.class);
final Method walksMethod = birdClass.getDeclaredMethod("walks");
final boolean walks = (boolean) walksMethod.invoke(bird);
@@ -26,6 +26,17 @@ public class StringToIntOrIntegerUnitTest {
assertThat(result).isEqualTo(new Integer(42));
}
@Test
public void givenString_whenCallingValueOf_shouldCacheSomeValues() {
for (int i = -128; i <= 127; i++) {
String value = i + "";
Integer first = Integer.valueOf(value);
Integer second = Integer.valueOf(value);
assertThat(first).isSameAs(second);
}
}
@Test
public void givenString_whenCallingIntegerConstructor_shouldConvertToInt() {
String givenString = "42";
+6
View File
@@ -225,6 +225,12 @@
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>${byte-buddy.version}</version>
<scope>test</scope>
</dependency>
<!-- jhipster-needle-maven-add-dependency -->
</dependencies>
+7 -1
View File
@@ -153,7 +153,13 @@
<artifactId>renjin-script-engine</artifactId>
<version>${renjin.version}</version>
</dependency>
<dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>${byte-buddy.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>${kafka.version}</version>
-5
View File
@@ -32,11 +32,6 @@
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>${byte-buddy.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
-6
View File
@@ -69,12 +69,6 @@
<version>${hamcrest-all.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>${byte-buddy.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>