How to use File method of org.easymock.tests2.EasyMockPropertiesTest class

Best Easymock code snippet using org.easymock.tests2.EasyMockPropertiesTest.File

Source:EasyMockPropertiesTest.java Github

copy

Full Screen

...27/**28 * @author Henri Tremblay29 */30public class EasyMockPropertiesTest {31 private static final String NORMAL_PATH = "target" + File.separatorChar + "test-classes";32 private static final String CLOVER_PATH = "target" + File.separatorChar + "clover" + File.separatorChar + "test-classes";33 private static final File PROPERTIES_FILE = new File(isCloverBuild() ? CLOVER_PATH : NORMAL_PATH, "easymock.properties");34 /**35 * Check that the test execution isn't ran by Clover. Because it it's the case, we need to generate the easymock.properties36 * file in a different directory37 */38 private static boolean isCloverBuild() {39 String surefireClasspath = System.getProperty("surefire.test.class.path");40 if(surefireClasspath != null) {41 return surefireClasspath.contains(CLOVER_PATH);42 }43 return false;44 }45 @BeforeClass46 public static void beforeClass() throws Exception {47 // Create an EasyMock property file for the test48 BufferedWriter out = new BufferedWriter(new FileWriter(PROPERTIES_FILE));49 out.write(EasyMock.ENABLE_THREAD_SAFETY_CHECK_BY_DEFAULT + "=" + true);50 out.newLine();51 out.write("easymock.a=1");52 out.newLine();53 out.write("easymock.b=2");54 out.newLine();55 out.write(EasyMock.NOT_THREAD_SAFE_BY_DEFAULT + "=" + true);56 out.newLine();57 out.close();58 }59 @AfterClass60 public static void afterClass() throws Exception {61 // Cleanup the mess62 PROPERTIES_FILE.delete();63 // Make sure we reset all our mess at the end64 resetInstance();65 }66 @Before67 public void setup() throws Exception {68 // Make sure to reset to prevent getting an already initialized69 // EasyMockProperties70 resetInstance();71 // Set manually a new one72 setEasyMockProperty("easymock.e", "7");73 // Set manually an old one74 setEasyMockProperty("easymock.c", "8");75 // Overload after (will be ignored)76 System.setProperty("easymock.h", "4");77 }78 @Test79 public void testGetInstance() {80 assertExpectedValue("1", "easymock.a");81 assertExpectedValue("8", "easymock.c");82 assertExpectedValue("7", "easymock.e");83 assertExpectedValue(null, "easymock.g");84 assertExpectedValue(null, "easymock.h");85 assertExpectedValue(null, "xxx.yyy");86 assertExpectedValue(Boolean.TRUE.toString(), EasyMock.NOT_THREAD_SAFE_BY_DEFAULT);87 assertExpectedValue(null, EasyMock.DISABLE_CLASS_MOCKING);88 }89 @Test90 public void testGetProperty() {91 EasyMockProperties instance = EasyMockProperties.getInstance();92 // use the default93 assertEquals("1", instance.getProperty("easymock.a", "10"));94 // don't use the default95 assertEquals("10", instance.getProperty("easymock.z", "10"));96 // null default97 assertNull(instance.getProperty("easymock.z", null));98 }99 @Test(expected = IllegalArgumentException.class)100 public void testSetProperty() {101 EasyMockProperties instance = EasyMockProperties.getInstance();102 instance.setProperty("tralala.a", null);103 }104 @Test105 public void testNoThreadContextClassLoader() throws Exception {106 ClassLoader old = Thread.currentThread().getContextClassLoader();107 try {108 resetInstance();109 // Remove the context class loader110 Thread.currentThread().setContextClassLoader(null);111 // This instance will load easymock.properties from the112 // EasyMockProperties class loader113 EasyMockProperties.getInstance();114 // And so "easymock.a" should be there115 assertExpectedValue("1", "easymock.a");116 } finally {117 // Whatever happens, set the initial class loader back or it'll get118 // messy119 Thread.currentThread().setContextClassLoader(old);120 }121 }122 @Test123 public void testBadPropertiesFile() throws Exception {124 final boolean[] close = new boolean[1];125 // A ClassLoader that returns no easymock.properties126 ClassLoader cl = new ClassLoader(getClass().getClassLoader()) {127 @Override128 public InputStream getResourceAsStream(String name) {129 if ("easymock.properties".equals(name)) {130 return new InputStream() {131 @Override132 public void close() {133 close[0] = true;134 }135 @Override136 public int read(byte[] b, int off, int len) throws IOException {137 throw new IOException("Failed!");138 }139 @Override140 public int read(byte[] b) throws IOException {141 throw new IOException("Failed!");142 }143 @Override144 public int read() throws IOException {145 throw new IOException("Failed!");146 }147 };148 }149 return super.getResourceAsStream(name);150 }151 };152 ClassLoader old = Thread.currentThread().getContextClassLoader();153 try {154 resetInstance();155 // Remove the context class loader156 Thread.currentThread().setContextClassLoader(cl);157 try {158 EasyMockProperties.getInstance();159 fail("Should have an issue loading the easymock.properties file");160 } catch (RuntimeException e) {161 assertEquals("Failed to read easymock.properties file", e.getMessage());162 // Make sure the thread was closed163 assertTrue(close[0]);164 }165 } finally {166 // Whatever happens, set the initial class loader back or it'll get167 // messy168 Thread.currentThread().setContextClassLoader(old);169 }170 }171 @Test172 public void testNoEasymockPropertiesFile() throws Exception {173 // A ClassLoader that returns no easymock.properties174 ClassLoader cl = new ClassLoader(getClass().getClassLoader()) {175 @Override176 public InputStream getResourceAsStream(String name) {177 if ("easymock.properties".equals(name)) {178 return null;179 }180 return super.getResourceAsStream(name);181 }182 };183 ClassLoader old = Thread.currentThread().getContextClassLoader();184 try {185 resetInstance();186 // Set our class loader...

Full Screen

Full Screen

File

Using AI Code Generation

copy

Full Screen

1Properties properties = new Properties();2InputStream inputStream = EasyMockPropertiesTest.class.getClassLoader()3.getResourceAsStream("easymock.properties");4properties.load(inputStream);5String value = properties.getProperty("org.easymock.test2");6System.out.println(value);

Full Screen

Full Screen

File

Using AI Code Generation

copy

Full Screen

1File file = EasyMockPropertiesTest.getFile("org.easymock.tests2.EasyMockPropertiesTest.testFile");2FileInputStream fis = new FileInputStream(file);3InputStreamReader isr = new InputStreamReader(fis);4BufferedReader br = new BufferedReader(isr);5String line = br.readLine();6StringReader sr = new StringReader(line);7BufferedReader br2 = new BufferedReader(sr);8String line2 = br2.readLine();9ByteArrayInputStream bais = new ByteArrayInputStream(line2.getBytes());10InputStreamReader isr2 = new InputStreamReader(bais);11BufferedReader br3 = new BufferedReader(isr2);12String line3 = br3.readLine();13StringReader sr2 = new StringReader(line3);14BufferedReader br4 = new BufferedReader(sr2);15String line4 = br4.readLine();16ByteArrayInputStream bais2 = new ByteArrayInputStream(line4.getBytes());17InputStreamReader isr3 = new InputStreamReader(bais2);18BufferedReader br5 = new BufferedReader(isr3);19String line5 = br5.readLine();20StringReader sr3 = new StringReader(line5);21BufferedReader br6 = new BufferedReader(sr3);22String line6 = br6.readLine();23ByteArrayInputStream bais3 = new ByteArrayInputStream(line6.getBytes());24InputStreamReader isr4 = new InputStreamReader(bais3);

Full Screen

Full Screen

File

Using AI Code Generation

copy

Full Screen

1File file = EasyMockPropertiesTest.getFile("org.easymock.test2.file");2String string = EasyMockPropertiesTest.getString("org.easymock.test2.string");3String stringWithDefault = EasyMockPropertiesTest.getString("org.easymock.test2.stringWithDefault", "default value");4int int = EasyMockPropertiesTest.getInt("org.easymock.test2.int");5int intWithDefault = EasyMockPropertiesTest.getInt("org.easymock.test2.intWithDefault", 42);6boolean boolean = EasyMockPropertiesTest.getBoolean("org.easymock.test2.boolean");7boolean booleanWithDefault = EasyMockPropertiesTest.getBoolean("org.easymock.test2.booleanWithDefault", true);

Full Screen

Full Screen

File

Using AI Code Generation

copy

Full Screen

1import static org.junit.Assert.assertEquals;2import static org.junit.Assert.assertTrue;3import java.io.File;4import org.easymock.EasyMock;5import org.easymock.EasyMockRule;6import org.easymock.Mock;7import org.easymock.MockType;8import org.easymock.internal.MocksControl;9import org.junit.Before;10import org.junit.Ignore;11import org.junit.Rule;12import org.junit.Test;13public class EasyMockPropertiesTest {14 private static final String EASYMOCK_PROPERTIES = "easymock.properties";15 public EasyMockRule rule = new EasyMockRule(this);16 @Mock(type = MockType.NICE)17 private MocksControl mocksControl;18 public void setUp() {19 EasyMock.reset(mocksControl);20 }21 public void testCreateMock() {22 EasyMock.createMock(Object.class);23 mocksControl.checkControl();24 }25 public void testCreateMockWithConstructorArgs() {26 EasyMock.createMock(Object.class, "arg");27 mocksControl.checkControl();28 }29 public void testCreateMockBuilder() {30 EasyMock.createMockBuilder(Object.class).createMock();31 mocksControl.checkControl();32 }33 public void testCreateMockBuilderWithConstructorArgs() {34 EasyMock.createMockBuilder(Object.class).withConstructor("arg").createMock();35 mocksControl.checkControl();36 }37 public void testCreateStrictMock() {38 EasyMock.createStrictMock(Object.class);39 mocksControl.checkControl();40 }41 public void testCreateStrictMockWithConstructorArgs() {42 EasyMock.createStrictMock(Object.class, "arg");43 mocksControl.checkControl();44 }45 public void testCreateStrictMockBuilder() {46 EasyMock.createMockBuilder(Object.class).createStrictMock();47 mocksControl.checkControl();48 }49 public void testCreateStrictMockBuilderWithConstructorArgs() {50 EasyMock.createMockBuilder(Object.class).withConstructor("arg").createStrictMock();51 mocksControl.checkControl();52 }

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful