package syncthing.bep.v1;

import org.junit.Before;
import org.junit.Test;
import syncthing.bep.util.XdrInputStream;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

public class CloseTests {

    private static final String SOME_REASON = "some reason";

    private Close message;

    @Before
    public void setUp() throws Exception {
        message = new Close(SOME_REASON);
    }

    @Test
    public void isType7() {
        assertThat(message.getType(), is(equalTo((byte) 7)));
    }

    @Test
    public void hasXdrEncodedReason() {
        String reason = extractReasonFromClose(message);
        assertThat(reason, is(equalTo(SOME_REASON)));
    }

    private String extractReasonFromClose(Close message) {
        XdrInputStream in = new XdrInputStream(message.getContents());
        return in.readString();
    }

    @Test
    public void xdrEncodedReasonEndsOnFourByteBoundary() {
        int amountOfBytes = message.getContents().length;
        assertThat(amountOfBytes % 4, is(equalTo(0)));
    }
}

@@ -915,196 +915,7 @@
    %7D
-%0A%0A    @Test%0A    public void xdrEncodedReasonEndsOnFourByteBoundary() %7B%0A        int amountOfBytes = message.getContents().length;%0A        assertThat(amountOfBytes %25 4, is(equalTo(0)));%0A    %7D
 %0A%7D%0A

remove superfluous test.