package com.gmail.cs475x.anybar4j;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import com.gmail.cs475x.anybar4j.AnyBar4j.AnyBarImage;

public class AnyBar4jTest {

	@Test
	public void shouldWorkWithDefaultHostAndPort() {
		Exception exception = null;

		try {
			AnyBar4j anybar = new AnyBar4j(AnyBar4j.DEFAULT_HOST, AnyBar4j.DEFAULT_PORT);

			anybar.setImage(AnyBarImage.GREEN);
			anybar.close();
		} catch (Exception e) {
			exception = e;
		}

		assertEquals(null, exception);
	}

	@Test
	public void shouldUseDefaultPortIfSuppliedPortIsLessThanOrEqualToZero() {
		AnyBar4j anybar = null;
		Exception exception = null;

		try {
			anybar = new AnyBar4j(AnyBar4j.DEFAULT_HOST, -1);

			anybar.close();
		} catch (Exception e) {
			exception = e;
		}

		assertEquals(null, exception);
		assertEquals(AnyBar4j.DEFAULT_PORT, anybar.port);
	}

}


@@ -241,16 +241,42 @@
 ort() %7B%0A
+%09%09AnyBar4j anybar = null;%0A
 %09%09Except
@@ -309,25 +309,16 @@
 ry %7B%0A%09%09%09
-AnyBar4j 
 anybar =
@@ -418,35 +418,16 @@
 GREEN);%0A
-%09%09%09anybar.close();%0A
 %09%09%7D catc
@@ -457,32 +457,96 @@
 ception = e;%0A%09%09%7D
+ finally %7B%0A%09%09%09if (anybar != null) %7B%0A%09%09%09%09anybar.close();%0A%09%09%09%7D%0A%09%09%7D
 %0A%0A%09%09assertEquals
@@ -771,28 +771,8 @@
 -1);
-%0A%0A%09%09%09anybar.close();
 %0A%09%09%7D
@@ -811,24 +811,88 @@
 ion = e;%0A%09%09%7D
+ finally %7B%0A%09%09%09if (anybar != null) %7B%0A%09%09%09%09anybar.close();%0A%09%09%09%7D%0A%09%09%7D
 %0A%0A%09%09assertEq

Move `close()` calls to finally block