Changeset 18009 in josm for trunk/test


Ignore:
Timestamp:
2021-07-13T00:27:59+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #20860 - make sure to not try to close a note when none is selected

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/osm/NoteDataTest.java

    r17275 r18009  
    33
    44import static org.junit.jupiter.api.Assertions.assertEquals;
     5import static org.junit.jupiter.api.Assertions.assertNotNull;
     6import static org.junit.jupiter.api.Assertions.assertNull;
     7import static org.junit.jupiter.api.Assertions.assertThrows;
     8import static org.junit.jupiter.api.Assertions.assertTrue;
    59
    610import java.util.Arrays;
     11import java.util.List;
    712
    813import org.junit.jupiter.api.Test;
     14import org.junit.jupiter.api.extension.RegisterExtension;
    915import org.openstreetmap.josm.data.coor.LatLon;
    1016import org.openstreetmap.josm.data.notes.Note;
     17import org.openstreetmap.josm.data.notes.Note.State;
     18import org.openstreetmap.josm.data.notes.NoteComment;
     19import org.openstreetmap.josm.testutils.JOSMTestRules;
     20
     21import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    1122
    1223/**
     
    1425 */
    1526class NoteDataTest {
     27
     28    /**
     29     * Setup test.
     30     */
     31    @RegisterExtension
     32    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     33    public JOSMTestRules test = new JOSMTestRules().preferences();
    1634
    1735    /**
     
    2543        assertEquals(1, notEmpty.getNotes().size());
    2644    }
     45
     46    /**
     47     * Unit test for {@link NoteData#closeNote}
     48     */
     49    @Test
     50    void testCloseNote_nominal() {
     51        Note note = new Note(LatLon.ZERO);
     52        note.setState(State.OPEN);
     53        assertNull(note.getClosedAt());
     54        assertTrue(note.getComments().isEmpty());
     55
     56        NoteData data = new NoteData(Arrays.asList(note));
     57        data.closeNote(note, "foo");
     58
     59        assertEquals(State.CLOSED, note.getState());
     60        assertNotNull(note.getClosedAt());
     61        List<NoteComment> comments = note.getComments();
     62        assertEquals(1, comments.size());
     63        NoteComment comment = comments.get(0);
     64        assertEquals("foo", comment.getText());
     65        assertEquals(note.getClosedAt(), comment.getCommentTimestamp());
     66    }
     67
     68    /**
     69     * Checks that closeNote does not throw NPE on null arguments
     70     */
     71    @Test
     72    void testCloseNote_nullsafe() {
     73        assertEquals("Note to close must be in layer",
     74                assertThrows(IllegalArgumentException.class,
     75                        () -> new NoteData().closeNote(null, null)).getMessage());
     76    }
    2777}
Note: See TracChangeset for help on using the changeset viewer.