Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make use proper assert functions in o.e.tips.tests... #90

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018 Remain Software
* Copyright (c) 2018, 2023 Remain Software
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.tips.core;

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

import org.eclipse.core.runtime.AssertionFailedException;
Expand Down Expand Up @@ -57,7 +58,7 @@ public void testGetIMGAttributes() {

@Test
public void testGetBase64() {
assertTrue(getTipImage().getBase64Image().equals(BASE64));
assertEquals(BASE64, getTipImage().getBase64Image());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018 Remain Software
* Copyright (c) 2018, 2023 Remain Software
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -13,6 +13,9 @@
*******************************************************************************/
package org.eclipse.tips.core;

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

import java.util.ArrayList;
Expand Down Expand Up @@ -45,14 +48,14 @@ public void testTipManager() {
public void testGetProvider() {
fManager.register(fProvider1);
TipProvider provider = fManager.getProvider(fProvider1.getID());
assertTrue(provider == fProvider1);
assertEquals(fProvider1, provider);
}

@Test
public void testRegister() {
fManager.register(fProvider1);
TipProvider provider = fManager.getProvider(fProvider1.getID());
assertTrue(provider == fProvider1);
assertEquals(provider, fProvider1);
}

/**
Expand All @@ -63,24 +66,24 @@ public void testGetProviders() {
fManager.register(fProvider1);
fManager.register(fProvider2);
fManager.register(fProvider2);
assertTrue(fManager.getProviders().size() + "", fManager.getProviders().size() == 1);
assertEquals(fManager.getProviders().size() + "", 1, fManager.getProviders().size());
}

@Test
public void testGetStartupBeahvior() {
assertTrue(fManager.getStartupBehavior() == TipManager.START_DIALOG);
assertTrue(fManager.getStartupBehavior() != TipManager.START_BACKGROUND);
assertTrue(fManager.getStartupBehavior() != TipManager.START_DISABLE);
assertEquals(TipManager.START_DIALOG, fManager.getStartupBehavior());
assertNotEquals(TipManager.START_BACKGROUND, fManager.getStartupBehavior());
assertNotEquals(TipManager.START_DISABLE, fManager.getStartupBehavior());

fManager.setStartupBehavior(TipManager.START_BACKGROUND);
assertTrue(fManager.getStartupBehavior() == TipManager.START_BACKGROUND);
assertTrue(fManager.getStartupBehavior() != TipManager.START_DIALOG);
assertTrue(fManager.getStartupBehavior() != TipManager.START_DISABLE);
assertEquals(TipManager.START_BACKGROUND, fManager.getStartupBehavior());
assertNotEquals(TipManager.START_DIALOG, fManager.getStartupBehavior());
assertNotEquals(TipManager.START_DISABLE, fManager.getStartupBehavior());

fManager.setStartupBehavior(TipManager.START_DISABLE);
assertTrue(fManager.getStartupBehavior() != TipManager.START_BACKGROUND);
assertTrue(fManager.getStartupBehavior() != TipManager.START_DIALOG);
assertTrue(fManager.getStartupBehavior() == TipManager.START_DISABLE);
assertNotEquals(TipManager.START_BACKGROUND, fManager.getStartupBehavior());
assertNotEquals(TipManager.START_DIALOG, fManager.getStartupBehavior());
assertEquals(TipManager.START_DISABLE, fManager.getStartupBehavior());
}

@Test
Expand All @@ -94,7 +97,7 @@ public IStatus loadNewTips(IProgressMonitor monitor) {
}
};
fManager.register(testTipProvider);
assertTrue(!test.isEmpty());
assertFalse(test.isEmpty());
}

@Test
Expand All @@ -108,7 +111,7 @@ public IStatus loadNewTips(IProgressMonitor monitor) {
}
};
fManager.register(testTipProvider);
assertTrue(!test.isEmpty());
assertFalse(test.isEmpty());
}

@Test
Expand All @@ -127,10 +130,10 @@ public TipManager open(boolean startUp) {
}
};
m.open(true);
assertTrue(test.size() == 1);
assertEquals(1, test.size());
test.clear();
m.open(false);
assertTrue(test.size() == 2);
assertEquals(2, test.size());
}

@Test
Expand Down Expand Up @@ -176,12 +179,12 @@ public void testSetServeUnread() {
fManager.setAsRead(fProvider1.getCurrentTip());
assertTrue(fProvider1.getTips().size() + "", fProvider1.getTips().size() == 1);
fManager.setServeReadTips(true);
assertTrue(fProvider1.getTips().size() == 2);
assertEquals(2, fProvider1.getTips().size());
}

@Test
public void testIsServeUnread() {
assertTrue(fManager.mustServeReadTips() == false);
assertFalse(fManager.mustServeReadTips());
fManager.setServeReadTips(true);
assertTrue(fManager.mustServeReadTips());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018 Remain Software
* Copyright (c) 2018, 2023 Remain Software
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -13,7 +13,11 @@
*******************************************************************************/
package org.eclipse.tips.core;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.util.Arrays;
Expand Down Expand Up @@ -47,30 +51,30 @@ public void testDispose() {

@Test
public void testGetDescription() {
assertTrue(fProvider.getDescription() != null);
assertNotNull(fProvider.getDescription());
}

@Test
public void testGetID() {
assertTrue(fProvider.getID() != null);
assertTrue(fProvider.getID().equals(fProvider.getClass().getName()));
assertNotNull(fProvider.getID());
assertEquals(fProvider.getClass().getName(), fProvider.getID());
}

@Test
public void testGetImage() {
assertTrue(fProvider.getImage() != null);
assertNotNull(fProvider.getImage());
}

@Test
public void testGetTips() {
assertTrue(fProvider.getTips(null).size() == 0);
assertEquals(0, fProvider.getTips(null).size());
createTestData();
fManager.setAsRead(fProvider.getNextTip());
assertTrue(fProvider.getTips(null).size() == 2);
assertTrue(fProvider.getTips(null).size() == 2);
assertTrue(fProvider.getTips().size() == 1);
assertEquals(2, fProvider.getTips(null).size());
assertEquals(2, fProvider.getTips(null).size());
assertEquals(1, fProvider.getTips().size());
((TipManager) fProvider.getManager()).setServeReadTips(true);
assertTrue(fProvider.getTips(null).size() == 2);
assertEquals(2, fProvider.getTips(null).size());
}

private void createTestData() {
Expand All @@ -80,111 +84,108 @@ private void createTestData() {

@Test
public void testGetCurrentTip() {
assertTrue(fProvider.getNextTip().equals(fProvider.getCurrentTip()));
assertEquals(fProvider.getNextTip(), fProvider.getCurrentTip());
}

@Test
public void testGetCurrentTip2() {
assertTrue(fProvider.getCurrentTip().equals(fProvider.getPreviousTip()));
assertEquals(fProvider.getPreviousTip(), fProvider.getCurrentTip());
}

@Test
public void testGetNextTip() {
createTestData();
fManager.setAsRead(fProvider.getNextTip());
assertTrue(fProvider.getNextTip().equals(fProvider.getCurrentTip()));
assertEquals(fProvider.getCurrentTip(), fProvider.getNextTip());
Tip nextTip = fProvider.getNextTip();
fManager.setAsRead(nextTip);
assertTrue(fManager.isRead(nextTip));
Tip nextTip2 = fProvider.getNextTip();
fManager.setAsRead(nextTip2);
assertTrue(fManager.isRead(nextTip2));
assertTrue(fProvider.getNextTip().getClass().getSimpleName().equals("FinalTip"));
assertEquals("FinalTip", fProvider.getNextTip().getClass().getSimpleName());
((TipManager) fProvider.getManager()).setServeReadTips(true);
assertFalse(fProvider.getNextTip().getClass().getSimpleName().equals("FinalTip"));
assertNotEquals("FinalTip", fProvider.getNextTip().getClass().getSimpleName());
}

@Test
public void testGetPreviousTip() {
assertTrue(fProvider.getPreviousTip().equals(fProvider.getCurrentTip()));
assertTrue(fProvider.getPreviousTip().equals(fProvider.getCurrentTip()));
assertEquals(fProvider.getCurrentTip(), fProvider.getPreviousTip());
assertEquals(fProvider.getCurrentTip(), fProvider.getPreviousTip());
}

@Test
public void testGetPreviousTip2() {
assertTrue(!fProvider.getPreviousTip().equals(null));
assertTrue(fProvider.getNextTip().getClass().getSimpleName().equals("FinalTip"));
assertNotNull(fProvider.getPreviousTip());
assertEquals("FinalTip", fProvider.getNextTip().getClass().getSimpleName());
}

@Test
public void testGetPreviousTip3() {
((TipManager) fProvider.getManager()).setServeReadTips(true);
assertTrue(fProvider.getPreviousTip().equals(fProvider.getCurrentTip()));
assertEquals(fProvider.getCurrentTip(), fProvider.getPreviousTip());
}

@Test
public void testGetPreviousTip4() {
createTestData();
assertTrue(fProvider.getPreviousTip() != null);
assertTrue(fProvider.getPreviousTip() != null);
assertTrue(fProvider.getPreviousTip() != null);
assertNotNull(fProvider.getPreviousTip());
assertNotNull(fProvider.getPreviousTip());
assertNotNull(fProvider.getPreviousTip());
}

@Test
public void testGetTipManager() {
assertTrue(fProvider.getManager().equals(fManager));
assertEquals(fManager, fProvider.getManager());
}

@Test
public void testIsReady() {
TestTipProvider p = (TestTipProvider) new TestTipProvider().setManager(fManager);
assertTrue(!p.isReady());
assertFalse(p.isReady());
p.setTips(Collections.emptyList());
assertTrue(p.isReady());
}

@Test
public void testLoad() {
TestTipProvider p = (TestTipProvider) new TestTipProvider().setManager(fManager);
assertTrue(!p.isReady());
assertFalse(p.isReady());
p.loadNewTips(new NullProgressMonitor());
assertTrue(p.isReady());
}

@Test
public void testSetManager() {
TestTipProvider p = new TestTipProvider();
assertTrue(p.getManager() == null);
assertNull(p.getManager());
p.setManager(fManager);
assertTrue(p.getManager() != null);
assertNotNull(p.getManager());
}

@Test
public void testSetTips() {
TestTipProvider p = new TestTipProvider() {
@Override
public IStatus loadNewTips(IProgressMonitor pMonitor) {
assertTrue(getTips(null).size() == 0);
assertTrue(setTips(Arrays.asList(new TestTip(getID(), "DDD", "XXX"))).getTips(null)
.size() == 1);
assertEquals(0, getTips(null).size());
assertEquals(1, setTips(Arrays.asList(new TestTip(getID(), "DDD", "XXX"))).getTips(null).size());
return Status.OK_STATUS;
}
};
assertTrue(p.getTips(null).size() == 0);
assertEquals(0, p.getTips(null).size());
fManager.register(p);
assertTrue(p.getTips(null).size() == 1);
assertEquals(1, p.getTips(null).size());
}

@Test
public void testAddTips() {
TestTipProvider p = new TestTipProvider() {
@Override
public IStatus loadNewTips(IProgressMonitor pMonitor) {
assertTrue(getTips(null).size() == 0);
assertTrue(setTips(Arrays.asList(new TestTip(getID(), "DDD", "XXX"))).getTips(null)
.size() == 1);
assertTrue(addTips(Arrays.asList(new TestTip(getID(), "DDD", "XXX"))).getTips(null)
.size() == 2);
assertEquals(0, getTips(null).size());
assertEquals(1, setTips(Arrays.asList(new TestTip(getID(), "DDD", "XXX"))).getTips(null).size());
assertEquals(2, addTips(Arrays.asList(new TestTip(getID(), "DDD", "XXX"))).getTips(null).size());
return Status.OK_STATUS;
}
};
Expand Down
Loading