Details

Recommendation type: New assertions

Configurable in Preferences: No

Filter category: Assertions

Description

This recommendation is displayed when your running your code using the Track option and UTA detects new assertions that are available for accessible fields. See Tracking Object Changes and Creating Assertions for details.

Example

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);
    }
}



  • No labels