Skip to content

Commit 1a58d62

Browse files
authored
Merge branch 'master' into thombergs-patch-6
2 parents 3723648 + be608ae commit 1a58d62

File tree

49 files changed

+251
-107
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+251
-107
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import static junit.framework.Assert.assertEquals;
2020
import static org.junit.Assert.assertNotNull;
2121

22-
public class CayenneAdvancedOperationIntegrationTest {
22+
public class CayenneAdvancedOperationLiveTest {
2323
private static ObjectContext context = null;
2424

2525
@BeforeClass

apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneOperationIntegrationTest.java renamed to apache-cayenne/src/test/java/com/baeldung/apachecayenne/CayenneOperationLiveTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import static org.junit.Assert.assertNull;
1717

1818

19-
public class CayenneOperationIntegrationTest {
19+
public class CayenneOperationLiveTest {
2020
private static ObjectContext context = null;
2121

2222
@BeforeClass

azure/src/test/java/com/baeldung/springboot/azure/AzureApplicationTests.java renamed to azure/src/test/java/com/baeldung/springboot/azure/AzureApplicationIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
@RunWith(SpringRunner.class)
99
@SpringBootTest
10-
public class AzureApplicationTests {
10+
public class AzureApplicationIntegrationTest {
1111

1212
@Test
1313
public void contextLoads() {

core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameTest.java renamed to core-java-8/src/test/java/com/baeldung/reflect/MethodParamNameUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import org.junit.Test;
1111

12-
public class MethodParamNameTest {
12+
public class MethodParamNameUnitTest {
1313

1414
@Test
1515
public void whenGetConstructorParams_thenOk()

core-java-io/src/test/java/com/baeldung/file/FilesManualTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ public void whenAppendToFileUsingFileWriter_thenCorrect() throws IOException {
7777
bw.newLine();
7878
bw.close();
7979

80-
assertThat(StreamUtils.getStringFromInputStream(new FileInputStream(fileName))).isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\n");
80+
assertThat(StreamUtils.getStringFromInputStream(new FileInputStream(fileName))).isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n");
8181
}
8282
}

core-java-io/src/test/java/org/baeldung/java/io/JavaReadFromFileUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void whenReadTwoFilesWithSequenceInputStream_thenCorrect() throws IOExcep
106106

107107
@Test
108108
public void whenReadUTFEncodedFile_thenCorrect() throws IOException {
109-
final String expected_value = "�空";
109+
final String expected_value = "青空";
110110
final BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("src/test/resources/test_read7.in"), "UTF-8"));
111111
final String currentLine = reader.readLine();
112112
reader.close();

core-java/src/test/java/com/baeldung/array/JaggedArrayTest.java renamed to core-java/src/test/java/com/baeldung/array/JaggedArrayUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import org.junit.Test;
1212

13-
public class JaggedArrayTest {
13+
public class JaggedArrayUnitTest {
1414

1515
private JaggedArray obj = new JaggedArray();
1616

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.baeldung.enums
2+
3+
enum class CardType(val color: String) : ICardLimit {
4+
SILVER("gray") {
5+
override fun getCreditLimit(): Int {
6+
return 100000
7+
}
8+
9+
override fun calculateCashbackPercent(): Float {
10+
return 0.25f
11+
}
12+
},
13+
GOLD("yellow") {
14+
override fun getCreditLimit(): Int {
15+
return 200000
16+
}
17+
18+
override fun calculateCashbackPercent(): Float {
19+
return 0.5f
20+
}
21+
},
22+
PLATINUM("black") {
23+
override fun getCreditLimit(): Int {
24+
return 300000
25+
}
26+
27+
override fun calculateCashbackPercent(): Float {
28+
return 0.75f
29+
}
30+
};
31+
32+
abstract fun calculateCashbackPercent(): Float
33+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.enums
2+
3+
class CardTypeHelper {
4+
fun getCardTypeByColor(color: String): CardType? {
5+
for (cardType in CardType.values()) {
6+
if (cardType.color.equals(color)) {
7+
return cardType;
8+
}
9+
}
10+
return null
11+
}
12+
13+
fun getCardTypeByName(name: String): CardType {
14+
return CardType.valueOf(name.toUpperCase())
15+
}
16+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.baeldung.enums
2+
3+
interface ICardLimit {
4+
fun getCreditLimit(): Int
5+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.baeldung.enums
2+
3+
import org.junit.jupiter.api.Assertions
4+
import org.junit.jupiter.api.Test
5+
6+
internal class CardTypeHelperUnitTest {
7+
8+
@Test
9+
fun whenGetCardTypeByColor_thenSilverCardType() {
10+
val cardTypeHelper = CardTypeHelper()
11+
Assertions.assertEquals(CardType.SILVER, cardTypeHelper.getCardTypeByColor("gray"))
12+
}
13+
14+
@Test
15+
fun whenGetCardTypeByColor_thenGoldCardType() {
16+
val cardTypeHelper = CardTypeHelper()
17+
Assertions.assertEquals(CardType.GOLD, cardTypeHelper.getCardTypeByColor("yellow"))
18+
}
19+
20+
@Test
21+
fun whenGetCardTypeByColor_thenPlatinumCardType() {
22+
val cardTypeHelper = CardTypeHelper()
23+
Assertions.assertEquals(CardType.PLATINUM, cardTypeHelper.getCardTypeByColor("black"))
24+
}
25+
26+
@Test
27+
fun whenGetCardTypeByName_thenSilverCardType() {
28+
val cardTypeHelper = CardTypeHelper()
29+
Assertions.assertEquals(CardType.SILVER, cardTypeHelper.getCardTypeByName("silver"))
30+
}
31+
32+
@Test
33+
fun whenGetCardTypeByName_thenGoldCardType() {
34+
val cardTypeHelper = CardTypeHelper()
35+
Assertions.assertEquals(CardType.GOLD, cardTypeHelper.getCardTypeByName("gold"))
36+
}
37+
38+
@Test
39+
fun whenGetCardTypeByName_thenPlatinumCardType() {
40+
val cardTypeHelper = CardTypeHelper()
41+
Assertions.assertEquals(CardType.PLATINUM, cardTypeHelper.getCardTypeByName("platinum"))
42+
}
43+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.baeldung.enums
2+
3+
import org.junit.jupiter.api.Assertions.assertEquals
4+
import org.junit.jupiter.api.Test
5+
6+
internal class CardTypeUnitTest {
7+
8+
@Test
9+
fun givenSilverCardType_whenCalculateCashbackPercent_thenReturnCashbackValue() {
10+
assertEquals(0.25f, CardType.SILVER.calculateCashbackPercent())
11+
}
12+
13+
@Test
14+
fun givenGoldCardType_whenCalculateCashbackPercent_thenReturnCashbackValue() {
15+
assertEquals(0.5f, CardType.GOLD.calculateCashbackPercent())
16+
}
17+
18+
@Test
19+
fun givenPlatinumCardType_whenCalculateCashbackPercent_thenReturnCashbackValue() {
20+
assertEquals(0.75f, CardType.PLATINUM.calculateCashbackPercent())
21+
}
22+
23+
@Test
24+
fun givenSilverCardType_whenGetCreditLimit_thenReturnCreditLimit() {
25+
assertEquals(100000, CardType.SILVER.getCreditLimit())
26+
}
27+
28+
@Test
29+
fun givenGoldCardType_whenGetCreditLimit_thenReturnCreditLimit() {
30+
assertEquals(200000, CardType.GOLD.getCreditLimit())
31+
}
32+
33+
@Test
34+
fun givenPlatinumCardType_whenGetCreditLimit_thenReturnCreditLimit() {
35+
assertEquals(300000, CardType.PLATINUM.getCreditLimit())
36+
}
37+
38+
@Test
39+
fun givenSilverCardType_whenCheckColor_thenReturnColor() {
40+
assertEquals("gray", CardType.SILVER.color)
41+
}
42+
43+
@Test
44+
fun givenGoldCardType_whenCheckColor_thenReturnColor() {
45+
assertEquals("yellow", CardType.GOLD.color)
46+
}
47+
48+
@Test
49+
fun givenPlatinumCardType_whenCheckColor_thenReturnColor() {
50+
assertEquals("black", CardType.PLATINUM.color)
51+
}
52+
}

custom-pmd-0.0.1.jar

23 Bytes
Binary file not shown.

custom-pmd/src/main/java/org/baeldung/pmd/UnitTestNamingConventionRule.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,16 @@ public class UnitTestNamingConventionRule extends AbstractJavaRule {
1414
"ManualTest",
1515
"JdbcTest",
1616
"LiveTest",
17-
"UnitTest");
17+
"UnitTest",
18+
"jmhTest");
1819

1920
public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
2021
String className = node.getImage();
2122
Objects.requireNonNull(className);
2223

23-
if (className.endsWith("Test") || className.endsWith("Tests")) {
24-
if (allowedEndings.stream()
25-
.noneMatch(className::endsWith)) {
26-
addViolation(data, node);
27-
}
24+
if (className.endsWith("Tests")
25+
|| (className.endsWith("Test") && allowedEndings.stream().noneMatch(className::endsWith))) {
26+
addViolation(data, node);
2827
}
2928

3029
return data;

spring-4/src/test/java/com/baeldung/flips/controller/FlipControllerTest.java renamed to flips/src/test/java/com/baeldung/flips/controller/FlipControllerIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
}, webEnvironment = SpringBootTest.WebEnvironment.MOCK)
2424
@AutoConfigureMockMvc
2525
@ActiveProfiles("dev")
26-
public class FlipControllerTest {
26+
public class FlipControllerIntegrationTest {
2727

2828
@Autowired private MockMvc mvc;
2929

libraries/src/main/java/com/baeldung/commons/math3/Histogram.java

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@
1010

1111
public class Histogram {
1212

13+
private Map distributionMap;
14+
private int classWidth;
15+
1316
public Histogram() {
1417

18+
distributionMap = new TreeMap();
19+
classWidth = 10;
1520
Map distributionMap = processRawData();
1621
List yData = new ArrayList();
1722
yData.addAll(distributionMap.values());
@@ -46,43 +51,43 @@ private Map processRawData() {
4651
Frequency frequency = new Frequency();
4752
datasetList.forEach(d -> frequency.addValue(Double.parseDouble(d.toString())));
4853

49-
int classWidth = 10;
50-
51-
Map distributionMap = new TreeMap();
5254
List processed = new ArrayList();
5355
datasetList.forEach(d -> {
56+
double observation = Double.parseDouble(d.toString());
5457

55-
double observation = Double.parseDouble(d.toString());
56-
57-
if(processed.contains(observation))
58-
return;
59-
60-
long observationFrequency = frequency.getCount(observation);
61-
int upperBoundary = (observation > classWidth) ? Math.multiplyExact( (int) Math.ceil(observation / classWidth), classWidth) : classWidth;
62-
int lowerBoundary = (upperBoundary > classWidth) ? Math.subtractExact(upperBoundary, classWidth) : 0;
63-
String bin = lowerBoundary + "-" + upperBoundary;
58+
if(processed.contains(observation))
59+
return;
6460

65-
int prevUpperBoundary = lowerBoundary;
66-
int prevLowerBoundary = (lowerBoundary > classWidth) ? lowerBoundary - classWidth : 0;
67-
String prevBin = prevLowerBoundary + "-" + prevUpperBoundary;
68-
if(!distributionMap.containsKey(prevBin))
69-
distributionMap.put(prevBin, 0);
61+
long observationFrequency = frequency.getCount(observation);
62+
int upperBoundary = (observation > classWidth) ? Math.multiplyExact( (int) Math.ceil(observation / classWidth), classWidth) : classWidth;
63+
int lowerBoundary = (upperBoundary > classWidth) ? Math.subtractExact(upperBoundary, classWidth) : 0;
64+
String bin = lowerBoundary + "-" + upperBoundary;
7065

71-
if(!distributionMap.containsKey(bin)) {
72-
distributionMap.put(bin, observationFrequency);
73-
}
74-
else {
75-
long oldFrequency = Long.parseLong(distributionMap.get(bin).toString());
76-
distributionMap.replace(bin, oldFrequency + observationFrequency);
77-
}
66+
updateDistributionMap(lowerBoundary, bin, observationFrequency);
7867

79-
processed.add(observation);
68+
processed.add(observation);
8069

8170
});
8271

8372
return distributionMap;
8473
}
8574

75+
private void updateDistributionMap(int lowerBoundary, String bin, long observationFrequency) {
76+
77+
int prevLowerBoundary = (lowerBoundary > classWidth) ? lowerBoundary - classWidth : 0;
78+
String prevBin = prevLowerBoundary + "-" + lowerBoundary;
79+
if(!distributionMap.containsKey(prevBin))
80+
distributionMap.put(prevBin, 0);
81+
82+
if(!distributionMap.containsKey(bin)) {
83+
distributionMap.put(bin, observationFrequency);
84+
}
85+
else {
86+
long oldFrequency = Long.parseLong(distributionMap.get(bin).toString());
87+
distributionMap.replace(bin, oldFrequency + observationFrequency);
88+
}
89+
}
90+
8691
public static void main(String[] args) {
8792
new Histogram();
8893
}

mustache/src/test/java/com/baeldung/mustache/TodoMustacheServiceTest.java renamed to mustache/src/test/java/com/baeldung/mustache/TodoMustacheServiceUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import static org.assertj.core.api.Assertions.assertThat;
1717

18-
public class TodoMustacheServiceTest {
18+
public class TodoMustacheServiceUnitTest {
1919

2020
private String executeTemplate(Mustache m, Map<String, Object> context) throws IOException {
2121
StringWriter writer = new StringWriter();
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* @author Donato Rimenti
1616
*
1717
*/
18-
public class SingletonSynchronizationUnitTest {
18+
public class SingletonSynchronizationIntegrationTest {
1919

2020
/**
2121
* Size of the thread pools used.
@@ -33,7 +33,7 @@ public class SingletonSynchronizationUnitTest {
3333
@Test
3434
public void givenDraconianSingleton_whenMultithreadInstancesEquals_thenTrue() {
3535
ExecutorService executor = Executors.newFixedThreadPool(POOL_SIZE);
36-
Set<DraconianSingleton> resultSet = Collections.synchronizedSet(new HashSet<DraconianSingleton>());
36+
Set<DraconianSingleton> resultSet = Collections.synchronizedSet(new HashSet<>());
3737

3838
// Submits the instantiation tasks.
3939
for (int i = 0; i < TASKS_TO_SUBMIT; i++) {
@@ -51,7 +51,7 @@ public void givenDraconianSingleton_whenMultithreadInstancesEquals_thenTrue() {
5151
@Test
5252
public void givenDclSingleton_whenMultithreadInstancesEquals_thenTrue() {
5353
ExecutorService executor = Executors.newFixedThreadPool(POOL_SIZE);
54-
Set<DclSingleton> resultSet = Collections.synchronizedSet(new HashSet<DclSingleton>());
54+
Set<DclSingleton> resultSet = Collections.synchronizedSet(new HashSet<>());
5555

5656
// Submits the instantiation tasks.
5757
for (int i = 0; i < TASKS_TO_SUBMIT; i++) {
@@ -69,7 +69,7 @@ public void givenDclSingleton_whenMultithreadInstancesEquals_thenTrue() {
6969
@Test
7070
public void givenEarlyInitSingleton_whenMultithreadInstancesEquals_thenTrue() {
7171
ExecutorService executor = Executors.newFixedThreadPool(POOL_SIZE);
72-
Set<EarlyInitSingleton> resultSet = Collections.synchronizedSet(new HashSet<EarlyInitSingleton>());
72+
Set<EarlyInitSingleton> resultSet = Collections.synchronizedSet(new HashSet<>());
7373

7474
// Submits the instantiation tasks.
7575
for (int i = 0; i < TASKS_TO_SUBMIT; i++) {
@@ -87,7 +87,7 @@ public void givenEarlyInitSingleton_whenMultithreadInstancesEquals_thenTrue() {
8787
@Test
8888
public void givenInitOnDemandSingleton_whenMultithreadInstancesEquals_thenTrue() {
8989
ExecutorService executor = Executors.newFixedThreadPool(POOL_SIZE);
90-
Set<InitOnDemandSingleton> resultSet = Collections.synchronizedSet(new HashSet<InitOnDemandSingleton>());
90+
Set<InitOnDemandSingleton> resultSet = Collections.synchronizedSet(new HashSet<>());
9191

9292
// Submits the instantiation tasks.
9393
for (int i = 0; i < TASKS_TO_SUBMIT; i++) {
@@ -105,7 +105,7 @@ public void givenInitOnDemandSingleton_whenMultithreadInstancesEquals_thenTrue()
105105
@Test
106106
public void givenEnumSingleton_whenMultithreadInstancesEquals_thenTrue() {
107107
ExecutorService executor = Executors.newFixedThreadPool(POOL_SIZE);
108-
Set<EnumSingleton> resultSet = Collections.synchronizedSet(new HashSet<EnumSingleton>());
108+
Set<EnumSingleton> resultSet = Collections.synchronizedSet(new HashSet<>());
109109

110110
// Submits the instantiation tasks.
111111
for (int i = 0; i < TASKS_TO_SUBMIT; i++) {

0 commit comments

Comments
 (0)