package de.idos.updates;

import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class UpdateCheckTest {

    UpdateConnection connection = mock(UpdateConnection.class);

    @Test
    public void returnsCurrentVersionIfNoNewerIsAvailable() throws Exception {
        Version currentVersion = new NumericVersion(1, 0, 0);
        when(connection.getLatestInstalledVersion()).thenReturn(currentVersion);
        Version latestVersion = new NumericVersion(0, 0, 0);
        when(connection.getLatestAvailableVersion()).thenReturn(latestVersion);
        UpdateCheck updateCheck = new UpdateCheck(connection);
        Version version = updateCheck.getLatestVersion();
        assertThat(version, is(currentVersion));
    }
}

@@ -248,17 +248,131 @@
 kTest %7B%0A
+    Version currentVersion = new NumericVersion(1, 0, 0);%0A    Version latestVersion = new NumericVersion(0, 0, 0);
 %0A
-
     Upda
@@ -521,70 +521,8 @@
 n %7B%0A
-        Version currentVersion = new NumericVersion(1, 0, 0);%0A
     
@@ -602,69 +602,8 @@
 n);%0A
-        Version latestVersion = new NumericVersion(0, 0, 0);%0A
     
@@ -853,11 +853,477 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void doesNotChangeStateIfNewerVersionBecomesAvailableLater() throws Exception %7B%0A        when(connection.getLatestInstalledVersion()).thenReturn(currentVersion);%0A        when(connection.getLatestAvailableVersion()).thenReturn(latestVersion, new NumericVersion(1,1,0));%0A        UpdateCheck updateCheck = new UpdateCheck(connection);%0A        Version version = updateCheck.getLatestVersion();%0A        assertThat(version, is(currentVersion));%0A    %7D
 %0A%7D%0A

Asserts that UpdateCheck is immutable