Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Lancelot committed Feb 12, 2015
1 parent 1f52154 commit fa0b5ce
Showing 1 changed file with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@
*/
package org.sonar.core.persistence;

import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import org.junit.Test;

import java.util.Collections;
import java.util.List;

import static com.google.common.collect.Lists.newArrayList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;

public class DaoUtilsTest {

Expand All @@ -38,6 +43,44 @@ public void list_all_dao_classes() {
public void repeatCondition() throws Exception {
assertThat(DaoUtils.repeatCondition("uuid=?", 1, "or")).isEqualTo("uuid=?");
assertThat(DaoUtils.repeatCondition("uuid=?", 3, "or")).isEqualTo("uuid=? or uuid=? or uuid=?");
}

@Test
public void execute_large_inputs() throws Exception {
List<Integer> inputs = newArrayList();
List<String> expectedOutputs = newArrayList();
for (int i = 0; i < 2010; i++) {
inputs.add(i);
expectedOutputs.add(Integer.toString(i));
}

List<String> outputs = DaoUtils.executeLargeInputs(inputs, new Function<List<Integer>, List<String>>() {
@Override
public List<String> apply(List<Integer> input) {
// Check that each partition is only done on 1000 elements max
assertThat(input.size()).isLessThanOrEqualTo(1000);
return newArrayList(Iterables.transform(input, new Function<Integer, String>() {
@Override
public String apply(Integer input) {
return Integer.toString(input);
}
}));
}
});

assertThat(outputs).isEqualTo(expectedOutputs);
}

@Test
public void execute_large_inputs_on_empty_list() throws Exception {
List<String> outputs = DaoUtils.executeLargeInputs(Collections.<Integer>emptyList(), new Function<List<Integer>, List<String>>() {
@Override
public List<String> apply(List<Integer> input) {
fail("No partition should be made on empty list");
return Collections.emptyList();
}
});

assertThat(outputs).isEmpty();
}
}

0 comments on commit fa0b5ce

Please sign in to comment.