Skip to content

Commit

Permalink
Use TestUtil consequently, code cleanup
Browse files Browse the repository at this point in the history
* Use TestUtil where it was appropriate but not yet used
* Use static imports for TestUtil
* Organized imports
  • Loading branch information
ralfstx committed Jun 7, 2012
1 parent 6a0976b commit 9970d08
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@

import static org.hamcrest.Matchers.greaterThan;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;


@RunWith( value = Parameterized.class )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.startsWith;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;


public class JSHint_Test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,8 @@
import com.eclipsesource.jshint.ui.internal.preferences.OptionsPreferences;
import com.eclipsesource.jshint.ui.internal.preferences.PreferencesFactory;

import static com.eclipsesource.jshint.ui.test.TestUtil.BUILDER_ID;
import static com.eclipsesource.jshint.ui.test.TestUtil.OLD_BUILDER_ID;
import static com.eclipsesource.jshint.ui.test.TestUtil.OLD_SETTINGS_FILE_NAME;
import static com.eclipsesource.jshint.ui.test.TestUtil.SETTINGS_FILE_NAME;
import static com.eclipsesource.jshint.ui.test.TestUtil.SETTINGS_FOLDER_PATH;
import static com.eclipsesource.jshint.ui.test.TestUtil.SETTINGS_TEMPLATE_0_9;
import static com.eclipsesource.jshint.ui.test.TestUtil.createExampleSettingsFile;
import static com.eclipsesource.jshint.ui.test.TestUtil.createFile;
import static com.eclipsesource.jshint.ui.test.TestUtil.createFolder;
import static com.eclipsesource.jshint.ui.test.TestUtil.createProject;
import static com.eclipsesource.jshint.ui.test.TestUtil.deleteProject;
import static com.eclipsesource.jshint.ui.test.TestUtil.list;
import static com.eclipsesource.jshint.ui.test.TestUtil.readContent;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static com.eclipsesource.jshint.ui.test.TestUtil.*;
import static org.junit.Assert.*;


public class CompatibilityUtil_Test {
Expand Down Expand Up @@ -106,7 +90,7 @@ public void getCurrentVersion() {
}

@Test
public void addsVersionToPreferences() throws Exception {
public void addsVersionToPreferences() {
Version currentVersion = CompatibilityUtil.getCurrentVersion();
Preferences wsPrefs = PreferencesFactory.getWorkspacePreferences();

Expand All @@ -128,7 +112,7 @@ public void turnsEnabledToBasicIncludes() throws Exception {
}

@Test
public void fixPre09FolderExcludePatterns_addsSlashesForFolder() throws Exception {
public void fixPre09FolderExcludePatterns_addsSlashesForFolder() {
createFolder( project, "/target" );
Preferences node = PreferencesFactory.getProjectPreferences( project );
EnablementPreferences enablePrefs = new EnablementPreferences( node );
Expand All @@ -140,7 +124,7 @@ public void fixPre09FolderExcludePatterns_addsSlashesForFolder() throws Exceptio
}

@Test
public void fixPre09FolderExcludePatterns_doesNotAddSlashesForFile() throws Exception {
public void fixPre09FolderExcludePatterns_doesNotAddSlashesForFile() {
createFile( project, "/test.js", "" );
Preferences node = PreferencesFactory.getProjectPreferences( project );
EnablementPreferences enablePrefs = new EnablementPreferences( node );
Expand All @@ -152,7 +136,7 @@ public void fixPre09FolderExcludePatterns_doesNotAddSlashesForFile() throws Exce
}

@Test
public void fixPre09FolderExcludePatterns_doesNotAddAdditionalSlashes() throws Exception {
public void fixPre09FolderExcludePatterns_doesNotAddAdditionalSlashes() {
createFolder( project, "/target" );
Preferences node = PreferencesFactory.getProjectPreferences( project );
EnablementPreferences enablePrefs = new EnablementPreferences( node );
Expand All @@ -164,7 +148,7 @@ public void fixPre09FolderExcludePatterns_doesNotAddAdditionalSlashes() throws E
}

@Test
public void fixPre09FolderExcludePatterns_worksForPre_0_9_4() throws Exception {
public void fixPre09FolderExcludePatterns_worksForPre_0_9_4() {
createFolder( project, "/target" );
Preferences node = PreferencesFactory.getProjectPreferences( project );
EnablementPreferences enablePrefs = new EnablementPreferences( node );
Expand All @@ -177,7 +161,7 @@ public void fixPre09FolderExcludePatterns_worksForPre_0_9_4() throws Exception {
}

@Test
public void fixPre09FolderExcludePatterns_skips_0_9_4() throws Exception {
public void fixPre09FolderExcludePatterns_skips_0_9_4() {
createFolder( project, "/target" );
Preferences node = PreferencesFactory.getProjectPreferences( project );
EnablementPreferences enablePrefs = new EnablementPreferences( node );
Expand All @@ -190,7 +174,7 @@ public void fixPre09FolderExcludePatterns_skips_0_9_4() throws Exception {
}

@Test
public void doesNotChangeProjectsWithoutSettings() throws Exception {
public void doesNotChangeProjectsWithoutSettings() {
CompatibilityUtil.run();

IFolder settingsFolder = project.getFolder( SETTINGS_FOLDER_PATH );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,35 @@
******************************************************************************/
package com.eclipsesource.jshint.ui.internal.builder;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.ByteArrayInputStream;
import java.io.IOException;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.eclipsesource.jshint.ui.test.TestUtil;

import static com.eclipsesource.jshint.ui.test.TestUtil.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;


public class BuilderUtil_Test {

private IProject project;
private IFile file;

@Before
public void setUp() throws CoreException {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
project = workspace.getRoot().getProject( "test.project" );
project.create( null );
project.open( null );
file = project.getFile( "/test.js" );
file.create( new ByteArrayInputStream( "test".getBytes() ), true, null );
public void setUp() {
project = createProject( "test" );
createFile( project, "/test.js", "test" );
}

@After
public void tearDown() throws CoreException {
if( project.exists() ) {
project.delete( true, null );
}
public void tearDown() {
deleteProject( project );
}

@Test
Expand All @@ -56,7 +47,7 @@ public void addBuilder() throws CoreException, IOException {

assertTrue( result );
IFile metadata = project.getFile( ".project" );
assertTrue( TestUtil.readContent( metadata ).contains( TestUtil.BUILDER_ID ) );
assertTrue( readContent( metadata ).contains( TestUtil.BUILDER_ID ) );
}

@Test
Expand All @@ -76,7 +67,7 @@ public void removeBuilder() throws CoreException, IOException {

assertTrue( result );
IFile metadata = project.getFile( ".project" );
assertFalse( TestUtil.readContent( metadata ).contains( TestUtil.BUILDER_ID ) );
assertFalse( readContent( metadata ).contains( TestUtil.BUILDER_ID ) );
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@
******************************************************************************/
package com.eclipsesource.jshint.ui.internal.builder;

import java.io.ByteArrayInputStream;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static com.eclipsesource.jshint.ui.test.TestUtil.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

Expand All @@ -36,20 +33,14 @@ public class MarkerAdapter_Test {
private IFile file;

@Before
public void setUp() throws CoreException {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
project = workspace.getRoot().getProject( TEST_PROJECT );
project.create( null );
project.open( null );
file = project.getFile( "/test.js" );
file.create( new ByteArrayInputStream( "test".getBytes() ), true, null );
public void setUp() {
project = createProject( TEST_PROJECT );
file = createFile( project, "/test.js", "test" );
}

@After
public void tearDown() throws CoreException {
if( project.exists() ) {
project.delete( true, null );
}
public void tearDown() {
deleteProject( project );
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
import org.junit.Test;

import com.eclipsesource.jshint.ui.internal.preferences.ui.IncludesView;
import com.eclipsesource.jshint.ui.test.TestUtil;

import static com.eclipsesource.jshint.ui.test.TestUtil.list;
import static com.eclipsesource.jshint.ui.test.TestUtil.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

Expand All @@ -40,13 +39,13 @@ public class IncludesView_Test {
public void setUp() {
Display display = Display.getDefault();
parent = new Shell( display );
project = TestUtil.createProject( "test" );
project = createProject( "test" );
preferences = new EnablementPreferences( new PreferencesMock( "test" ) );
}

@After
public void tearDown() {
TestUtil.deleteProject( project );
deleteProject( project );
parent.dispose();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;


public class JSHintPreferences_Test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@
import org.junit.Test;

import com.eclipsesource.jshint.Configuration;
import com.eclipsesource.jshint.ui.internal.preferences.OptionParserUtil;
import com.eclipsesource.jshint.ui.internal.preferences.OptionParserUtil.Entry;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;


public class OptionParserUtil_Test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
import org.junit.Test;
import org.osgi.service.prefs.BackingStoreException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;


public class OptionsPreferences_Test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;


public class PathPattern_Test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;


public class PathSegmentPattern_Test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
package com.eclipsesource.jshint.ui.internal.preferences;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.osgi.service.prefs.Preferences;

import static com.eclipsesource.jshint.ui.test.TestUtil.createProject;
import static com.eclipsesource.jshint.ui.test.TestUtil.deleteProject;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;

Expand All @@ -26,14 +26,13 @@ public class PreferencesFactory_Test {
private IProject project;

@Before
public void setUp() throws CoreException {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
project = workspace.getRoot().getProject( "test" );
if( project.exists() ) {
project.delete( true, null );
}
project.create( null );
project.open( null );
public void setUp() {
project = createProject( "test" );
}

@After
public void tearDown() {
deleteProject( project );
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
import org.osgi.service.prefs.Preferences;

import static com.eclipsesource.jshint.ui.test.TestUtil.*;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;


public class ProjectPreferences_Test {
Expand Down
Loading

0 comments on commit 9970d08

Please sign in to comment.