@Test public void selectByKeys_throws_IAE_when_keys_contains_null() { Random random = new Random(); Set<String> keysIncludingANull = Stream.of( IntStream.range(0, random.nextInt(10)).mapToObj(i -> "b_" + i), Stream.of((String) null), IntStream.range(0, random.nextInt(10)).mapToObj(i -> "a_" + i)) .flatMap(s -> s) .collect(Collectors.toSet()); expectKeyNullOrEmptyIAE(); underTest.selectByKeys(dbSession, keysIncludingANull); }
@Test public void save_throws_IAE_if_value_is_null() { expectValueNullOrEmptyIAE(); underTest.save(dbSession, A_KEY, null); }
@Test public void save_persists_value_in_varchar_if_4000() { when(system2.now()).thenReturn(DATE_1); underTest.save(dbSession, A_KEY, VALUE_SIZE_4000); assertThatInternalProperty(A_KEY) .hasTextValue(VALUE_SIZE_4000) .hasCreatedAt(DATE_1); }
@Test public void save_persists_new_value_in_clob_if_more_than_4000_when_old_one_was_in_varchar() { when(system2.now()).thenReturn(DATE_1, DATE_2); underTest.save(dbSession, A_KEY, VALUE_SMALL); assertThatInternalProperty(A_KEY) .hasTextValue(VALUE_SMALL) .hasCreatedAt(DATE_1); underTest.save(dbSession, A_KEY, VALUE_SIZE_4001); assertThatInternalProperty(A_KEY) .hasClobValue(VALUE_SIZE_4001) .hasCreatedAt(DATE_2); }
@Test public void save_persists_new_value_in_varchar_if_less_than_4000_when_old_one_was_in_clob() { when(system2.now()).thenReturn(DATE_1, DATE_2); underTest.save(dbSession, A_KEY, VALUE_SIZE_4001); assertThatInternalProperty(A_KEY) .hasClobValue(VALUE_SIZE_4001) .hasCreatedAt(DATE_1); underTest.save(dbSession, A_KEY, VALUE_SMALL); assertThatInternalProperty(A_KEY) .hasTextValue(VALUE_SMALL) .hasCreatedAt(DATE_2); }
@Test public void selectByKeys_throws_IAE_when_keys_contains_empty_string() { Random random = new Random(); Set<String> keysIncludingAnEmptyString = Stream.of( IntStream.range(0, random.nextInt(10)).mapToObj(i -> "b_" + i), Stream.of(""), IntStream.range(0, random.nextInt(10)).mapToObj(i -> "a_" + i)) .flatMap(s -> s) .collect(Collectors.toSet()); expectKeyNullOrEmptyIAE(); underTest.selectByKeys(dbSession, keysIncludingAnEmptyString); }
@Test public void save_throws_IAE_if_value_is_empty() { expectValueNullOrEmptyIAE(); underTest.save(dbSession, A_KEY, EMPTY_STRING); }
@Test public void save_persists_value_in_varchar_if_less_than_4000() { when(system2.now()).thenReturn(DATE_2); underTest.save(dbSession, A_KEY, VALUE_SMALL); assertThatInternalProperty(A_KEY) .hasTextValue(VALUE_SMALL) .hasCreatedAt(DATE_2); }
@Test public void saveAsEmpty_throws_IAE_if_key_is_null() { expectKeyNullOrEmptyIAE(); underTest.saveAsEmpty(dbSession, null); }
@Test public void save_persists_new_value_in_varchar_if_4000_when_old_one_was_in_varchar() { when(system2.now()).thenReturn(DATE_1, DATE_2); underTest.save(dbSession, A_KEY, VALUE_SMALL); assertThatInternalProperty(A_KEY) .hasTextValue(VALUE_SMALL) .hasCreatedAt(DATE_1); underTest.save(dbSession, A_KEY, VALUE_SIZE_4000); assertThatInternalProperty(A_KEY) .hasTextValue(VALUE_SIZE_4000) .hasCreatedAt(DATE_2); }
@Test public void save_throws_IAE_if_key_is_empty() { expectKeyNullOrEmptyIAE(); underTest.save(dbSession, EMPTY_STRING, VALUE_SMALL); }
@Test public void saveAsEmpty_persist_property_without_textvalue_nor_clob_value_when_old_value_was_in_clob() { when(system2.now()).thenReturn(DATE_2, DATE_1); underTest.save(dbSession, A_KEY, VALUE_SIZE_4001); assertThatInternalProperty(A_KEY) .hasClobValue(VALUE_SIZE_4001) .hasCreatedAt(DATE_2); underTest.saveAsEmpty(dbSession, A_KEY); assertThatInternalProperty(A_KEY) .isEmpty() .hasCreatedAt(DATE_1); }
@Test public void saveAsEmpty_throws_IAE_if_key_is_empty() { expectKeyNullOrEmptyIAE(); underTest.saveAsEmpty(dbSession, EMPTY_STRING); }
@Test public void save_persists_new_value_in_clob_if_more_than_4000_when_old_one_was_in_clob() { when(system2.now()).thenReturn(DATE_1, DATE_2); String oldValue = VALUE_SIZE_4001 + "blabla"; underTest.save(dbSession, A_KEY, oldValue); assertThatInternalProperty(A_KEY) .hasClobValue(oldValue) .hasCreatedAt(DATE_1); underTest.save(dbSession, A_KEY, VALUE_SIZE_4001); assertThatInternalProperty(A_KEY) .hasClobValue(VALUE_SIZE_4001) .hasCreatedAt(DATE_2); }
@Test public void save_throws_IAE_if_key_is_null() { expectKeyNullOrEmptyIAE(); underTest.save(dbSession, null, VALUE_SMALL); }
@Test public void save_persists_value_in_varchar_if_more_than_4000() { when(system2.now()).thenReturn(DATE_2); underTest.save(dbSession, A_KEY, VALUE_SIZE_4001); assertThatInternalProperty(A_KEY) .hasClobValue(VALUE_SIZE_4001) .hasCreatedAt(DATE_2); }
@Test public void selectByKey_throws_IAE_when_key_is_null() { expectKeyNullOrEmptyIAE(); underTest.selectByKey(dbSession, null); }
@Test public void saveAsEmpty_persist_property_without_textvalue_nor_clob_value() { when(system2.now()).thenReturn(DATE_2); underTest.saveAsEmpty(dbSession, A_KEY); assertThatInternalProperty(A_KEY) .isEmpty() .hasCreatedAt(DATE_2); }
@Test public void selectByKey_throws_IAE_when_key_is_empty() { expectKeyNullOrEmptyIAE(); underTest.selectByKey(dbSession, EMPTY_STRING); }
@Test public void saveAsEmpty_persist_property_without_textvalue_nor_clob_value_when_old_value_was_in_varchar() { when(system2.now()).thenReturn(DATE_1, DATE_2); underTest.save(dbSession, A_KEY, VALUE_SMALL); assertThatInternalProperty(A_KEY) .hasTextValue(VALUE_SMALL) .hasCreatedAt(DATE_1); underTest.saveAsEmpty(dbSession, A_KEY); assertThatInternalProperty(A_KEY) .isEmpty() .hasCreatedAt(DATE_2); }