推奨事項のタイプ: 新規アサーション
設定可能: いいえ
フィルター カテゴリアサーション
この推奨事項は、[トラック] オプションを使用してコードを実行し、アクセス可能なフィールドに対して利用可能な新しいアサーションが検出された場合に表示されます。詳細については「オブジェクトの変更の追跡とアサーションの作成」を参照してください。
public class TrackableMethodExample
{
private List<String> coll = Arrays.asList("s1", "s2", "s3", "", null);
private Map<String, String> aMap = new HashMap<String, String>();
private int [] aInts = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5 };
private Integer [] aBigInts = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5 };
private String [] aStrings = { "a", "b", null, "d", "a long string, just long enough to be slightly shortened"};
private State [] aStates = null;
protected int id = 0;
protected String label = null;
private ResultStatus lastChangeStatus = null;
private ResultStatus lastChangeStatusDupe = null;
En enumField = En.E1;
public TrackableMethodExample(State initialState)
{
aStates = new State [] { initialState };
aMap.put("foo", "bar");
}
public int getId(){/*an odd getter*/return/*an odd getter*/ id/*an odd getter*/;/*an odd getter*/}
public String getLabel()
{
return label;
}
public ResultStatus changeState(State newState)
{
aStates = new State [] { aStates[0], newState };
aMap.put("hello", "world");
id = newState.newId;
label = newState.newLabel;
lastChangeStatus = new ResultStatus();
enumField = En.E2;
return lastChangeStatus;
}
public <E> List<E> genericList(List<E> aGenericList) {
return aGenericList;
}
public static final class State
{
public final String newLabel;
public final int newId;
public State(String newLabel, int newId)
{
this.newLabel = newLabel;
this.newId = newId;
}
}
public static final class ResultStatus
{
Object o1 = null;
Object o2 = new Object();
}
public enum En { E1, E2 }
}
public class TrackableMethodExampleTest
{
@Test
public void testChangeState() throws Exception
{
State initialState = new State("state", 2);
// Given
TrackableMethodExample underTest = new TrackableMethodExample(initialState);
// When
State newState = new State("state changed", 10);
ResultStatus result = underTest.changeState(newState);
Assert.assertNotNull(result);
}
}
|