Skip to content

Commit 2d34971

Browse files
maibinpivovarit
authored andcommitted
Junit5 (latest two commits) (eugenp#825)
* PDF to X * PDF to X * Remove created doc * Code fixes and cleanup for PDF module * Fix web.xml in spring-mvc-web-vs-initializer project * Rollback web.xml * Fixes to PDF article * Merge with main eugen branch * Junit 5 * Fix name of test and modifier
1 parent aeb8f75 commit 2d34971

24 files changed

Lines changed: 914 additions & 97 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.baeldung.hexToAscii;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import org.junit.Test;
6+
7+
public class HexToAscii {
8+
9+
@Test
10+
public static void whenHexToAscii() {
11+
String asciiString = "http://www.baeldung.com/jackson-serialize-dates";
12+
String hexEquivalent = "687474703a2f2f7777772e6261656c64756e672e636f6d2f6a61636b736f6e2d73657269616c697a652d6461746573";
13+
14+
assertEquals(asciiString, hexToAscii(hexEquivalent));
15+
}
16+
17+
@Test
18+
public static void whenAsciiToHex() {
19+
String asciiString = "http://www.baeldung.com/jackson-serialize-dates";
20+
String hexEquivalent = "687474703a2f2f7777772e6261656c64756e672e636f6d2f6a61636b736f6e2d73657269616c697a652d6461746573";
21+
22+
assertEquals(hexEquivalent, asciiToHex(asciiString));
23+
}
24+
25+
//
26+
27+
private static String asciiToHex(String asciiStr) {
28+
char[] chars = asciiStr.toCharArray();
29+
StringBuilder hex = new StringBuilder();
30+
for (char ch : chars) {
31+
hex.append(Integer.toHexString((int) ch));
32+
}
33+
34+
return hex.toString();
35+
}
36+
37+
private static String hexToAscii(String hexStr) {
38+
StringBuilder output = new StringBuilder("");
39+
for (int i = 0; i < hexStr.length(); i += 2) {
40+
String str = hexStr.substring(i, i + 2);
41+
output.append((char) Integer.parseInt(str, 16));
42+
}
43+
return output.toString();
44+
}
45+
46+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package org.baeldung.equalshashcode.entities;
2+
3+
import java.util.List;
4+
import java.util.Set;
5+
6+
public class ComplexClass {
7+
8+
private List<?> genericList;
9+
private Set<Integer> integerSet;
10+
11+
public ComplexClass(List<?> genericArrayList, Set<Integer> integerHashSet) {
12+
super();
13+
this.genericList = genericArrayList;
14+
this.integerSet = integerHashSet;
15+
}
16+
17+
@Override
18+
public int hashCode() {
19+
final int prime = 31;
20+
int result = 1;
21+
result = prime * result + ((genericList == null) ? 0 : genericList.hashCode());
22+
result = prime * result + ((integerSet == null) ? 0 : integerSet.hashCode());
23+
return result;
24+
}
25+
26+
@Override
27+
public boolean equals(Object obj) {
28+
if (this == obj)
29+
return true;
30+
if (obj == null)
31+
return false;
32+
if (!(obj instanceof ComplexClass))
33+
return false;
34+
ComplexClass other = (ComplexClass) obj;
35+
if (genericList == null) {
36+
if (other.genericList != null)
37+
return false;
38+
} else if (!genericList.equals(other.genericList))
39+
return false;
40+
if (integerSet == null) {
41+
if (other.integerSet != null)
42+
return false;
43+
} else if (!integerSet.equals(other.integerSet))
44+
return false;
45+
return true;
46+
}
47+
48+
protected List<?> getGenericList() {
49+
return genericList;
50+
}
51+
52+
protected void setGenericArrayList(List<?> genericList) {
53+
this.genericList = genericList;
54+
}
55+
56+
protected Set<Integer> getIntegerSet() {
57+
return integerSet;
58+
}
59+
60+
protected void setIntegerSet(Set<Integer> integerSet) {
61+
this.integerSet = integerSet;
62+
}
63+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.baeldung.equalshashcode.entities;
2+
3+
public class PrimitiveClass {
4+
5+
private boolean primitiveBoolean;
6+
private int primitiveInt;
7+
8+
public PrimitiveClass(boolean primitiveBoolean, int primitiveInt) {
9+
super();
10+
this.primitiveBoolean = primitiveBoolean;
11+
this.primitiveInt = primitiveInt;
12+
}
13+
14+
protected boolean isPrimitiveBoolean() {
15+
return primitiveBoolean;
16+
}
17+
18+
@Override
19+
public int hashCode() {
20+
final int prime = 31;
21+
int result = 1;
22+
result = prime * result + (primitiveBoolean ? 1231 : 1237);
23+
result = prime * result + primitiveInt;
24+
return result;
25+
}
26+
27+
@Override
28+
public boolean equals(Object obj) {
29+
if (this == obj)
30+
return true;
31+
if (obj == null)
32+
return false;
33+
if (getClass() != obj.getClass())
34+
return false;
35+
PrimitiveClass other = (PrimitiveClass) obj;
36+
if (primitiveBoolean != other.primitiveBoolean)
37+
return false;
38+
if (primitiveInt != other.primitiveInt)
39+
return false;
40+
return true;
41+
}
42+
43+
protected void setPrimitiveBoolean(boolean primitiveBoolean) {
44+
this.primitiveBoolean = primitiveBoolean;
45+
}
46+
47+
protected int getPrimitiveInt() {
48+
return primitiveInt;
49+
}
50+
51+
protected void setPrimitiveInt(int primitiveInt) {
52+
this.primitiveInt = primitiveInt;
53+
}
54+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.baeldung.equalshashcode.entities;
2+
3+
public class Rectangle extends Shape {
4+
private double width;
5+
private double length;
6+
7+
public Rectangle(double width, double length) {
8+
this.width = width;
9+
this.length = length;
10+
}
11+
12+
@Override
13+
public double area() {
14+
return width * length;
15+
}
16+
17+
@Override
18+
public double perimeter() {
19+
return 2 * (width + length);
20+
}
21+
22+
@Override
23+
public int hashCode() {
24+
final int prime = 31;
25+
int result = 1;
26+
long temp;
27+
temp = Double.doubleToLongBits(length);
28+
result = prime * result + (int) (temp ^ (temp >>> 32));
29+
temp = Double.doubleToLongBits(width);
30+
result = prime * result + (int) (temp ^ (temp >>> 32));
31+
return result;
32+
}
33+
34+
@Override
35+
public boolean equals(Object obj) {
36+
if (this == obj)
37+
return true;
38+
if (obj == null)
39+
return false;
40+
if (getClass() != obj.getClass())
41+
return false;
42+
Rectangle other = (Rectangle) obj;
43+
if (Double.doubleToLongBits(length) != Double.doubleToLongBits(other.length))
44+
return false;
45+
if (Double.doubleToLongBits(width) != Double.doubleToLongBits(other.width))
46+
return false;
47+
return true;
48+
}
49+
50+
protected double getWidth() {
51+
return width;
52+
}
53+
54+
protected double getLength() {
55+
return length;
56+
}
57+
58+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.baeldung.equalshashcode.entities;
2+
3+
public abstract class Shape {
4+
public abstract double area();
5+
6+
public abstract double perimeter();
7+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.baeldung.equalshashcode.entities;
2+
3+
import java.awt.Color;
4+
5+
public class Square extends Rectangle {
6+
7+
Color color;
8+
9+
public Square(double width, Color color) {
10+
super(width, width);
11+
this.color = color;
12+
}
13+
14+
/* (non-Javadoc)
15+
* @see java.lang.Object#hashCode()
16+
*/
17+
@Override
18+
public int hashCode() {
19+
final int prime = 31;
20+
int result = super.hashCode();
21+
result = prime * result + ((color == null) ? 0 : color.hashCode());
22+
return result;
23+
}
24+
25+
/* (non-Javadoc)
26+
* @see java.lang.Object#equals(java.lang.Object)
27+
*/
28+
@Override
29+
public boolean equals(Object obj) {
30+
if (this == obj) {
31+
return true;
32+
}
33+
if (!super.equals(obj)) {
34+
return false;
35+
}
36+
if (!(obj instanceof Square)) {
37+
return false;
38+
}
39+
Square other = (Square) obj;
40+
if (color == null) {
41+
if (other.color != null) {
42+
return false;
43+
}
44+
} else if (!color.equals(other.color)) {
45+
return false;
46+
}
47+
return true;
48+
}
49+
50+
protected Color getColor() {
51+
return color;
52+
}
53+
54+
protected void setColor(Color color) {
55+
this.color = color;
56+
}
57+
58+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.baeldung.executable;
2+
3+
import javax.swing.JOptionPane;
4+
5+
public class ExecutableMavenJar {
6+
7+
public static void main(String[] args) {
8+
JOptionPane.showMessageDialog(null, "It worked!", "Executable Jar with Maven", 1);
9+
}
10+
11+
}

0 commit comments

Comments
 (0)