Skip to content

Commit

Permalink
Merge pull request #77 from mkotsur/DEPLOYITPB-4656
Browse files Browse the repository at this point in the history
Fixed SshSudoFile.equals
  • Loading branch information
Vincent Partington committed Jun 10, 2013
2 parents 59abd40 + 980727c commit 4f09a8c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/main/java/com/xebialabs/overthere/ssh/SshSudoFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SshSudoFile extends SshScpFile {

/**
* Constructs a SshSudoHostFile
*
*
* @param connection
* the connection connected to the host
* @param remotePath
Expand Down Expand Up @@ -187,7 +187,7 @@ void copyToTempFile(OverthereFile tempFile) {
if (chmodResult != 0) {
String errorMessage = chmodCapturedOutput.getOutput();
throw new RuntimeIOException("Cannot grant group and other read and execute permissions (chmod -R go+rX) to file " + tempFile
+ " before download: " + errorMessage);
+ " before download: " + errorMessage);
}
}

Expand Down Expand Up @@ -220,6 +220,19 @@ boolean isTempFile() {
return isTempFile;
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof SshSudoFile)) {
return false;
}
return super.equals(obj) && isTempFile == ((SshSudoFile)obj).isTempFile;
}

@Override
public int hashCode() {
return path.hashCode() + Boolean.valueOf(isTempFile).hashCode();
}

private Logger logger = LoggerFactory.getLogger(SshSudoFile.class);

}
37 changes: 37 additions & 0 deletions src/test/java/com/xebialabs/overthere/ssh/SshSudoFileTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.xebialabs.overthere.ssh;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

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

public class SshSudoFileTest {

public static final String REMOTE_PATH = "/tmp/file.txt";
private SshSudoConnection connection;

@BeforeClass
public void setup() {
connection = mock(SshSudoConnection.class);
}

@Test
public void shouldNotBeEqualWhenOneIsTempAndAnotherIsNot() {
SshSudoFile f1 = new SshSudoFile(connection, REMOTE_PATH, false);
SshSudoFile f2 = new SshSudoFile(connection, REMOTE_PATH, true);
assertThat(f1, is(not(f2)));
assertThat(f1.hashCode(), is(not(f2.hashCode())));
}

@Test
public void shouldBeEqual() {
SshSudoFile f1 = new SshSudoFile(connection, REMOTE_PATH, false);
SshSudoFile f2 = new SshSudoFile(connection, REMOTE_PATH, false);
assertThat(f1, is(f2));
assertThat(f1.hashCode(), is(f2.hashCode()));
}

}

0 comments on commit 4f09a8c

Please sign in to comment.