public final void testSkipCxxTest() throws Exception { CxxTestRunnerMojo cxxTestRunnerMojo = ( CxxTestRunnerMojo ) lookupConfiguredMojo( CxxTestRunnerMojo.MOJO_NAME, "/unit/cxxtest/skip-cxxtest.pom" ) ; try { cxxTestRunnerMojo.execute(); } catch ( AbstractMojoExecutionException ame ) { fail( ame.getCause() != null ? ame.getCause().getMessage() : ame.getMessage() ); } if ( !outputStream.toString().contains( CXXTEST_SKIP_MESSAGE ) ) { fail(); } }
@Test public final void testFailingCxxTest() throws Exception { CxxTestRunnerMojo cxxTestRunnerMojo = ( CxxTestRunnerMojo ) lookupConfiguredMojo( CxxTestRunnerMojo.MOJO_NAME, "/unit/cxxtest/failing-test-config.pom" ) ; try { cxxTestRunnerMojo.execute(); } catch ( MojoFailureException mfe ) { return; } catch ( AbstractMojoExecutionException ame ) { fail( ame.getCause() != null ? ame.getCause().getMessage() : ame.getMessage() ); } fail ( "Expected CxxTest failure." ); }
@Test public void resetsMockEvenWhenExceptionOccurs() { Log logMock = mock(Log.class); AbstractSlf4jMojo objectUnderTest = new AbstractSlf4jMojo() { @Override protected void doExecute() throws MojoExecutionException, MojoFailureException { throw new MojoFailureException("FAIL"); } }; objectUnderTest.setLog(logMock); try { objectUnderTest.execute(); } catch (AbstractMojoExecutionException ignored) { } LoggerFactory.getLogger(getClass()).info("Hello JUnit!"); verifyZeroInteractions(logMock); }
private FileWriter setupTargetFile() throws AbstractMojoExecutionException, IOException { if (!target.exists()) { target.getParentFile().mkdirs(); final boolean fileCreated; fileCreated = target.createNewFile(); if (!fileCreated) { throw new MojoFailureException("Could not create target file '" + target.getAbsolutePath() + "'!"); } } return new FileWriter(target); }
@Test public final void testPassingCxxTest() throws Exception { CxxTestRunnerMojo cxxTestRunnerMojo = ( CxxTestRunnerMojo ) lookupConfiguredMojo( CxxTestRunnerMojo.MOJO_NAME, "/unit/cxxtest/passing-test-config.pom" ) ; try { cxxTestRunnerMojo.execute(); } catch ( AbstractMojoExecutionException ame ) { fail( ame.getCause() != null ? ame.getCause().getMessage() : ame.getMessage() ); } }
private String getMessage( String message, Throwable exception ) { String fullMessage = ( message != null ) ? message : ""; for ( Throwable t = exception; t != null; t = t.getCause() ) { String exceptionMessage = t.getMessage(); if ( t instanceof AbstractMojoExecutionException ) { String longMessage = ( (AbstractMojoExecutionException) t ).getLongMessage(); if ( StringUtils.isNotEmpty( longMessage ) ) { if ( StringUtils.isEmpty( exceptionMessage ) || longMessage.contains( exceptionMessage ) ) { exceptionMessage = longMessage; } else if ( !exceptionMessage.contains( longMessage ) ) { exceptionMessage = join( exceptionMessage, '\n' + longMessage ); } } } if ( StringUtils.isEmpty( exceptionMessage ) ) { exceptionMessage = t.getClass().getSimpleName(); } if ( t instanceof UnknownHostException && !fullMessage.contains( "host" ) ) { fullMessage = join( fullMessage, "Unknown host " + exceptionMessage ); } else if ( !fullMessage.contains( exceptionMessage ) ) { fullMessage = join( fullMessage, exceptionMessage ); } } return fullMessage.trim(); }