private ILoggingEvent log(List<ILoggingEvent> events) { final Integer value = ThreadLocalRandom.current().nextInt(); testLogger.trace("{}", value); assertThat(events).hasSize(1); final ILoggingEvent event = events.remove(0); assertThat(event.getLevel()).isEqualTo(Level.TRACE); assertThat(event.getFormattedMessage()).isEqualTo(value.toString()); assertThat(event.getArgumentArray()).containsExactly(value); return event; }
@Test public void testListToIterator() { final List<String> in = new ArrayList<String>(2); in.add("1"); in.add("2"); final Object[] out = toArray(IterableLike.of(in)); assertThat(out).containsExactly("1", "2"); }
@Test public void testSetToIterator() { final Set<String> in = new HashSet<String>(2); in.add("1"); in.add("2"); final Object[] out = toArray(IterableLike.of(in)); assertThat(out).containsExactly("1", "2"); }
@Test public void testObjectArray() { ao.insertIntArray(testInts); Object[] actuals = ao.fetchObjectArray(); Object[] expecteds = IntStream.of(testInts).mapToObj(Integer::valueOf).toArray(Object[]::new); assertThat(actuals).containsExactly(expecteds); }
@Test public void testUuidArray() { final UuidObject uo = h.attach(UuidObject.class); UUID[] ary = new UUID[] {UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID()}; uo.insertArray(ary); assertThat(uo.getArray()).containsExactly(ary); }
@Test public void subRegionName() { RegionPath path = new RegionPath("test1/test2"); assertThat(path.getParent()).isEqualTo("/test1"); assertThat(path.getName()).isEqualTo("test2"); assertThat(path.isRoot()).isFalse(); assertThat(path.getRegionsOnParentPath()).containsExactly("test1"); assertThat(path.getRootRegionName()).isEqualTo("test1"); }
@Test public void subSubRegionName() { RegionPath path = new RegionPath("test1/test2/test3"); assertThat(path.getParent()).isEqualTo("/test1/test2"); assertThat(path.getName()).isEqualTo("test3"); assertThat(path.isRoot()).isFalse(); assertThat(path.getRegionsOnParentPath()).containsExactly("test1", "test2"); assertThat(path.getRootRegionName()).isEqualTo("test1"); }
@Test public void subRegionNameWithSlash() { RegionPath path = new RegionPath("/test1/test2"); assertThat(path.getParent()).isEqualTo("/test1"); assertThat(path.getName()).isEqualTo("test2"); assertThat(path.isRoot()).isFalse(); assertThat(path.getRegionsOnParentPath()).containsExactly("test1"); assertThat(path.getRootRegionName()).isEqualTo("test1"); }
@Test public void subSubRegionNameWithSlash() { RegionPath path = new RegionPath("/test1/test2/test3"); assertThat(path.getParent()).isEqualTo("/test1/test2"); assertThat(path.getName()).isEqualTo("test3"); assertThat(path.isRoot()).isFalse(); assertThat(path.getRegionsOnParentPath()).containsExactly("test1", "test2"); assertThat(path.getRootRegionName()).isEqualTo("test1"); } }
@Test public void oneQueueWithOneElementShouldConvertToArrayWhenPassedZeroLengthArray() { assertThat(oneQueueWithTestElement(TEST_ELEMENT).toArray(new Integer[0])) .containsExactly(TEST_ELEMENT); }
@Test public void testStringArrayToIterator() { final String[] in = new String[]{"1", "2"}; final Object[] out = toArray(IterableLike.of(in)); assertThat(out).containsExactly("1", "2"); }
@Test public void emptyOneQueueShouldConvertToArrayAndPutNullMarkerAndReuseInputArrayOnWhenPassedOneLengthArray() { Queue<Integer> q = emptyOneQueue(); //and Integer[] passedArray = new Integer[1]; //when Integer[] convertedArray = q.toArray(passedArray); //then assertThat(convertedArray) .containsExactly((Integer)null) .isSameAs(passedArray); }
@Test public void oneQueueWithOneElementShouldConvertToArrayAndReuseInputArrayWhenPassedOneLengthArray() { Queue<Integer> q = oneQueueWithTestElement(TEST_ELEMENT); //and Integer[] passedArray = new Integer[1]; //when Integer[] convertedArray = q.toArray(passedArray); //then assertThat(convertedArray) .containsExactly(TEST_ELEMENT) .isSameAs(passedArray); }
@Test public void toIntegerArray_returnsOrderedArray() { int[] sequence = new int[] {0, 1, 2, 4, 8}; assertThat(toIntegerArray(sequence)).isNotNull().hasSize(sequence.length).containsExactly(0, 1, 2, 4, 8); }
@Test public void get_string_array_settings() { MapSettings serverSettings = new MapSettings(); serverSettings.setProperty("prop", "1,3.4,8,50"); when(settingsRepository.getConfiguration()).thenReturn(serverSettings.asConfig()); MeasureComputerContextImpl underTest = newContext(FILE_1_REF); assertThat(underTest.getSettings().getStringArray("prop")).containsExactly("1", "3.4", "8", "50"); assertThat(underTest.getSettings().getStringArray("unknown")).isEmpty(); }
@Test public void getDefaultValues() { Configuration config = new DefaultConfiguration(new PropertyDefinitions(Arrays.asList( PropertyDefinition.builder("single").multiValues(false).defaultValue("default").build(), PropertyDefinition.builder("multiA").multiValues(true).defaultValue("foo,bar").build())), new Encryption(null), ImmutableMap.of()) { }; assertThat(config.get("multiA")).hasValue("foo,bar"); assertThat(config.getStringArray("multiA")).containsExactly("foo", "bar"); assertThat(config.get("single")).hasValue("default"); assertThat(config.getStringArray("single")).containsExactly("default"); }
@Test public void shouldSendOnErrorSignalWithDelaySubscription() { Signal<? extends Long>[] first = new Signal[1]; RuntimeException error = new RuntimeException(); StepVerifier.create(Flux.<Long>error(error) .switchOnFirst((s, f) -> { first[0] = s; return f.delaySubscription(Duration.ofMillis(100)); })) .expectSubscription() .expectError(RuntimeException.class) .verify(); Assertions.assertThat(first).containsExactly(Signal.error(error)); }
@Test public void shouldSendOnErrorSignal() { Signal<? extends Long>[] first = new Signal[1]; RuntimeException error = new RuntimeException(); StepVerifier.create(Flux.<Long>error(error) .switchOnFirst((s, f) -> { first[0] = s; return f; })) .expectSubscription() .expectError(RuntimeException.class) .verify(); Assertions.assertThat(first).containsExactly(Signal.error(error)); }
@Test public void shouldSendOnCompleteSignalWithDelaySubscription() { Signal<? extends Long>[] first = new Signal[1]; StepVerifier.create(Flux.<Long>empty() .switchOnFirst((s, f) -> { first[0] = s; return f.delaySubscription(Duration.ofMillis(100)); })) .expectSubscription() .expectComplete() .verify(); Assertions.assertThat(first).containsExactly(Signal.complete()); }
@Test public void accessingPropertySetPropertiesShouldBeConsistentWithDeclaration() { Configuration config = new DefaultConfiguration(new PropertyDefinitions(Arrays.asList( PropertyDefinition.builder("props").fields(PropertyFieldDefinition.build("foo1").name("Foo1").build(), PropertyFieldDefinition.build("foo2").name("Foo2").build()).build())), new Encryption(null), ImmutableMap.of("props", "1,2", "props.1.foo1", "a", "props.1.foo2", "b")) { }; assertThat(config.get("props")).hasValue("1,2"); assertThat(logTester.logs(LoggerLevel.WARN)) .contains( "Access to the multi-values/property set property 'props' should be made using 'getStringArray' method. The SonarQube plugin using this property should be updated."); logTester.clear(); assertThat(config.getStringArray("props")).containsExactly("1", "2"); assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty(); }