Skip to content

Commit

Permalink
HHH-12246 - Fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
dreab8 committed Jan 24, 2018
1 parent 9d33596 commit 9704b56
Showing 1 changed file with 21 additions and 8 deletions.
Expand Up @@ -30,12 +30,9 @@
import org.junit.Before;
import org.junit.Test;

import org.mockito.Mockito;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.doThrow;

/**
* @author Vlad Mihalcea
Expand All @@ -44,10 +41,10 @@ public class SchemaScriptFileGenerationFailureTest {
private Writer writer;
private EntityManagerFactoryBuilder entityManagerFactoryBuilder;


@Before
public void setUp() throws IOException {
writer = Mockito.mock( Writer.class );
doThrow( new IOException( "Expected" ) ).when( writer ).flush();
public void setUp() {
writer = new FailingWriter();

entityManagerFactoryBuilder = Bootstrap.getEntityManagerFactoryBuilder(
buildPersistenceUnitDescriptor(),
Expand All @@ -57,7 +54,7 @@ public void setUp() throws IOException {

@Test
@TestForIssue(jiraKey = "HHH-12192")
public void testErrorMessageContainsTheFailingDDLCommand() throws Exception {
public void testErrorMessageContainsTheFailingDDLCommand() {
try {
entityManagerFactoryBuilder.generateSchema();
fail( "Should haave thrown IOException" );
Expand All @@ -79,7 +76,6 @@ public void testErrorMessageContainsTheFailingDDLCommand() throws Exception {

IOException root = (IOException) e.getCause().getCause().getCause();
assertEquals( "Expected", root.getMessage() );

}
}

Expand Down Expand Up @@ -116,4 +112,21 @@ private Map getConfig() {
return config;
}

public class FailingWriter extends Writer {

@Override
public void write(char[] cbuf, int off, int len) throws IOException {

}

@Override
public void flush() throws IOException {
throw new IOException( "Expected" );
}

@Override
public void close() throws IOException {

}
}
}

0 comments on commit 9704b56

Please sign in to comment.