001/* 002 * Copyright (C) 2022 - 2024, the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package io.github.ascopes.jct.assertions; 017 018import io.github.ascopes.jct.repr.StackTraceRepresentation; 019import java.util.ArrayList; 020import java.util.List; 021import org.apiguardian.api.API; 022import org.apiguardian.api.API.Status; 023import org.assertj.core.api.AbstractListAssert; 024import org.jspecify.annotations.Nullable; 025 026/** 027 * Assertions for a list of {@link StackTraceElement stack trace frames}. 028 * 029 * <p>This type is a placeholder and will be replaced when AssertJ releases changes to 030 * support assertions on stack traces. 031 * 032 * @author Ashley Scopes 033 * @since 0.0.1 034 */ 035@API(since = "0.0.1", status = Status.STABLE) 036public final class StackTraceAssert 037 extends AbstractListAssert<StackTraceAssert, List<? extends StackTraceElement>, StackTraceElement, StackTraceElementAssert> { 038 039 /** 040 * Initialize a new assertions object. 041 * 042 * @param actual the list of stack trace elements to assert upon. 043 */ 044 @SuppressWarnings("DataFlowIssue") 045 public StackTraceAssert(@Nullable List<? extends StackTraceElement> actual) { 046 super(actual, StackTraceAssert.class); 047 info.useRepresentation(StackTraceRepresentation.getInstance()); 048 } 049 050 @Override 051 protected StackTraceElementAssert toAssert(StackTraceElement value, String description) { 052 return new StackTraceElementAssert(value).describedAs(description); 053 } 054 055 @Override 056 protected StackTraceAssert newAbstractIterableAssert( 057 Iterable<? extends StackTraceElement> iterable 058 ) { 059 var list = new ArrayList<StackTraceElement>(); 060 iterable.forEach(list::add); 061 return new StackTraceAssert(list); 062 } 063}