org.junit.Assert.assertArrayEquals()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(11.6k)|赞(0)|评价(0)|浏览(882)

本文整理了Java中org.junit.Assert.assertArrayEquals()方法的一些代码示例,展示了Assert.assertArrayEquals()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Assert.assertArrayEquals()方法的具体详情如下:
包路径:org.junit.Assert
类名称:Assert
方法名:assertArrayEquals

Assert.assertArrayEquals介绍

[英]Asserts that two byte arrays are equal. If they are not, an AssertionError is thrown with the given message.
[中]断言两个字节数组相等。如果不是,则会抛出带有给定消息的AssertionError。

代码示例

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testGroupBy() {
  Observable<String> source = Observable.just("one", "two", "three", "four", "five", "six");
  Observable<GroupedObservable<Integer, String>> grouped = source.groupBy(length);
  Map<Integer, Collection<String>> map = toMap(grouped);
  assertEquals(3, map.size());
  assertArrayEquals(Arrays.asList("one", "two", "six").toArray(), map.get(3).toArray());
  assertArrayEquals(Arrays.asList("four", "five").toArray(), map.get(4).toArray());
  assertArrayEquals(Arrays.asList("three").toArray(), map.get(5).toArray());
}

代码示例来源:origin: spring-projects/spring-framework

@Test // SPR-16590
public void parameterMap() {
  this.multipartParams.put("key1", new String[] {"p1"});
  this.multipartParams.put("key2", new String[] {"p2"});
  this.queryParams.add("key1", "q1");
  this.queryParams.add("key3", "q3");
  Map<String, String[]> map = createMultipartRequest().getParameterMap();
  assertEquals(3, map.size());
  assertArrayEquals(new String[] {"p1", "q1"}, map.get("key1"));
  assertArrayEquals(new String[] {"p2"}, map.get("key2"));
  assertArrayEquals(new String[] {"q3"}, map.get("key3"));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void resolveStringArrayArgument() throws Exception {
  String[] expected = new String[] {"foo", "bar"};
  servletRequest.addHeader("name", expected);
  Object result = resolver.resolveArgument(paramNamedValueStringArray, null, webRequest, null);
  assertTrue(result instanceof String[]);
  assertArrayEquals(expected, (String[]) result);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void write() throws IOException {
  this.converter.write((byte) -8, null, this.response);
  assertEquals("ISO-8859-1", this.servletResponse.getCharacterEncoding());
  assertTrue(this.servletResponse.getContentType().startsWith(MediaType.TEXT_PLAIN_VALUE));
  assertEquals(2, this.servletResponse.getContentLength());
  assertArrayEquals(new byte[] { '-', '8' }, this.servletResponse.getContentAsByteArray());
}

代码示例来源:origin: neo4j/neo4j

public void assertRecord( int index, Object... values )
{
  assertThat( index, lessThan( records.size() ) );
  assertArrayEquals( records.get( index ).fields(), values );
}

代码示例来源:origin: checkstyle/checkstyle

@Test
public void testExtractBlockComment() {
  final FileContents fileContents = new FileContents(
      new FileText(new File("filename"), Arrays.asList("   ", "    ", "  /* test   ",
          "  */  ", "   ")));
  fileContents.reportCComment(3, 2, 4, 2);
  final Map<Integer, List<TextBlock>> blockComments =
    fileContents.getBlockComments();
  final String[] text = blockComments.get(3).get(0).getText();
  assertArrayEquals("Invalid comment text", new String[] {"/* test   ", "  *"}, text);
}

代码示例来源:origin: apache/flink

private void compareMaps(List<List<Event>> actual, List<List<Event>> expected) {
  Assert.assertEquals(expected.size(), actual.size());
  for (List<Event> p: actual) {
    Collections.sort(p, new EventComparator());
  }
  for (List<Event> p: expected) {
    Collections.sort(p, new EventComparator());
  }
  Collections.sort(actual, new ListEventComparator());
  Collections.sort(expected, new ListEventComparator());
  Assert.assertArrayEquals(expected.toArray(), actual.toArray());
}

代码示例来源:origin: checkstyle/checkstyle

@Test
public void testCheckerProcessCallAllNeededMethodsOfFileSets() throws Exception {
  final DummyFileSet fileSet = new DummyFileSet();
  final Checker checker = new Checker();
  checker.addFileSetCheck(fileSet);
  checker.process(Collections.singletonList(new File("dummy.java")));
  final List<String> expected =
    Arrays.asList("beginProcessing", "finishProcessing", "destroy");
  assertArrayEquals("Method calls were not expected",
      expected.toArray(), fileSet.getMethodCalls().toArray());
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testGetValuesUnbounded() {
  ReplaySubject<Object> rs = ReplaySubject.createUnbounded();
  Object[] expected = new Object[10];
  for (int i = 0; i < expected.length; i++) {
    expected[i] = i;
    rs.onNext(i);
    assertArrayEquals(Arrays.copyOf(expected, i + 1), rs.getValues());
  }
  rs.onComplete();
  assertArrayEquals(expected, rs.getValues());
}

代码示例来源:origin: spring-projects/spring-framework

private void assertGetMergedAnnotation(Class<?> element, String... expected) {
  String name = ContextConfig.class.getName();
  ContextConfig contextConfig = getMergedAnnotation(element, ContextConfig.class);
  assertNotNull("Should find @ContextConfig on " + element.getSimpleName(), contextConfig);
  assertArrayEquals("locations", expected, contextConfig.locations());
  assertArrayEquals("value", expected, contextConfig.value());
  assertArrayEquals("classes", new Class<?>[0], contextConfig.classes());
  // Verify contracts between utility methods:
  assertTrue(isAnnotated(element, name));
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testGroupByWithElementSelector() {
  Observable<String> source = Observable.just("one", "two", "three", "four", "five", "six");
  Observable<GroupedObservable<Integer, Integer>> grouped = source.groupBy(length, length);
  Map<Integer, Collection<Integer>> map = toMap(grouped);
  assertEquals(3, map.size());
  assertArrayEquals(Arrays.asList(3, 3, 3).toArray(), map.get(3).toArray());
  assertArrayEquals(Arrays.asList(4, 4).toArray(), map.get(4).toArray());
  assertArrayEquals(Arrays.asList(5).toArray(), map.get(5).toArray());
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void ambiguousHeaderPreflightRequest() throws Exception {
  this.headers.add(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
  this.headers.add(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "header1");
  ResponseEntity<String> entity = performOptions("/ambiguous-header", this.headers, String.class);
  assertEquals(HttpStatus.OK, entity.getStatusCode());
  assertEquals("http://site1.com", entity.getHeaders().getAccessControlAllowOrigin());
  assertArrayEquals(new HttpMethod[] {HttpMethod.GET},
      entity.getHeaders().getAccessControlAllowMethods().toArray());
  assertArrayEquals(new String[] {"header1"},
      entity.getHeaders().getAccessControlAllowHeaders().toArray());
  assertTrue(entity.getHeaders().getAccessControlAllowCredentials());
}

代码示例来源:origin: gocd/gocd

@Test
public void shouldGetFilesToLoadMatchingPattern() throws Exception {
  GoConfigMother mother = new GoConfigMother();
  PipelineConfig pipe1 = mother.cruiseConfigWithOnePipelineGroup().getAllPipelineConfigs().get(0);
  File file1 = helper.addFileWithPipeline("pipe1.gocd.xml", pipe1);
  File file2 = helper.addFileWithPipeline("pipe1.gcd.xml", pipe1);
  File file3 = helper.addFileWithPipeline("subdir/pipe1.gocd.xml", pipe1);
  File file4 = helper.addFileWithPipeline("subdir/sub/pipe1.gocd.xml", pipe1);
  File[] matchingFiles = xmlPartialProvider.getFiles(tmpFolder, mock(PartialConfigLoadContext.class));
  File[] expected = new File[] {file1, file3, file4};
  assertArrayEquals("Matched files are: " + Arrays.asList(matchingFiles).toString(), expected, matchingFiles);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testRequestToFooHandler() throws Exception {
  URI url = new URI("http://localhost:" + this.port + "/foo");
  RequestEntity<Void> request = RequestEntity.get(url).build();
  ResponseEntity<byte[]> response = new RestTemplate().exchange(request, byte[].class);
  assertEquals(HttpStatus.OK, response.getStatusCode());
  assertArrayEquals("foo".getBytes("UTF-8"), response.getBody());
}

代码示例来源:origin: apache/flink

public static void compareMaps(List<List<Event>> actual, List<List<Event>> expected) {
  Assert.assertEquals(expected.size(), actual.size());
  for (List<Event> p: actual) {
    Collections.sort(p, new EventComparator());
  }
  for (List<Event> p: expected) {
    Collections.sort(p, new EventComparator());
  }
  Collections.sort(actual, new ListEventComparator());
  Collections.sort(expected, new ListEventComparator());
  Assert.assertArrayEquals(expected.toArray(), actual.toArray());
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void getMergedAnnotationAttributesWithAliasedComposedAnnotation() {
  Class<?> element = AliasedComposedContextConfigClass.class;
  String name = ContextConfig.class.getName();
  AnnotationAttributes attributes = getMergedAnnotationAttributes(element, name);
  assertNotNull("Should find @ContextConfig on " + element.getSimpleName(), attributes);
  assertArrayEquals("value", asArray("test.xml"), attributes.getStringArray("value"));
  assertArrayEquals("locations", asArray("test.xml"), attributes.getStringArray("locations"));
  // Verify contracts between utility methods:
  assertTrue(isAnnotated(element, name));
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testGetValues() {
  ReplaySubject<Object> rs = ReplaySubject.create();
  Object[] expected = new Object[10];
  for (int i = 0; i < expected.length; i++) {
    expected[i] = i;
    rs.onNext(i);
    assertArrayEquals(Arrays.copyOf(expected, i + 1), rs.getValues());
  }
  rs.onComplete();
  assertArrayEquals(expected, rs.getValues());
}

代码示例来源:origin: spring-projects/spring-framework

private void getMergedAnnotationAttributesWithHalfConventionBasedAndHalfAliasedComposedAnnotation(Class<?> clazz) {
  String[] expected = asArray("explicitDeclaration");
  String name = ContextConfig.class.getName();
  String simpleName = clazz.getSimpleName();
  AnnotationAttributes attributes = getMergedAnnotationAttributes(clazz, name);
  assertNotNull("Should find @ContextConfig on " + simpleName, attributes);
  assertArrayEquals("locations for class [" + clazz.getSimpleName() + "]", expected, attributes.getStringArray("locations"));
  assertArrayEquals("value for class [" + clazz.getSimpleName() + "]", expected, attributes.getStringArray("value"));
  // Verify contracts between utility methods:
  assertTrue(isAnnotated(clazz, name));
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testGroupByWithElementSelector2() {
  Observable<String> source = Observable.just("one", "two", "three", "four", "five", "six");
  Observable<GroupedObservable<Integer, Integer>> grouped = source.groupBy(length, length);
  Map<Integer, Collection<Integer>> map = toMap(grouped);
  assertEquals(3, map.size());
  assertArrayEquals(Arrays.asList(3, 3, 3).toArray(), map.get(3).toArray());
  assertArrayEquals(Arrays.asList(4, 4).toArray(), map.get(4).toArray());
  assertArrayEquals(Arrays.asList(5).toArray(), map.get(5).toArray());
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void writeUtf16() throws IOException {
  MediaType contentType = new MediaType("text", "plain", StandardCharsets.UTF_16);
  this.converter.write(Integer.valueOf(958), contentType, this.response);
  assertEquals("UTF-16", this.servletResponse.getCharacterEncoding());
  assertTrue(this.servletResponse.getContentType().startsWith(MediaType.TEXT_PLAIN_VALUE));
  assertEquals(8, this.servletResponse.getContentLength());
  // First two bytes: byte order mark
  assertArrayEquals(new byte[] { -2, -1, 0, '9', 0, '5', 0, '8' }, this.servletResponse.getContentAsByteArray());
}

相关文章