Skip to content

Commit

Permalink
Build opt 22 06 (eugenp#2132)
Browse files Browse the repository at this point in the history
* Drools reformat

* Further refactor

* Further refactor

* Refactor
  • Loading branch information
pivovarit authored Jun 22, 2017
1 parent 38dc204 commit 87049b6
Show file tree
Hide file tree
Showing 48 changed files with 291 additions and 336 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,39 @@ public class ApplicantServiceIntegrationTest {
private ApplicantService applicantService;

@Before
public void setup(){
public void setup() {
applicantService = new ApplicantService();
}

@Test
public void whenCriteriaMatching_ThenSuggestManagerRole() throws IOException {
Applicant applicant=new Applicant("Davis",37,1600000.0,11);
SuggestedRole suggestedRole=new SuggestedRole();
applicantService.suggestARoleForApplicant(applicant,suggestedRole);
assertEquals("Manager",suggestedRole.getRole());
Applicant applicant = new Applicant("Davis", 37, 1600000.0, 11);
SuggestedRole suggestedRole = new SuggestedRole();
applicantService.suggestARoleForApplicant(applicant, suggestedRole);
assertEquals("Manager", suggestedRole.getRole());
}

@Test
public void whenCriteriaMatching_ThenSuggestSeniorDeveloperRole() throws IOException {
Applicant applicant=new Applicant("John",37,1200000.0,8);
SuggestedRole suggestedRole=new SuggestedRole();
applicantService.suggestARoleForApplicant(applicant,suggestedRole);
assertEquals("Senior developer",suggestedRole.getRole());
Applicant applicant = new Applicant("John", 37, 1200000.0, 8);
SuggestedRole suggestedRole = new SuggestedRole();
applicantService.suggestARoleForApplicant(applicant, suggestedRole);
assertEquals("Senior developer", suggestedRole.getRole());
}

@Test
public void whenCriteriaMatching_ThenSuggestDeveloperRole() throws IOException {
Applicant applicant=new Applicant("Davis",37,800000.0,3);
SuggestedRole suggestedRole=new SuggestedRole();
applicantService.suggestARoleForApplicant(applicant,suggestedRole);
assertEquals("Developer",suggestedRole.getRole());
Applicant applicant = new Applicant("Davis", 37, 800000.0, 3);
SuggestedRole suggestedRole = new SuggestedRole();
applicantService.suggestARoleForApplicant(applicant, suggestedRole);
assertEquals("Developer", suggestedRole.getRole());
}

@Test
public void whenCriteriaNotMatching_ThenNoRole() throws IOException {
Applicant applicant=new Applicant("John",37,1200000.0,5);
SuggestedRole suggestedRole=new SuggestedRole();
applicantService.suggestARoleForApplicant(applicant,suggestedRole);
Applicant applicant = new Applicant("John", 37, 1200000.0, 5);
SuggestedRole suggestedRole = new SuggestedRole();
applicantService.suggestARoleForApplicant(applicant, suggestedRole);
assertNull(suggestedRole.getRole());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.baeldung.drools.model.Product;
import org.junit.Before;
import org.junit.Test;

import static junit.framework.TestCase.assertEquals;


Expand All @@ -11,22 +12,22 @@ public class ProductServiceIntegrationTest {
private ProductService productService;

@Before
public void setup(){
productService=new ProductService();
public void setup() {
productService = new ProductService();
}


@Test
public void whenProductTypeElectronic_ThenLabelBarcode(){
Product product=new Product("Microwave","Electronic");
product=productService.applyLabelToProduct(product);
assertEquals("BarCode",product.getLabel());
public void whenProductTypeElectronic_ThenLabelBarcode() {
Product product = new Product("Microwave", "Electronic");
product = productService.applyLabelToProduct(product);
assertEquals("BarCode", product.getLabel());
}

@Test
public void whenProductTypeBook_ThenLabelIsbn(){
Product product=new Product("AutoBiography","Book");
product=productService.applyLabelToProduct(product);
assertEquals("ISBN",product.getLabel());
public void whenProductTypeBook_ThenLabelIsbn() {
Product product = new Product("AutoBiography", "Book");
product = productService.applyLabelToProduct(product);
assertEquals("ISBN", product.getLabel());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@ public class AsciidoctorDemo {

private final Asciidoctor asciidoctor;

public AsciidoctorDemo() {
AsciidoctorDemo() {
asciidoctor = create();
}

public void generatePDFFromString(final String input) {

final Map<String, Object> options = options().inPlace(true)
.backend("pdf")
.asMap();
.backend("pdf")
.asMap();

final String outfile = asciidoctor.convertFile(new File("sample.adoc"), options);
}

public String generateHTMLFromString(final String input) {
final String output = asciidoctor.convert("Hello _Baeldung_!", new HashMap<String, Object>());
return output;
String generateHTMLFromString(final String input) {
return asciidoctor.convert("Hello _Baeldung_!", new HashMap<String, Object>());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,78 @@

import org.apache.commons.lang3.ArrayUtils;
import org.junit.Test;
import static org.junit.Assert.assertEquals;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

public class ArrayUtilsUnitTest {
@Test
public void givenArray_whenAddingElementAtSpecifiedPosition_thenCorrect() {
int[] oldArray = { 2, 3, 4, 5 };
int[] oldArray = {2, 3, 4, 5};
int[] newArray = ArrayUtils.add(oldArray, 0, 1);
int[] expectedArray = { 1, 2, 3, 4, 5 };
int[] expectedArray = {1, 2, 3, 4, 5};
assertArrayEquals(expectedArray, newArray);
}

@Test
public void givenArray_whenAddingElementAtTheEnd_thenCorrect() {
int[] oldArray = { 2, 3, 4, 5 };
int[] oldArray = {2, 3, 4, 5};
int[] newArray = ArrayUtils.add(oldArray, 1);
int[] expectedArray = { 2, 3, 4, 5, 1 };
int[] expectedArray = {2, 3, 4, 5, 1};
assertArrayEquals(expectedArray, newArray);
}

@Test
public void givenArray_whenAddingAllElementsAtTheEnd_thenCorrect() {
int[] oldArray = { 0, 1, 2 };
int[] oldArray = {0, 1, 2};
int[] newArray = ArrayUtils.addAll(oldArray, 3, 4, 5);
int[] expectedArray = { 0, 1, 2, 3, 4, 5 };
int[] expectedArray = {0, 1, 2, 3, 4, 5};
assertArrayEquals(expectedArray, newArray);
}

@Test
public void givenArray_whenRemovingElementAtSpecifiedPosition_thenCorrect() {
int[] oldArray = { 1, 2, 3, 4, 5 };
int[] oldArray = {1, 2, 3, 4, 5};
int[] newArray = ArrayUtils.remove(oldArray, 1);
int[] expectedArray = { 1, 3, 4, 5 };
int[] expectedArray = {1, 3, 4, 5};
assertArrayEquals(expectedArray, newArray);
}

@Test
public void givenArray_whenRemovingAllElementsAtSpecifiedPositions_thenCorrect() {
int[] oldArray = { 1, 2, 3, 4, 5 };
int[] oldArray = {1, 2, 3, 4, 5};
int[] newArray = ArrayUtils.removeAll(oldArray, 1, 3);
int[] expectedArray = { 1, 3, 5 };
int[] expectedArray = {1, 3, 5};
assertArrayEquals(expectedArray, newArray);
}

@Test
public void givenArray_whenRemovingAnElement_thenCorrect() {
int[] oldArray = { 1, 2, 3, 3, 4 };
int[] oldArray = {1, 2, 3, 3, 4};
int[] newArray = ArrayUtils.removeElement(oldArray, 3);
int[] expectedArray = { 1, 2, 3, 4 };
int[] expectedArray = {1, 2, 3, 4};
assertArrayEquals(expectedArray, newArray);
}

@Test
public void givenArray_whenRemovingElements_thenCorrect() {
int[] oldArray = { 1, 2, 3, 3, 4 };
int[] oldArray = {1, 2, 3, 3, 4};
int[] newArray = ArrayUtils.removeElements(oldArray, 2, 3, 5);
int[] expectedArray = { 1, 3, 4 };
int[] expectedArray = {1, 3, 4};
assertArrayEquals(expectedArray, newArray);
}

@Test
public void givenArray_whenRemovingAllElementOccurences_thenCorrect() {
int[] oldArray = { 1, 2, 2, 2, 3 };
int[] oldArray = {1, 2, 2, 2, 3};
int[] newArray = ArrayUtils.removeAllOccurences(oldArray, 2);
int[] expectedArray = { 1, 3 };
int[] expectedArray = {1, 3};
assertArrayEquals(expectedArray, newArray);
}

@Test
public void givenArray_whenCheckingExistingElement_thenCorrect() {
int[] array = { 1, 3, 5, 7, 9 };
int[] array = {1, 3, 5, 7, 9};
boolean evenContained = ArrayUtils.contains(array, 2);
boolean oddContained = ArrayUtils.contains(array, 7);
assertEquals(false, evenContained);
Expand All @@ -81,57 +82,57 @@ public void givenArray_whenCheckingExistingElement_thenCorrect() {

@Test
public void givenArray_whenReversingElementsWithinARange_thenCorrect() {
int[] originalArray = { 1, 2, 3, 4, 5 };
int[] originalArray = {1, 2, 3, 4, 5};
ArrayUtils.reverse(originalArray, 1, 4);
int[] expectedArray = { 1, 4, 3, 2, 5 };
int[] expectedArray = {1, 4, 3, 2, 5};
assertArrayEquals(expectedArray, originalArray);
}

@Test
public void givenArray_whenReversingAllElements_thenCorrect() {
int[] originalArray = { 1, 2, 3, 4, 5 };
int[] originalArray = {1, 2, 3, 4, 5};
ArrayUtils.reverse(originalArray);
int[] expectedArray = { 5, 4, 3, 2, 1 };
int[] expectedArray = {5, 4, 3, 2, 1};
assertArrayEquals(expectedArray, originalArray);
}

@Test
public void givenArray_whenShiftingElementsWithinARange_thenCorrect() {
int[] originalArray = { 1, 2, 3, 4, 5 };
int[] originalArray = {1, 2, 3, 4, 5};
ArrayUtils.shift(originalArray, 1, 4, 1);
int[] expectedArray = { 1, 4, 2, 3, 5 };
int[] expectedArray = {1, 4, 2, 3, 5};
assertArrayEquals(expectedArray, originalArray);
}

@Test
public void givenArray_whenShiftingAllElements_thenCorrect() {
int[] originalArray = { 1, 2, 3, 4, 5 };
int[] originalArray = {1, 2, 3, 4, 5};
ArrayUtils.shift(originalArray, 1);
int[] expectedArray = { 5, 1, 2, 3, 4 };
int[] expectedArray = {5, 1, 2, 3, 4};
assertArrayEquals(expectedArray, originalArray);
}

@Test
public void givenArray_whenExtractingElements_thenCorrect() {
int[] oldArray = { 1, 2, 3, 4, 5 };
int[] oldArray = {1, 2, 3, 4, 5};
int[] newArray = ArrayUtils.subarray(oldArray, 2, 7);
int[] expectedArray = { 3, 4, 5 };
int[] expectedArray = {3, 4, 5};
assertArrayEquals(expectedArray, newArray);
}

@Test
public void givenArray_whenSwapingElementsWithinARange_thenCorrect() {
int[] originalArray = { 1, 2, 3, 4, 5 };
int[] originalArray = {1, 2, 3, 4, 5};
ArrayUtils.swap(originalArray, 0, 3, 2);
int[] expectedArray = { 4, 5, 3, 1, 2 };
int[] expectedArray = {4, 5, 3, 1, 2};
assertArrayEquals(expectedArray, originalArray);
}

@Test
public void givenArray_whenSwapingElementsAtSpecifiedPositions_thenCorrect() {
int[] originalArray = { 1, 2, 3, 4, 5 };
int[] originalArray = {1, 2, 3, 4, 5};
ArrayUtils.swap(originalArray, 0, 3);
int[] expectedArray = { 4, 2, 3, 1, 5 };
int[] expectedArray = {4, 2, 3, 1, 5};
assertArrayEquals(expectedArray, originalArray);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class ComplexUnitTest {

@Test
public void whenComplexPow_thenCorrect() {
Complex first = new Complex(1.0, 3.0);
Complex first = new Complex(1.0, 3.0);
Complex second = new Complex(2.0, 5.0);

Complex power = first.pow(second);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public void givenDataSet_whenExecuteWordCount_thenReturnWordCount() throws Excep
//then
List<Tuple2<String, Integer>> collect = result.collect();
assertThat(collect).containsExactlyInAnyOrder(
new Tuple2<>("a", 3), new Tuple2<>("sentence", 2), new Tuple2<>("word", 1),
new Tuple2<>("is", 2), new Tuple2<>("this", 2), new Tuple2<>("second", 1),
new Tuple2<>("first", 1), new Tuple2<>("with", 1), new Tuple2<>("one", 1));
new Tuple2<>("a", 3), new Tuple2<>("sentence", 2), new Tuple2<>("word", 1),
new Tuple2<>("is", 2), new Tuple2<>("this", 2), new Tuple2<>("second", 1),
new Tuple2<>("first", 1), new Tuple2<>("with", 1), new Tuple2<>("one", 1));
}

@Test
Expand All @@ -48,9 +48,9 @@ public void givenListOfAmounts_whenUseMapReduce_thenSumAmountsThatAreOnlyAboveTh

//when
List<Integer> collect = amounts
.filter(a -> a > threshold)
.reduce((integer, t1) -> integer + t1)
.collect();
.filter(a -> a > threshold)
.reduce((integer, t1) -> integer + t1)
.collect();

//then
assertThat(collect.get(0)).isEqualTo(90);
Expand Down Expand Up @@ -78,13 +78,13 @@ public void givenDataSet_whenSortItByOneField_thenShouldReturnSortedDataSet() th
Tuple2<Integer, String> fourthPerson = new Tuple2<>(200, "Michael");
Tuple2<Integer, String> firstPerson = new Tuple2<>(1, "Jack");
DataSet<Tuple2<Integer, String>> transactions = env.fromElements(fourthPerson, secondPerson,
thirdPerson, firstPerson);
thirdPerson, firstPerson);


//when
List<Tuple2<Integer, String>> sorted = transactions
.sortPartition(new IdKeySelectorTransaction(), Order.ASCENDING)
.collect();
.sortPartition(new IdKeySelectorTransaction(), Order.ASCENDING)
.collect();

//then
assertThat(sorted).containsExactly(firstPerson, secondPerson, thirdPerson, fourthPerson);
Expand All @@ -99,15 +99,15 @@ public void giveTwoDataSets_whenJoinUsingId_thenProduceJoinedData() throws Excep

Tuple2<Integer, String> firstTransaction = new Tuple2<>(1, "Transaction_1");
DataSet<Tuple2<Integer, String>> transactions =
env.fromElements(firstTransaction, new Tuple2<>(12, "Transaction_2"));
env.fromElements(firstTransaction, new Tuple2<>(12, "Transaction_2"));


//when
List<Tuple2<Tuple2<Integer, String>, Tuple3<Integer, String, String>>> joined =
transactions.join(addresses)
.where(new IdKeySelectorTransaction())
.equalTo(new IdKeySelectorAddress())
.collect();
transactions.join(addresses)
.where(new IdKeySelectorTransaction())
.equalTo(new IdKeySelectorAddress())
.collect();

//then
assertThat(joined).hasSize(1);
Expand All @@ -121,7 +121,7 @@ public void givenStreamOfEvents_whenProcessEvents_thenShouldPrintResultsOnSinkOp
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

DataStream<String> text
= env.fromElements("This is a first sentence", "This is a second sentence with a one word");
= env.fromElements("This is a first sentence", "This is a second sentence with a one word");


SingleOutputStreamOperator<String> upperCase = text.map(String::toUpperCase);
Expand All @@ -139,8 +139,8 @@ public void givenStreamOfEvents_whenProcessEvents_thenShouldApplyWindowingOnTran
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

SingleOutputStreamOperator<Tuple2<Integer, Long>> windowed = env.fromElements(
new Tuple2<>(16, ZonedDateTime.now().plusMinutes(25).toInstant().getEpochSecond()),
new Tuple2<>(15, ZonedDateTime.now().plusMinutes(2).toInstant().getEpochSecond())
new Tuple2<>(16, ZonedDateTime.now().plusMinutes(25).toInstant().getEpochSecond()),
new Tuple2<>(15, ZonedDateTime.now().plusMinutes(2).toInstant().getEpochSecond())
).assignTimestampsAndWatermarks(new BoundedOutOfOrdernessTimestampExtractor<Tuple2<Integer, Long>>(Time.seconds(20)) {
@Override
public long extractTimestamp(Tuple2<Integer, Long> element) {
Expand All @@ -149,8 +149,8 @@ public long extractTimestamp(Tuple2<Integer, Long> element) {
});

SingleOutputStreamOperator<Tuple2<Integer, Long>> reduced = windowed
.windowAll(TumblingEventTimeWindows.of(Time.seconds(5)))
.maxBy(0, true);
.windowAll(TumblingEventTimeWindows.of(Time.seconds(5)))
.maxBy(0, true);

reduced.print();

Expand Down
Loading

0 comments on commit 87049b6

Please sign in to comment.